From 61a51fbeeb3f3a62f7fbe74428fbf7b77d880f99 Mon Sep 17 00:00:00 2001 From: Benjamin Crews Date: Thu, 4 Jul 2024 13:19:22 -0400 Subject: [PATCH 1/6] Trying to fix the actions to match my other projects. --- .github/dependabot.yml | 8 ++++---- .github/workflows/constraints.txt | 4 ++-- .github/workflows/labeler.yml | 7 ++++++- .github/workflows/release.yml | 6 ++++-- .github/workflows/tests.yml | 20 ++++++++++++++------ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2beb269..803fa9b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,19 +3,19 @@ updates: - package-ecosystem: github-actions directory: "/" schedule: - interval: daily + interval: weekly - package-ecosystem: pip directory: "/.github/workflows" schedule: - interval: daily + interval: weekly - package-ecosystem: pip directory: "/docs" schedule: - interval: daily + interval: weekly - package-ecosystem: pip directory: "/" schedule: - interval: daily + interval: weekly versioning-strategy: lockfile-only allow: - dependency-type: "all" diff --git a/.github/workflows/constraints.txt b/.github/workflows/constraints.txt index 828b972..74f9aaf 100644 --- a/.github/workflows/constraints.txt +++ b/.github/workflows/constraints.txt @@ -1,5 +1,5 @@ pip==24.0 nox==2024.4.15 nox-poetry==1.0.3 -poetry==1.8.2 -virtualenv==20.22.0 +poetry==1.8.3 +virtualenv==20.26.1 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 173926f..547ac02 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -4,11 +4,15 @@ on: push: branches: - main - - master jobs: labeler: runs-on: ubuntu-latest + permissions: + actions: read + contents: read + issues: write # <--- permission granted explicitely + security-events: write steps: - name: Check out the repository uses: actions/checkout@v4 @@ -16,4 +20,5 @@ jobs: - name: Run Labeler uses: crazy-max/ghaction-github-labeler@v5.0.0 with: + github-token: ${{ secrets.GITHUB_TOKEN }} skip-delete: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9ec34a1..acfee63 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,8 @@ on: jobs: release: name: Release + permissions: + contents: write runs-on: ubuntu-latest steps: - name: Check out the repository @@ -19,7 +21,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.11" - name: Upgrade pip run: | @@ -71,7 +73,7 @@ jobs: repository_url: https://test.pypi.org/legacy/ - name: Publish the release notes - uses: release-drafter/release-drafter@v5.25.0 + uses: release-drafter/release-drafter@v6.0.0 with: publish: ${{ steps.check-version.outputs.tag != '' }} tag: ${{ steps.check-version.outputs.tag }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3580815..fc5fd2f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,11 +14,13 @@ jobs: include: - { python: "3.11", os: "ubuntu-latest", session: "pre-commit" } - { python: "3.11", os: "ubuntu-latest", session: "safety" } + - { python: "3.11", os: "ubuntu-latest", session: "mypy" } + - { python: "3.10", os: "ubuntu-latest", session: "mypy" } + - { python: "3.9", os: "ubuntu-latest", session: "mypy" } - { python: "3.11", os: "ubuntu-latest", session: "tests" } - { python: "3.10", os: "ubuntu-latest", session: "tests" } - { python: "3.9", os: "ubuntu-latest", session: "tests" } - { python: "3.11", os: "windows-latest", session: "tests" } - - { python: "3.10", os: "windows-latest", session: "tests" } - { python: "3.11", os: "macos-latest", session: "tests" } - { python: "3.11", os: "ubuntu-latest", session: "typeguard" } - { python: "3.11", os: "ubuntu-latest", session: "xdoctest" } @@ -40,7 +42,7 @@ jobs: - name: Upgrade pip run: | - pip install --constraint=.github/workflows/constraints.txt pip + pip install --constraint=.github/workflows/constraints.txt pip "pipx==1.4.3" pip --version - name: Upgrade pip in virtual environments @@ -53,11 +55,14 @@ jobs: print(f"VIRTUALENV_PIP={pip.__version__}", file=io) - name: Install Poetry + shell: bash run: | + pipx --version pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry poetry --version - name: Install Nox + shell: bash run: | pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry @@ -95,7 +100,7 @@ jobs: if: always() && matrix.session == 'tests' uses: "actions/upload-artifact@v4" with: - name: coverage-data + name: coverage-data-${{ matrix.python}}-${{ matrix.os }} path: ".coverage.*" - name: Upload documentation @@ -119,7 +124,7 @@ jobs: - name: Upgrade pip run: | - pip install --constraint=.github/workflows/constraints.txt pip + pip install --constraint=.github/workflows/constraints.txt pip "pipx==1.4.3" pip --version - name: Install Poetry @@ -136,7 +141,8 @@ jobs: - name: Download coverage data uses: actions/download-artifact@v4 with: - name: coverage-data + pattern: coverage-data-* + merge-multiple: true - name: Combine coverage data and display human readable report run: | @@ -147,4 +153,6 @@ jobs: nox --session=coverage -- xml - name: Upload coverage report - uses: codecov/codecov-action@v3.1.4 + uses: codecov/codecov-action@v4.3.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} From 101c02be8b6ee2f8ee84cd71ca25ea8d8b37db94 Mon Sep 17 00:00:00 2001 From: Benjamin Crews Date: Thu, 4 Jul 2024 13:30:44 -0400 Subject: [PATCH 2/6] Should fix pre-commit on Actions. --- .flake8 | 2 +- src/thymed/thymer.py | 2 +- src/thymed/tui.py | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.flake8 b/.flake8 index 93714a6..9e25277 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,7 @@ [flake8] select = B,B9,C,D,DAR,E,F,N,RST,S,W ignore = E203,E501,RST201,RST203,RST301,W503,B907,B905,D101,D102 -max-line-length = 80 +max-line-length = 120 max-complexity = 10 docstring-convention = google per-file-ignores = tests/*:S101 diff --git a/src/thymed/thymer.py b/src/thymed/thymer.py index 98afd17..29d6299 100644 --- a/src/thymed/thymer.py +++ b/src/thymed/thymer.py @@ -13,7 +13,7 @@ from textual.containers import Container from textual.containers import ScrollableContainer from textual.reactive import reactive -from textual.reactive import var +# from textual.reactive import var from textual.widget import Widget from textual.widgets import Button from textual.widgets import DataTable diff --git a/src/thymed/tui.py b/src/thymed/tui.py index cc453b2..e6bdaf1 100644 --- a/src/thymed/tui.py +++ b/src/thymed/tui.py @@ -50,7 +50,7 @@ SIDEBAR_INFO = """ There are multiple tools available in Thymed. To use one, select it or hit the keybinding. The main area will be updated with the 'applet' along with some more information. :smiley: -""" +""" # noqa: B950 LINKS = """ Here are some links, you can click these! @@ -180,7 +180,10 @@ def get_data(self) -> Table: for code in codes: table.add_row( - str(code.id), code.name, code.description, str(code.is_active) + str(code.id), + code.name, + code.description, + str(code.is_active) ) return table From 2ad7da6302985a04a0d573c49f26a71cdda2da94 Mon Sep 17 00:00:00 2001 From: Benjamin Crews Date: Thu, 4 Jul 2024 13:34:03 -0400 Subject: [PATCH 3/6] Pre-commit again... --- src/thymed/tui.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/thymed/tui.py b/src/thymed/tui.py index e6bdaf1..7bdfeb5 100644 --- a/src/thymed/tui.py +++ b/src/thymed/tui.py @@ -50,7 +50,7 @@ SIDEBAR_INFO = """ There are multiple tools available in Thymed. To use one, select it or hit the keybinding. The main area will be updated with the 'applet' along with some more information. :smiley: -""" # noqa: B950 +""" # noqa: B950 LINKS = """ Here are some links, you can click these! @@ -180,10 +180,7 @@ def get_data(self) -> Table: for code in codes: table.add_row( - str(code.id), - code.name, - code.description, - str(code.is_active) + str(code.id), code.name, code.description, str(code.is_active) ) return table From 6ed11a13eb57fc5acd2d50245eae4caad70e252d Mon Sep 17 00:00:00 2001 From: Benjamin Crews Date: Thu, 4 Jul 2024 13:41:44 -0400 Subject: [PATCH 4/6] Small black change. --- src/thymed/thymer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thymed/thymer.py b/src/thymed/thymer.py index 29d6299..569d28a 100644 --- a/src/thymed/thymer.py +++ b/src/thymed/thymer.py @@ -13,6 +13,7 @@ from textual.containers import Container from textual.containers import ScrollableContainer from textual.reactive import reactive + # from textual.reactive import var from textual.widget import Widget from textual.widgets import Button From 371ab47fa5664b3ab6e8baecebe0a0903fe16170 Mon Sep 17 00:00:00 2001 From: Benjamin Crews Date: Thu, 4 Jul 2024 14:31:12 -0400 Subject: [PATCH 5/6] Fixing typeguard. Chargecode.is_active now returns type Any. Not the most specific, but I think it works. --- src/thymed/__init__.py | 2 +- tests/test_chargecode.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/thymed/__init__.py b/src/thymed/__init__.py index 20dcbb6..f5a49b7 100644 --- a/src/thymed/__init__.py +++ b/src/thymed/__init__.py @@ -122,7 +122,7 @@ def __post_init__(self) -> None: raise e @property - def is_active(self) -> [bool, Any]: + def is_active(self) -> Any: """The charge code is active if it has been activated, but not closed.""" # If the last item in the times list has only 1 entry, # we assume the code is still active. diff --git a/tests/test_chargecode.py b/tests/test_chargecode.py index 3364f77..0cf0427 100644 --- a/tests/test_chargecode.py +++ b/tests/test_chargecode.py @@ -135,13 +135,13 @@ def fake_times( # # # T E S T S # # # -def test_create(): +def test_create() -> None: """If a ChargeCode can be created.""" the_code = ChargeCode("test_code", "description", 0) assert not the_code.is_active -def test_punch(blank_code): +def test_punch(blank_code) -> None: """Punches a charge code, sees active. Punches again, sees inactive.""" blank_code.punch() assert blank_code.is_active @@ -150,7 +150,7 @@ def test_punch(blank_code): assert not blank_code.is_active -def test_data(blank_code): +def test_data(blank_code) -> None: """Write some data, and instantiate a code that recognizes the times.""" blank_code.punch() time.sleep(0.1) @@ -164,7 +164,7 @@ def test_data(blank_code): remove_test_data("99999998") -def test_multiple(): +def test_multiple() -> None: """Make multiple for post_init checks.""" one = ChargeCode("One", "Tester 1, Tester One.", 1) one.write_class() @@ -178,7 +178,7 @@ def test_multiple(): remove_test_charge("2") -def test_fake_time(fake_times, blank_code): +def test_fake_time(fake_times, blank_code) -> None: """Build some real data to work with.""" blank_code.punch() time.sleep(0.1) From 9e6b65df9da83d148f75d4ceb8b8d2bb5315e363 Mon Sep 17 00:00:00 2001 From: Benjamin Crews Date: Thu, 4 Jul 2024 14:50:13 -0400 Subject: [PATCH 6/6] Adds back in the mypy sessions. They will still fail. Need to open an issue to work these... Significant effort, since it's been ignored for so long. --- noxfile.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/noxfile.py b/noxfile.py index 044f9d3..11f6a99 100644 --- a/noxfile.py +++ b/noxfile.py @@ -29,6 +29,7 @@ "pre-commit", "safety", "tests", + "mypy", "typeguard", "xdoctest", "docs-build", @@ -156,6 +157,17 @@ def tests(session: Session) -> None: session.notify("coverage", posargs=[]) +@session(python=python_versions) +def mypy(session: Session) -> None: + """Type-check using mypy.""" + args = session.posargs or ["src", "tests", "docs/conf.py"] + session.install(".") + session.install("mypy", "pytest") + session.run("mypy", *args) + if not session.posargs: + session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py") + + @session(python=python_versions[0]) def coverage(session: Session) -> None: """Produce the coverage report."""