Skip to content

Commit

Permalink
bump sqlalchemy to >2.0 (#7)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jkanche authored May 5, 2024
1 parent 51b2f76 commit eb37d35
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
password: ${{ secrets.PYPI_PASSWORD }}
11 changes: 8 additions & 3 deletions .github/workflows/pypi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]

name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -32,4 +37,4 @@ jobs:
# # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with tox
run: |
tox
tox
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
exclude: '^docs/conf.py'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-ast
- id: check-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: mixed-line-ending
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
# --config, ./pyproject.toml

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.7
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

## If like to embrace black styles even in the docs:
# - repo: https://github.com/asottile/blacken-docs
# rev: v1.13.0
# hooks:
# - id: blacken-docs
# additional_dependencies: [black]

## Check for misspells in documentation files:
# - repo: https://github.com/codespell-project/codespell
# rev: v2.2.5
# hooks:
# - id: codespell
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributors

* Jayaram Kancherla <[email protected]>
* Max Hargreaves <[email protected]>
* Max Hargreaves <[email protected]>
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Version 0.1 (development)

- Initial release
- Initial release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Package is published to [PyPI](https://pypi.org/project/pyBiocFileCache/)
pip install pybiocfilecache
```

#### Initialize a cache directory
#### Initialize a cache directory

```
from pybiocfilecache import BiocFileCache
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
furo
# Requirements file for ReadTheDocs, check .readthedocs.yml.
# To build the module reference correctly, make sure every external package
# under `install_requires` in `setup.cfg` is also listed here!
# sphinx_rtd_theme
recommonmark
sphinx>=3.2.1
furo
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
# See configuration details in https://github.com/pypa/setuptools_scm
version_scheme = "no-guess-dev"

[tool.ruff]
line-length = 120
src = ["src"]
exclude = ["tests"]
extend-ignore = ["F821"]

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.per-file-ignores]
"__init__.py" = ["E402", "F401"]

[tool.black]
force-exclude = "__init__.py"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ package_dir =
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
sqlalchemy>=1.4,<2.0
sqlalchemy>=2,<2.1

[options.packages.find]
where = src
Expand Down
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
Setup file for pyBiocFileCache.
Use setup.cfg to configure your project.
"""Setup file for pyBiocFileCache. Use setup.cfg to configure your project.
This file was generated with PyScaffold 4.1.
PyScaffold helps you to put up the scaffold of your new Python project.
Learn more under: https://pyscaffold.org/
This file was generated with PyScaffold 4.1.
PyScaffold helps you to put up the scaffold of your new Python project.
Learn more under: https://pyscaffold.org/
"""

from setuptools import setup

if __name__ == "__main__":
Expand Down
18 changes: 10 additions & 8 deletions src/pybiocfilecache/BiocFileCache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Python Implementation of BiocFileCache
"""
"""Python Implementation of BiocFileCache."""

import os
from pathlib import Path
Expand All @@ -21,9 +19,7 @@


class BiocFileCache:
"""
Class to manage and cache files.
"""
"""Class to manage and cache files."""

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

# create new record in the database
res = Resource(
**dict(rid=rid, rname=rname, rpath=rpath, rtype=rtype, fpath=str(fpath),)
**dict(
rid=rid,
rname=rname,
rpath=rpath,
rtype=rtype,
fpath=str(fpath),
)
)

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

def get(self, rname: str) -> Optional[Resource]:
"""get resource by name from cache.
"""Get resource by name from cache.
Args:
rname (str): Name of the file to search.
Expand Down
2 changes: 1 addition & 1 deletion src/pybiocfilecache/db/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
"""Create the schema in the sqlite database
"""Create the schema in the sqlite database.
Args:
cache_dir (str): Location where the cache directory
Expand Down
1 change: 0 additions & 1 deletion src/pybiocfilecache/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ class Resource(Base):

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

4 changes: 2 additions & 2 deletions src/pybiocfilecache/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def create_tmp_dir() -> str:
"""create a temporary directory.
"""Create a temporary directory.
Returns:
str: path to the directory
Expand Down Expand Up @@ -57,7 +57,7 @@ def copy_or_move(


def setup_logging(loglevel):
"""Setup basic logging
"""Setup basic logging.
Args:
loglevel (int): minimum loglevel for emitting messages
Expand Down
11 changes: 5 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
Dummy conftest.py for pybiocfilecache.
"""Dummy conftest.py for pybiocfilecache.
If you don't know what this is for, just leave it empty.
Read more about conftest.py under:
- https://docs.pytest.org/en/stable/fixture.html
- https://docs.pytest.org/en/stable/writing_plugins.html
If you don't know what this is for, just leave it empty.
Read more about conftest.py under:
- https://docs.pytest.org/en/stable/fixture.html
- https://docs.pytest.org/en/stable/writing_plugins.html
"""

# import pytest
2 changes: 1 addition & 1 deletion tests/data/test1.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test1
test1
2 changes: 1 addition & 1 deletion tests/data/test2.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test2
test2
17 changes: 8 additions & 9 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import shutil

from pybiocfilecache.BiocFileCache import BiocFileCache

Expand All @@ -12,7 +11,7 @@

def test_create_cache():
bfc = BiocFileCache(CACHE_DIR)
assert os.path.exists(CACHE_DIR == True)
assert os.path.exists(CACHE_DIR)

bfc.purge()

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

bfc.add("test1", os.getcwd() + "/tests/data/test1.txt")
rec1 = bfc.get("test1")
assert rec1 != None
assert rec1 is not None

bfc.add("test2", os.getcwd() + "/tests/data/test2.txt")
rec2 = bfc.get("test2")
assert rec2 != None
assert rec2 is not None

frec1 = open(rec1.rpath, "r").read()
frec1 = open(rec1.rpath, "r").read().strip()
assert frec1 == "test1"

frec2 = open(rec2.rpath, "r").read()
frec2 = open(rec2.rpath, "r").read().strip()
assert frec2 == "test2"

bfc.purge()
Expand All @@ -42,14 +41,14 @@ def test_remove_operations():

bfc.add("test1", os.getcwd() + "/tests/data/test1.txt")
rec1 = bfc.get("test1")
assert rec1 != None
assert rec1 is not None

bfc.add("test2", os.getcwd() + "/tests/data/test2.txt")
rec2 = bfc.get("test2")
assert rec2 != None
assert rec2 is not None

bfc.remove("test1")
rec1 = bfc.get("test1")
assert rec1 == None
assert rec1 is None

bfc.purge()

0 comments on commit eb37d35

Please sign in to comment.