From f89c505e77d44147dc21241f52087d8fec6e864c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 02:34:20 +0000 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=9A=A8=20Run=20isort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/linting.yml | 2 +- compass.api/src/compass/api/util/flatten_units.py | 2 +- docker/gunicorn_conf.py | 2 +- tests/test_compass_core_logger.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index eacb8a68..887095f9 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -19,7 +19,7 @@ jobs: # code style (import ordering) - tool: "isort" command: "python -m isort --check --diff --color ." - deps: "isort" + deps: "isort colorama" # (pyflakes, pycodestyle, mccabe) + pep8-naming - tool: "flake8" command: "python -m flake8 ." diff --git a/compass.api/src/compass/api/util/flatten_units.py b/compass.api/src/compass/api/util/flatten_units.py index c7527402..82448784 100644 --- a/compass.api/src/compass/api/util/flatten_units.py +++ b/compass.api/src/compass/api/util/flatten_units.py @@ -5,8 +5,8 @@ from typing import TYPE_CHECKING, Union from compass.api.schemas.unit_records import UnitRecord -from compass.core.settings import Settings import compass.core as ci +from compass.core.settings import Settings if TYPE_CHECKING: from collections.abc import Iterator diff --git a/docker/gunicorn_conf.py b/docker/gunicorn_conf.py index 2b9f3696..8d5e2278 100644 --- a/docker/gunicorn_conf.py +++ b/docker/gunicorn_conf.py @@ -1,4 +1,4 @@ -from os import cpu_count, getenv +from os import cpu_count, getenv # isort: skip # Non-gunicorn variables host = getenv("HOST", "0.0.0.0") diff --git a/tests/test_compass_core_logger.py b/tests/test_compass_core_logger.py index 87f5e31c..71e889d3 100644 --- a/tests/test_compass_core_logger.py +++ b/tests/test_compass_core_logger.py @@ -2,8 +2,8 @@ import pathlib import sys -from compass.core.logger import logger from compass.core.logger import enable_debug_logging +from compass.core.logger import logger class TestLogger: From 9a85f27e5e9c049835ecd9b2f65804e1e5e23963 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 02:36:48 +0000 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=9A=A8=20Run=20black?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compass.api/src/compass/api/routes/members.py | 4 +++- compass.api/src/compass/api/util/oauth2.py | 4 +++- tools/prepare_release.py | 2 +- update_js.py | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compass.api/src/compass/api/routes/members.py b/compass.api/src/compass/api/routes/members.py index 339c2150..bf55c5cd 100644 --- a/compass.api/src/compass/api/routes/members.py +++ b/compass.api/src/compass/api/routes/members.py @@ -26,7 +26,9 @@ async def get_current_member(api: ci.CompassInterface = Depends(ci_user)) -> ci. @router.get("/me/roles", response_model=ci.MemberRolesCollection) -async def get_current_member_roles(api: ci.CompassInterface = Depends(ci_user), volunteer_only: bool = False) -> ci.MemberRolesCollection: +async def get_current_member_roles( + api: ci.CompassInterface = Depends(ci_user), volunteer_only: bool = False +) -> ci.MemberRolesCollection: """Gets my roles.""" logger.debug(f"Getting /me/roles for {api.user.membership_number}") async with error_handler: diff --git a/compass.api/src/compass/api/util/oauth2.py b/compass.api/src/compass/api/util/oauth2.py index 27ccde9e..2439b90f 100644 --- a/compass.api/src/compass/api/util/oauth2.py +++ b/compass.api/src/compass/api/util/oauth2.py @@ -54,7 +54,9 @@ async def create_token(username: str, pw: str, role: Optional[str], location: Op return access_token -async def authenticate_user(username: str, password: str, role: Optional[str], location: Optional[str]) -> tuple[User, ci.CompassInterface]: +async def authenticate_user( + username: str, password: str, role: Optional[str], location: Optional[str] +) -> tuple[User, ci.CompassInterface]: logger.info(f"Logging in to Compass -- {username}") api = ci.login(username, password, role=role, location=location) diff --git a/tools/prepare_release.py b/tools/prepare_release.py index 54f2f24a..14a4fd62 100644 --- a/tools/prepare_release.py +++ b/tools/prepare_release.py @@ -30,7 +30,7 @@ def update_changelog(version): "\n".join(RELEASE_FILE.read_text(encoding="utf-8").split("\n")[1:]).strip(), "", *lines[3:], - "" + "", ) HISTORY_FILE.write_text("\n".join(new_changelog_lines), encoding="utf-8") diff --git a/update_js.py b/update_js.py index 7a723a6d..4c89bb7e 100644 --- a/update_js.py +++ b/update_js.py @@ -44,7 +44,7 @@ async def main() -> list[str]: return [resp.content for resp in responses] -if __name__ == '__main__': +if __name__ == "__main__": files_contents = asyncio.run(main()) for i, filename in enumerate(files): Path(f"js/{filename}.js").write_bytes(files_contents[i].decode("utf-8-sig").encode("utf-8")) From e73f94264e45ba38ad5f449462d3b965f9a0738a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 02:39:02 +0000 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20flake8=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compass.api/src/compass/api/app.py | 16 ++++++++-------- compass.api/src/compass/api/routes/hierarchy.py | 4 ++-- tools/prepare_release.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compass.api/src/compass/api/app.py b/compass.api/src/compass/api/app.py index 2005eac4..16443e50 100644 --- a/compass.api/src/compass/api/app.py +++ b/compass.api/src/compass/api/app.py @@ -18,16 +18,16 @@ ] long_description = """ -The ***Compass Interface*** project aims to provide a unified and well-documented API to -the Scouts' national membership system, *[Compass](https://compass.scouts.org.uk)*. +The ***Compass Interface*** project aims to provide a unified and well-documented API to +the Scouts' national membership system, *[Compass](https://compass.scouts.org.uk)*. -The project aims to: - - increase flexibility and simplicity when developing applications that interface with *Compass* data, - - provide stability and abstract complexities of *Compass*, and - - enable greater support to our adult volunteers and -members. +The project aims to: + - increase flexibility and simplicity when developing applications that interface with *Compass* data, + - provide stability and abstract complexities of *Compass*, and + - enable greater support to our adult volunteers and +members. -***Compass Interface*** is naturally [open source](https://github.com/the-scouts/compass-interface) +***Compass Interface*** is naturally [open source](https://github.com/the-scouts/compass-interface) and is licensed under the **[MIT license](https://choosealicense.com/licenses/mit/)**. """ diff --git a/compass.api/src/compass/api/routes/hierarchy.py b/compass.api/src/compass/api/routes/hierarchy.py index a2f33cf0..7c8235a6 100644 --- a/compass.api/src/compass/api/routes/hierarchy.py +++ b/compass.api/src/compass/api/routes/hierarchy.py @@ -42,7 +42,7 @@ async def get_unit_data(unit_id: int) -> UnitRecordModel: @router.get("/{unit_id}/children", response_model=list[ci.HierarchyUnit]) -async def get_unit_data(unit_id: int) -> list[ci.HierarchyUnit]: +async def get_unit_children(unit_id: int) -> list[ci.HierarchyUnit]: """Gets hierarchy details for given unit ID.""" logger.debug(f"Getting /hierarchy/{{unit_id}} for {unit_id=}") async with error_handler: @@ -50,7 +50,7 @@ async def get_unit_data(unit_id: int) -> list[ci.HierarchyUnit]: @router.get("/{unit_id}/sections", response_model=list[ci.HierarchyUnit]) -async def get_unit_data(unit_id: int) -> list[ci.HierarchyUnit]: +async def get_unit_sections(unit_id: int) -> list[ci.HierarchyUnit]: """Gets hierarchy details for given unit ID.""" logger.debug(f"Getting /hierarchy/{{unit_id}} for {unit_id=}") async with error_handler: diff --git a/tools/prepare_release.py b/tools/prepare_release.py index 14a4fd62..ecbdd3a9 100644 --- a/tools/prepare_release.py +++ b/tools/prepare_release.py @@ -73,10 +73,10 @@ def push_with_tags(version): print("Committing changes") commit(new_version) - print(f"Creating tag") + print("Creating tag") tag(new_version) - print(f"Pushing changes") + print("Pushing changes") push_with_tags(new_version) raise SystemExit(0) From 3aecccc9799eedb47cf0fac3fad2d135f8f95a72 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 02:59:37 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=94=A7=20Move=20pydocstyle=20configur?= =?UTF-8?q?ation=20to=20pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 8 ++++++++ setup.cfg | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3f14cf71..cf10c152 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,6 +105,14 @@ disable = [ "wrong-import-order", ] +# pydocstyle configuration +[tool.pydocstyle] +convention = "google" +# re-enable D413, Missing blank line after last section +add_select = ["D413"] +# ignore missing docstrings in public modules, public classes, public methods, and public functions +add_ignore = ["D100", "D101", "D102", "D103"] + [tool.coverage.report] exclude_lines = [ # re-enable the standard pragma diff --git a/setup.cfg b/setup.cfg index 35f6b1d5..bb53c06a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,11 +4,3 @@ max-complexity = 15 # black manages line length ignore = E501, W503 classmethod-decorators = classmethod, validator - -# pydocstyle configuration -[pydocstyle] -convention = google -# re-enable D413, Missing blank line after last section -add_select = D413 -# ignore missing docstrings in public modules, public classes, public methods, and public functions -add_ignore = D100, D101, D102, D103 From d83bf2707a57ce50b9bd0bd1c6102d5d4c83cb7b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 03:14:35 +0000 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=94=A7=20Exclude=20some=20directories?= =?UTF-8?q?=20for=20pydocstyle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index cf10c152..a67a58dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,6 +112,7 @@ convention = "google" add_select = ["D413"] # ignore missing docstrings in public modules, public classes, public methods, and public functions add_ignore = ["D100", "D101", "D102", "D103"] +match-dir = "(?!tools|tests).*" [tool.coverage.report] exclude_lines = [ From b2027a7ddaa38947b9b7b1b017d9bebef5404b15 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 04:28:12 +0000 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=94=A7=20Move=20bandit=20configuratio?= =?UTF-8?q?n=20to=20pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/linting.yml | 4 ++-- ci/bandit.yml | 9 --------- pyproject.toml | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 11 deletions(-) delete mode 100644 ci/bandit.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 887095f9..0e8a4a41 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -34,8 +34,8 @@ jobs: deps: "pydocstyle" # Common security issues - tool: "bandit" - command: "python -m bandit -c ci/bandit.yml -r ." - deps: "bandit" + command: "python -m bandit --configfile pyproject.toml --recursive ." + deps: "bandit toml" # packaging (CheeseShop) compliance - tool: "pyroma" command: "pyroma ." diff --git a/ci/bandit.yml b/ci/bandit.yml deleted file mode 100644 index a62eb051..00000000 --- a/ci/bandit.yml +++ /dev/null @@ -1,9 +0,0 @@ -# bandit configuration - -# skip checking usages of assertions in test files -assert_used: - skips: ['*/*_test.py', '*/test_*.py'] - -skips: [ - 'B410', # import lxml.* (defusedxml.lxml is deprecated) -] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a67a58dc..c679f3d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,6 +66,7 @@ xfail_strict = true [tool.pylint] MASTER.persistent=false # pylint runs on CI, so no point saving MASTER.jobs=0 # auto-detect the number of processors to use +MASTER.ignore-paths="^tests/.*" DESIGN.max-statements=60 FORMAT.max-line-length=132 SIMILARITIES.ignore-imports=true @@ -114,6 +115,19 @@ add_select = ["D413"] add_ignore = ["D100", "D101", "D102", "D103"] match-dir = "(?!tools|tests).*" +# bandit configuration +[tool.bandit] +exclude_dirs = [ + "./docker/*", + "./scripts/*", + "./tests/*", + "./tools/*", +] + +skips = [ +'B410', # import lxml.* (defusedxml.lxml is deprecated) +] + [tool.coverage.report] exclude_lines = [ # re-enable the standard pragma From b399d1a809603c3ffd55da94a41245e96d4f4c75 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 04:29:35 +0000 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20bandit=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compass.api/src/compass/api/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compass.api/src/compass/api/app.py b/compass.api/src/compass/api/app.py index 16443e50..e321a7f5 100644 --- a/compass.api/src/compass/api/app.py +++ b/compass.api/src/compass/api/app.py @@ -107,7 +107,7 @@ from compass.core.logger import enable_debug_logging enable_debug_logging() - uvicorn.run("app:app", host="0.0.0.0", port=8002) + uvicorn.run("app:app", host="0.0.0.0", port=8002) # nosec (B104; don't care as explicitly for local testing) print() From db1025d94c2b5c4d9f28428e6a046eef5e656cbe Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 04:43:10 +0000 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=9A=A8=20Disable=20pyroma=20checking?= =?UTF-8?q?=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/linting.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 0e8a4a41..e72c5852 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -36,10 +36,10 @@ jobs: - tool: "bandit" command: "python -m bandit --configfile pyproject.toml --recursive ." deps: "bandit toml" - # packaging (CheeseShop) compliance - - tool: "pyroma" - command: "pyroma ." - deps: "pyroma" +# # packaging (CheeseShop) compliance [DISABLED, pyroma doesn't support PEP 621 metadata yet] +# - tool: "pyroma" +# command: "pyroma ." +# deps: "pyroma" # type checking - tool: "mypy" command: "mypy --namespace-packages -p compass" From f58a7f35f0950c1f27ca5754db27413bfe602186 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 28 Dec 2021 04:50:52 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=9A=A8=20Make=20release=20file=20chec?= =?UTF-8?q?ker=20error=20more=20immediately=20useful?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/linting.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index e72c5852..3259cb34 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -56,12 +56,13 @@ jobs: run: ${{ matrix.command }} release-file: + name: check for RELEASE.rst runs-on: ubuntu-latest if: github.event_name == 'pull_request' steps: - uses: actions/checkout@v2 - name: Check for RELEASE.rst run: test -e RELEASE.rst - - name: No RELEASE.rst file found! + - name: You need to add a RELEASE.rst file at the top-level. if: failure() - run: echo "::error::You need to add a RELEASE.rst file at the top-level." + run: echo "::error::No RELEASE.rst file found!"