From abdea76f28d79957818521a28616cc3bddfa1206 Mon Sep 17 00:00:00 2001 From: jacobi petrucciani Date: Tue, 27 Aug 2024 15:14:34 -0400 Subject: [PATCH] fixup github actions, fixup setup.py, add pyproject.toml, replace mypy and prospector with ruff --- .github/workflows/deploy.yml | 11 ++---- .github/workflows/test.yml | 32 ++++++--------- .prospector.yaml | 70 --------------------------------- bucketstore.py | 21 ++++++---- default.nix | 26 ++++++------- pyproject.toml | 75 ++++++++++++++++++++++++++++++++++++ setup.py | 3 +- tests/conftest.py | 5 ++- tests/test_bucketstore.py | 7 ++-- tox.ini | 2 +- 10 files changed, 125 insertions(+), 127 deletions(-) delete mode 100644 .prospector.yaml create mode 100644 pyproject.toml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6fa2f20..5d03043 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,19 +8,16 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: set up python - uses: actions/setup-python@v2 + - uses: actions/checkout@v4.1.7 + - uses: actions/setup-python@v5 with: python-version: '3.x' - - name: install dependencies - run: | + - run: | python -m pip install --upgrade pip pip install setuptools wheel twine sed -i -E "s#VERSION#${GITHUB_REF/refs\/tags\//}#g" ./setup.py sed -i -E "s#VERSION#${GITHUB_REF/refs\/tags\//}#g" ./bucketstore.py - - name: build and publish - env: + - env: TWINE_USERNAME: ${{ secrets.PYPI_USER }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8754e14..4dde8f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,42 +10,32 @@ on: workflow_dispatch: jobs: - prospector: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: jpetrucciani/prospector-check@master - mypy: - runs-on: ubuntu-latest + ruff: + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 - - uses: jpetrucciani/mypy-check@master - with: - path: 'bucketstore.py' + - uses: actions/checkout@v4.1.7 + - uses: jpetrucciani/ruff-check@main black: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4.1.7 - uses: jpetrucciani/black-check@master with: path: 'bucketstore.py' tests: runs-on: ubuntu-latest - needs: [mypy, prospector, black] + needs: [ruff, black] strategy: matrix: - python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] name: python ${{ matrix.python-version }} tests steps: - - uses: actions/checkout@v2 - - name: setup python - uses: actions/setup-python@v2 + - uses: actions/checkout@v4.1.7 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} architecture: x64 - - name: install requirements - run: | + - run: | pip install -r requirements.txt pip install -r requirements.dev.txt - - name: run Tox - run: tox -e py + - run: tox -e py diff --git a/.prospector.yaml b/.prospector.yaml deleted file mode 100644 index 520b2d2..0000000 --- a/.prospector.yaml +++ /dev/null @@ -1,70 +0,0 @@ -strictness: veryhigh -doc-warnings: true -member-warnings: false -test-warnings: false - -ignore-patterns: - - (^|/)\..+ - -pylint: - disable: - - anomalous-backslash-in-string - - import-error - - broad-except - - protected-access - - unsupported-membership-test - - wrong-import-order - - options: - max-args: 14 - max-locals: 100 - max-returns: 10 - max-branches: 30 - max-statements: 180 - max-parents: 10 - max-attributes: 12 - min-public-methods: 0 - max-public-methods: 20 - max-module-lines: 2000 - max-line-length: 100 - -mccabe: - options: - max-complexity: 22 - -pycodestyle: - disable: - - N802 - - N807 - - W503 - options: - max-line-length: 100 - single-line-if-stmt: n - -vulture: - run: false - -pyroma: - run: false - disable: - - PYR19 - - PYR16 - -pydocstyle: - disable: - - D000 - - D100 - - D104 - - D107 - - D200 - - D202 - - D203 - - D205 - - D212 - - D204 - - D300 - - D400 - - D401 - - D403 - - D404 - - D415 diff --git a/bucketstore.py b/bucketstore.py index 75e39cb..0595f17 100644 --- a/bucketstore.py +++ b/bucketstore.py @@ -1,6 +1,7 @@ """ bucketstore module """ + import io import os import os.path @@ -31,7 +32,7 @@ def __len__(self) -> int: return self.size() @property - def _boto_object(self): # type: ignore + def _boto_object(self): # noqa: ANN202 """the underlying boto3 s3 key object""" return self.bucket._boto_s3.Object(self.bucket.name, self.name) @@ -98,9 +99,11 @@ def delete( def is_public(self) -> bool: """returns True if the public-read ACL is set for the Key.""" for grant in self._boto_object.Acl().grants: - if "AllUsers" in grant["Grantee"].get("URI", ""): - if grant["Permission"] == "READ": - return True + if ( + "AllUsers" in grant["Grantee"].get("URI", "") + and grant["Permission"] == "READ" + ): + return True return False @@ -164,7 +167,7 @@ def __init__( self._boto_bucket = self._boto_s3.Bucket(self.name) # Check if the bucket exists. - if not self._boto_s3.Bucket(self.name) in self._boto_s3.buckets.all(): + if self._boto_s3.Bucket(self.name) not in self._boto_s3.buckets.all(): if create: # Create the bucket. self._boto_s3.create_bucket(Bucket=self.name) @@ -213,9 +216,11 @@ def list(self, prefix: str = None, legacy_api: bool = False) -> List: def is_public(self) -> bool: """returns True if the public-read ACL is set for the bucket.""" for grant in self._boto_bucket.Acl().grants: - if "AllUsers" in grant["Grantee"].get("URI", ""): - if grant["Permission"] == "READ": - return True + if ( + "AllUsers" in grant["Grantee"].get("URI", "") + and grant["Permission"] == "READ" + ): + return True return False diff --git a/default.nix b/default.nix index 0550659..2caf386 100644 --- a/default.nix +++ b/default.nix @@ -1,24 +1,22 @@ -{ jacobi ? import - ( - fetchTarball { - name = "jpetrucciani-2022-08-17"; - url = "https://github.com/jpetrucciani/nix/archive/9e8f5c0b0f7f69257f7ff1c2032cbadbc3da7d25.tar.gz"; - sha256 = "1vyjwlhbqxfmm4xpvwyzvdl8k5jd5wg83avxlwpjkfh8yndm0bny"; - } - ) +{ pkgs ? import + (fetchTarball { + name = "jpetrucciani-2024-08-27"; + url = "https://github.com/jpetrucciani/nix/archive/20a58e6a4fccb574caef9b764585609b8d4fbd7d.tar.gz"; + sha256 = "0ksjkhcrd0h5zb8a5x6mbpn491gjs0n7rq9mxxvx9k3mnfjfaq5y"; + }) { } }: let - inherit (jacobi.hax) ifIsLinux ifIsDarwin; + inherit (pkgs.hax) ifIsLinux ifIsDarwin; name = "bucketstore"; - tools = with jacobi; { + tools = with pkgs; { cli = [ jq nixpkgs-fmt ]; python = [ - (python310.withPackages (p: with p; [ + (python311.withPackages (p: with p; [ boto3 # dev @@ -29,9 +27,9 @@ let ])) ]; }; - - env = jacobi.enviro { - inherit name tools; + paths = pkgs.lib.flatten [ (builtins.attrValues tools) ]; + env = pkgs.buildEnv { + inherit name paths; buildInputs = paths; }; in env diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ead00f2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,75 @@ +[tool.ruff] +line-length = 100 +lint.select = [ + "A", + "ANN", + "ARG", + "B", + "C4", + "D", + "E", + "F", + "ICN", + "ISC", + "N", + "PD", + "PGH", + "PLR", + "PLW", + "PIE", + "PT", + "Q", + "RET", + "RUF", + "S", + "SIM", + "TID", + "UP", + "W", + "YTT", +] +lint.ignore = [ + "A001", + "A003", + "ANN101", + "ANN102", + "ANN401", + "B008", + "B017", + "B019", + "C405", + "D103", + "D107", + "D200", + "D202", + "D203", + "D205", + "D212", + "D400", + "D401", + "D403", + "D404", + "D415", + "E501", + "N818", + "PGH003", + "PGH004", + "PLR2004", + "PT011", + "PT012", + "RUF013", + "S101", + "S105", + "S108", + "S311", + "W605", +] +target-version = "py38" +exclude = [ + ".direnv", + ".git", + ".mypy_cache", + ".pytest_cache", + ".ruff_cache", + "__pypackages__", +] diff --git a/setup.py b/setup.py index e9c6341..500c39b 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- """ pip setup file """ @@ -39,6 +38,8 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ], diff --git a/tests/conftest.py b/tests/conftest.py index 476f0b7..45b8a24 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ """ bucketstore pytest configuration """ + import bucketstore import os import pytest @@ -15,10 +16,10 @@ @pytest.fixture(autouse=True) -def login() -> Generator: +def login() -> Generator: # noqa: PT004 """fixture that will automatically set the login variables.""" bucketstore.login("access_key", "secret_key") - yield + return @pytest.fixture diff --git a/tests/test_bucketstore.py b/tests/test_bucketstore.py index fb31843..41e78ac 100644 --- a/tests/test_bucketstore.py +++ b/tests/test_bucketstore.py @@ -1,6 +1,7 @@ """ pytest the bucketstore functionality """ + import bucketstore import json import os @@ -16,7 +17,7 @@ def dbg(text: str) -> None: text = json.dumps(text, sort_keys=True, indent=2) caller = sys._getframe(1) print("") - print("----- {} line {} ------".format(caller.f_code.co_name, caller.f_lineno)) + print(f"----- {caller.f_code.co_name} line {caller.f_lineno} ------") print(text) print("-----") print("") @@ -211,7 +212,7 @@ def test_key_download(bucket: bucketstore.S3Bucket, key: bucketstore.S3Key) -> N # test downloading to a file _, path = tempfile.mkstemp() key.download(path) - with open(path, "r") as file_0: + with open(path) as file_0: data = file_0.read() assert isinstance(data, str) assert "a testing value" in data @@ -221,7 +222,7 @@ def test_key_download(bucket: bucketstore.S3Bucket, key: bucketstore.S3Key) -> N _, path = tempfile.mkstemp() with open(path, "wb") as file_1: key.download(file_1) - with open(path, "r") as file_2: + with open(path) as file_2: data = file_2.read() assert isinstance(data, str) assert "a testing value" in data diff --git a/tox.ini b/tox.ini index 4dcea2a..d6cff82 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{36,37,38,39,310} +envlist = py{36,37,38,39,310,311,312} [testenv] commands =