Skip to content

Commit eb37d35

Browse files
authored
bump sqlalchemy to >2.0 (#7)
- Migrate sqlalchemy to 2.0 but not yet supported for the development version (2.1) - Sync tests and pre-commit configuration with the rest of the biocpy packages - Minor edits to tests
1 parent 51b2f76 commit eb37d35

18 files changed

+114
-44
lines changed

.github/workflows/pypi-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
4949
with:
5050
user: __token__
51-
password: ${{ secrets.PYPI_PASSWORD }}
51+
password: ${{ secrets.PYPI_PASSWORD }}

.github/workflows/pypi-test.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
1619

20+
name: Python ${{ matrix.python-version }}
1721
steps:
1822
- uses: actions/checkout@v2
19-
- name: Set up Python 3.9
23+
- name: Setup Python
2024
uses: actions/setup-python@v2
2125
with:
22-
python-version: 3.9
26+
python-version: ${{ matrix.python-version }}
27+
cache: 'pip'
2328
- name: Install dependencies
2429
run: |
2530
python -m pip install --upgrade pip
@@ -32,4 +37,4 @@ jobs:
3237
# # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3338
- name: Test with tox
3439
run: |
35-
tox
40+
tox

.pre-commit-config.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
exclude: '^docs/conf.py'
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.6.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: check-added-large-files
9+
- id: check-ast
10+
- id: check-json
11+
- id: check-merge-conflict
12+
- id: check-xml
13+
- id: check-yaml
14+
- id: debug-statements
15+
- id: end-of-file-fixer
16+
- id: requirements-txt-fixer
17+
- id: mixed-line-ending
18+
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
19+
20+
- repo: https://github.com/PyCQA/docformatter
21+
rev: v1.7.5
22+
hooks:
23+
- id: docformatter
24+
additional_dependencies: [tomli]
25+
args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
26+
# --config, ./pyproject.toml
27+
28+
- repo: https://github.com/psf/black
29+
rev: 24.4.0
30+
hooks:
31+
- id: black
32+
language_version: python3
33+
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
# Ruff version.
36+
rev: v0.3.7
37+
hooks:
38+
- id: ruff
39+
args: [--fix, --exit-non-zero-on-fix]
40+
41+
## If like to embrace black styles even in the docs:
42+
# - repo: https://github.com/asottile/blacken-docs
43+
# rev: v1.13.0
44+
# hooks:
45+
# - id: blacken-docs
46+
# additional_dependencies: [black]
47+
48+
## Check for misspells in documentation files:
49+
# - repo: https://github.com/codespell-project/codespell
50+
# rev: v2.2.5
51+
# hooks:
52+
# - id: codespell

AUTHORS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Contributors
22

33
* Jayaram Kancherla <[email protected]>
4-
* Max Hargreaves <[email protected]>
4+
* Max Hargreaves <[email protected]>

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## Version 0.1 (development)
44

5-
- Initial release
5+
- Initial release

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Package is published to [PyPI](https://pypi.org/project/pyBiocFileCache/)
1616
pip install pybiocfilecache
1717
```
1818

19-
#### Initialize a cache directory
19+
#### Initialize a cache directory
2020

2121
```
2222
from pybiocfilecache import BiocFileCache

docs/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
furo
12
# Requirements file for ReadTheDocs, check .readthedocs.yml.
23
# To build the module reference correctly, make sure every external package
34
# under `install_requires` in `setup.cfg` is also listed here!
45
# sphinx_rtd_theme
56
recommonmark
67
sphinx>=3.2.1
7-
furo

pyproject.toml

+15
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,18 @@ build-backend = "setuptools.build_meta"
66
[tool.setuptools_scm]
77
# See configuration details in https://github.com/pypa/setuptools_scm
88
version_scheme = "no-guess-dev"
9+
10+
[tool.ruff]
11+
line-length = 120
12+
src = ["src"]
13+
exclude = ["tests"]
14+
extend-ignore = ["F821"]
15+
16+
[tool.ruff.pydocstyle]
17+
convention = "google"
18+
19+
[tool.ruff.per-file-ignores]
20+
"__init__.py" = ["E402", "F401"]
21+
22+
[tool.black]
23+
force-exclude = "__init__.py"

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ package_dir =
4747
# For more information, check out https://semver.org/.
4848
install_requires =
4949
importlib-metadata; python_version<"3.8"
50-
sqlalchemy>=1.4,<2.0
50+
sqlalchemy>=2,<2.1
5151

5252
[options.packages.find]
5353
where = src

setup.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
"""
2-
Setup file for pyBiocFileCache.
3-
Use setup.cfg to configure your project.
1+
"""Setup file for pyBiocFileCache. Use setup.cfg to configure your project.
42
5-
This file was generated with PyScaffold 4.1.
6-
PyScaffold helps you to put up the scaffold of your new Python project.
7-
Learn more under: https://pyscaffold.org/
3+
This file was generated with PyScaffold 4.1.
4+
PyScaffold helps you to put up the scaffold of your new Python project.
5+
Learn more under: https://pyscaffold.org/
86
"""
7+
98
from setuptools import setup
109

1110
if __name__ == "__main__":

src/pybiocfilecache/BiocFileCache.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Python Implementation of BiocFileCache
3-
"""
1+
"""Python Implementation of BiocFileCache."""
42

53
import os
64
from pathlib import Path
@@ -21,9 +19,7 @@
2119

2220

2321
class BiocFileCache:
24-
"""
25-
Class to manage and cache files.
26-
"""
22+
"""Class to manage and cache files."""
2723

2824
def __init__(self, cacheDirOrPath: Union[str, Path] = create_tmp_dir()):
2925
"""Initialize BiocFileCache.
@@ -90,7 +86,13 @@ def add(
9086

9187
# create new record in the database
9288
res = Resource(
93-
**dict(rid=rid, rname=rname, rpath=rpath, rtype=rtype, fpath=str(fpath),)
89+
**dict(
90+
rid=rid,
91+
rname=rname,
92+
rpath=rpath,
93+
rtype=rtype,
94+
fpath=str(fpath),
95+
)
9496
)
9597

9698
# If this was higher up a parallel process could have added the key to
@@ -164,7 +166,7 @@ def _get(self, session: Session, rname: str) -> Optional[Resource]:
164166
return resource
165167

166168
def get(self, rname: str) -> Optional[Resource]:
167-
"""get resource by name from cache.
169+
"""Get resource by name from cache.
168170
169171
Args:
170172
rname (str): Name of the file to search.

src/pybiocfilecache/db/Base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
16-
"""Create the schema in the sqlite database
16+
"""Create the schema in the sqlite database.
1717
1818
Args:
1919
cache_dir (str): Location where the cache directory

src/pybiocfilecache/db/schema.py

-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ class Resource(Base):
3333

3434
def __repr__(self):
3535
return "<Resource(id='%s', rname='%s')>" % (self.id, self.rname)
36-

src/pybiocfilecache/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def create_tmp_dir() -> str:
12-
"""create a temporary directory.
12+
"""Create a temporary directory.
1313
1414
Returns:
1515
str: path to the directory
@@ -57,7 +57,7 @@ def copy_or_move(
5757

5858

5959
def setup_logging(loglevel):
60-
"""Setup basic logging
60+
"""Setup basic logging.
6161
6262
Args:
6363
loglevel (int): minimum loglevel for emitting messages

tests/conftest.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
"""
2-
Dummy conftest.py for pybiocfilecache.
1+
"""Dummy conftest.py for pybiocfilecache.
32
4-
If you don't know what this is for, just leave it empty.
5-
Read more about conftest.py under:
6-
- https://docs.pytest.org/en/stable/fixture.html
7-
- https://docs.pytest.org/en/stable/writing_plugins.html
3+
If you don't know what this is for, just leave it empty.
4+
Read more about conftest.py under:
5+
- https://docs.pytest.org/en/stable/fixture.html
6+
- https://docs.pytest.org/en/stable/writing_plugins.html
87
"""
98

109
# import pytest

tests/data/test1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test1
1+
test1

tests/data/test2.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test2
1+
test2

tests/test_cache.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import shutil
32

43
from pybiocfilecache.BiocFileCache import BiocFileCache
54

@@ -12,7 +11,7 @@
1211

1312
def test_create_cache():
1413
bfc = BiocFileCache(CACHE_DIR)
15-
assert os.path.exists(CACHE_DIR == True)
14+
assert os.path.exists(CACHE_DIR)
1615

1716
bfc.purge()
1817

@@ -22,16 +21,16 @@ def test_add_get_operations():
2221

2322
bfc.add("test1", os.getcwd() + "/tests/data/test1.txt")
2423
rec1 = bfc.get("test1")
25-
assert rec1 != None
24+
assert rec1 is not None
2625

2726
bfc.add("test2", os.getcwd() + "/tests/data/test2.txt")
2827
rec2 = bfc.get("test2")
29-
assert rec2 != None
28+
assert rec2 is not None
3029

31-
frec1 = open(rec1.rpath, "r").read()
30+
frec1 = open(rec1.rpath, "r").read().strip()
3231
assert frec1 == "test1"
3332

34-
frec2 = open(rec2.rpath, "r").read()
33+
frec2 = open(rec2.rpath, "r").read().strip()
3534
assert frec2 == "test2"
3635

3736
bfc.purge()
@@ -42,14 +41,14 @@ def test_remove_operations():
4241

4342
bfc.add("test1", os.getcwd() + "/tests/data/test1.txt")
4443
rec1 = bfc.get("test1")
45-
assert rec1 != None
44+
assert rec1 is not None
4645

4746
bfc.add("test2", os.getcwd() + "/tests/data/test2.txt")
4847
rec2 = bfc.get("test2")
49-
assert rec2 != None
48+
assert rec2 is not None
5049

5150
bfc.remove("test1")
5251
rec1 = bfc.get("test1")
53-
assert rec1 == None
52+
assert rec1 is None
5453

5554
bfc.purge()

0 commit comments

Comments
 (0)