Skip to content

Commit abdea76

Browse files
committed
fixup github actions, fixup setup.py, add pyproject.toml, replace mypy and prospector with ruff
1 parent 4572706 commit abdea76

File tree

10 files changed

+125
-127
lines changed

10 files changed

+125
-127
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
12-
- name: set up python
13-
uses: actions/setup-python@v2
11+
- uses: actions/checkout@v4.1.7
12+
- uses: actions/setup-python@v5
1413
with:
1514
python-version: '3.x'
16-
- name: install dependencies
17-
run: |
15+
- run: |
1816
python -m pip install --upgrade pip
1917
pip install setuptools wheel twine
2018
sed -i -E "s#VERSION#${GITHUB_REF/refs\/tags\//}#g" ./setup.py
2119
sed -i -E "s#VERSION#${GITHUB_REF/refs\/tags\//}#g" ./bucketstore.py
22-
- name: build and publish
23-
env:
20+
- env:
2421
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
2522
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
2623
run: |

.github/workflows/test.yml

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,32 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
prospector:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- uses: actions/checkout@v2
17-
- uses: jpetrucciani/prospector-check@master
18-
mypy:
19-
runs-on: ubuntu-latest
13+
ruff:
14+
runs-on: ubuntu-24.04
2015
steps:
21-
- uses: actions/checkout@v2
22-
- uses: jpetrucciani/mypy-check@master
23-
with:
24-
path: 'bucketstore.py'
16+
- uses: actions/checkout@v4.1.7
17+
- uses: jpetrucciani/ruff-check@main
2518
black:
2619
runs-on: ubuntu-latest
2720
steps:
28-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v4.1.7
2922
- uses: jpetrucciani/black-check@master
3023
with:
3124
path: 'bucketstore.py'
3225
tests:
3326
runs-on: ubuntu-latest
34-
needs: [mypy, prospector, black]
27+
needs: [ruff, black]
3528
strategy:
3629
matrix:
37-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
30+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
3831
name: python ${{ matrix.python-version }} tests
3932
steps:
40-
- uses: actions/checkout@v2
41-
- name: setup python
42-
uses: actions/setup-python@v2
33+
- uses: actions/checkout@v4.1.7
34+
- uses: actions/setup-python@v5
4335
with:
4436
python-version: ${{ matrix.python-version }}
4537
architecture: x64
46-
- name: install requirements
47-
run: |
38+
- run: |
4839
pip install -r requirements.txt
4940
pip install -r requirements.dev.txt
50-
- name: run Tox
51-
run: tox -e py
41+
- run: tox -e py

.prospector.yaml

Lines changed: 0 additions & 70 deletions
This file was deleted.

bucketstore.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
bucketstore module
33
"""
4+
45
import io
56
import os
67
import os.path
@@ -31,7 +32,7 @@ def __len__(self) -> int:
3132
return self.size()
3233

3334
@property
34-
def _boto_object(self): # type: ignore
35+
def _boto_object(self): # noqa: ANN202
3536
"""the underlying boto3 s3 key object"""
3637
return self.bucket._boto_s3.Object(self.bucket.name, self.name)
3738

@@ -98,9 +99,11 @@ def delete(
9899
def is_public(self) -> bool:
99100
"""returns True if the public-read ACL is set for the Key."""
100101
for grant in self._boto_object.Acl().grants:
101-
if "AllUsers" in grant["Grantee"].get("URI", ""):
102-
if grant["Permission"] == "READ":
103-
return True
102+
if (
103+
"AllUsers" in grant["Grantee"].get("URI", "")
104+
and grant["Permission"] == "READ"
105+
):
106+
return True
104107

105108
return False
106109

@@ -164,7 +167,7 @@ def __init__(
164167
self._boto_bucket = self._boto_s3.Bucket(self.name)
165168

166169
# Check if the bucket exists.
167-
if not self._boto_s3.Bucket(self.name) in self._boto_s3.buckets.all():
170+
if self._boto_s3.Bucket(self.name) not in self._boto_s3.buckets.all():
168171
if create:
169172
# Create the bucket.
170173
self._boto_s3.create_bucket(Bucket=self.name)
@@ -213,9 +216,11 @@ def list(self, prefix: str = None, legacy_api: bool = False) -> List:
213216
def is_public(self) -> bool:
214217
"""returns True if the public-read ACL is set for the bucket."""
215218
for grant in self._boto_bucket.Acl().grants:
216-
if "AllUsers" in grant["Grantee"].get("URI", ""):
217-
if grant["Permission"] == "READ":
218-
return True
219+
if (
220+
"AllUsers" in grant["Grantee"].get("URI", "")
221+
and grant["Permission"] == "READ"
222+
):
223+
return True
219224

220225
return False
221226

default.nix

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
{ jacobi ? import
2-
(
3-
fetchTarball {
4-
name = "jpetrucciani-2022-08-17";
5-
url = "https://github.com/jpetrucciani/nix/archive/9e8f5c0b0f7f69257f7ff1c2032cbadbc3da7d25.tar.gz";
6-
sha256 = "1vyjwlhbqxfmm4xpvwyzvdl8k5jd5wg83avxlwpjkfh8yndm0bny";
7-
}
8-
)
1+
{ pkgs ? import
2+
(fetchTarball {
3+
name = "jpetrucciani-2024-08-27";
4+
url = "https://github.com/jpetrucciani/nix/archive/20a58e6a4fccb574caef9b764585609b8d4fbd7d.tar.gz";
5+
sha256 = "0ksjkhcrd0h5zb8a5x6mbpn491gjs0n7rq9mxxvx9k3mnfjfaq5y";
6+
})
97
{ }
108
}:
119
let
12-
inherit (jacobi.hax) ifIsLinux ifIsDarwin;
10+
inherit (pkgs.hax) ifIsLinux ifIsDarwin;
1311

1412
name = "bucketstore";
15-
tools = with jacobi; {
13+
tools = with pkgs; {
1614
cli = [
1715
jq
1816
nixpkgs-fmt
1917
];
2018
python = [
21-
(python310.withPackages (p: with p; [
19+
(python311.withPackages (p: with p; [
2220
boto3
2321

2422
# dev
@@ -29,9 +27,9 @@ let
2927
]))
3028
];
3129
};
32-
33-
env = jacobi.enviro {
34-
inherit name tools;
30+
paths = pkgs.lib.flatten [ (builtins.attrValues tools) ];
31+
env = pkgs.buildEnv {
32+
inherit name paths; buildInputs = paths;
3533
};
3634
in
3735
env

pyproject.toml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[tool.ruff]
2+
line-length = 100
3+
lint.select = [
4+
"A",
5+
"ANN",
6+
"ARG",
7+
"B",
8+
"C4",
9+
"D",
10+
"E",
11+
"F",
12+
"ICN",
13+
"ISC",
14+
"N",
15+
"PD",
16+
"PGH",
17+
"PLR",
18+
"PLW",
19+
"PIE",
20+
"PT",
21+
"Q",
22+
"RET",
23+
"RUF",
24+
"S",
25+
"SIM",
26+
"TID",
27+
"UP",
28+
"W",
29+
"YTT",
30+
]
31+
lint.ignore = [
32+
"A001",
33+
"A003",
34+
"ANN101",
35+
"ANN102",
36+
"ANN401",
37+
"B008",
38+
"B017",
39+
"B019",
40+
"C405",
41+
"D103",
42+
"D107",
43+
"D200",
44+
"D202",
45+
"D203",
46+
"D205",
47+
"D212",
48+
"D400",
49+
"D401",
50+
"D403",
51+
"D404",
52+
"D415",
53+
"E501",
54+
"N818",
55+
"PGH003",
56+
"PGH004",
57+
"PLR2004",
58+
"PT011",
59+
"PT012",
60+
"RUF013",
61+
"S101",
62+
"S105",
63+
"S108",
64+
"S311",
65+
"W605",
66+
]
67+
target-version = "py38"
68+
exclude = [
69+
".direnv",
70+
".git",
71+
".mypy_cache",
72+
".pytest_cache",
73+
".ruff_cache",
74+
"__pypackages__",
75+
]

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32
"""
43
pip setup file
54
"""
@@ -39,6 +38,8 @@
3938
"Programming Language :: Python :: 3.8",
4039
"Programming Language :: Python :: 3.9",
4140
"Programming Language :: Python :: 3.10",
41+
"Programming Language :: Python :: 3.11",
42+
"Programming Language :: Python :: 3.12",
4243
"Programming Language :: Python :: Implementation :: CPython",
4344
"Programming Language :: Python :: Implementation :: PyPy",
4445
],

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
bucketstore pytest configuration
33
"""
4+
45
import bucketstore
56
import os
67
import pytest
@@ -15,10 +16,10 @@
1516

1617

1718
@pytest.fixture(autouse=True)
18-
def login() -> Generator:
19+
def login() -> Generator: # noqa: PT004
1920
"""fixture that will automatically set the login variables."""
2021
bucketstore.login("access_key", "secret_key")
21-
yield
22+
return
2223

2324

2425
@pytest.fixture

tests/test_bucketstore.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
pytest the bucketstore functionality
33
"""
4+
45
import bucketstore
56
import json
67
import os
@@ -16,7 +17,7 @@ def dbg(text: str) -> None:
1617
text = json.dumps(text, sort_keys=True, indent=2)
1718
caller = sys._getframe(1)
1819
print("")
19-
print("----- {} line {} ------".format(caller.f_code.co_name, caller.f_lineno))
20+
print(f"----- {caller.f_code.co_name} line {caller.f_lineno} ------")
2021
print(text)
2122
print("-----")
2223
print("")
@@ -211,7 +212,7 @@ def test_key_download(bucket: bucketstore.S3Bucket, key: bucketstore.S3Key) -> N
211212
# test downloading to a file
212213
_, path = tempfile.mkstemp()
213214
key.download(path)
214-
with open(path, "r") as file_0:
215+
with open(path) as file_0:
215216
data = file_0.read()
216217
assert isinstance(data, str)
217218
assert "a testing value" in data
@@ -221,7 +222,7 @@ def test_key_download(bucket: bucketstore.S3Bucket, key: bucketstore.S3Key) -> N
221222
_, path = tempfile.mkstemp()
222223
with open(path, "wb") as file_1:
223224
key.download(file_1)
224-
with open(path, "r") as file_2:
225+
with open(path) as file_2:
225226
data = file_2.read()
226227
assert isinstance(data, str)
227228
assert "a testing value" in data

0 commit comments

Comments
 (0)