Skip to content

Commit

Permalink
fixup github actions, fixup setup.py, add pyproject.toml, replace myp…
Browse files Browse the repository at this point in the history
…y and prospector with ruff
  • Loading branch information
jpetrucciani committed Aug 27, 2024
1 parent 4572706 commit abdea76
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 127 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- 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: |
Expand Down
32 changes: 11 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- 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/[email protected]
- 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
70 changes: 0 additions & 70 deletions .prospector.yaml

This file was deleted.

21 changes: 13 additions & 8 deletions bucketstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
bucketstore module
"""

import io
import os
import os.path
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
26 changes: 12 additions & 14 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
75 changes: 75 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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__",
]
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
pip setup file
"""
Expand Down Expand Up @@ -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",
],
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
bucketstore pytest configuration
"""

import bucketstore
import os
import pytest
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/test_bucketstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
pytest the bucketstore functionality
"""

import bucketstore
import json
import os
Expand All @@ -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("")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit abdea76

Please sign in to comment.