diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 91ce4a6..7b591a2 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -48,4 +48,4 @@ jobs: uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 with: user: __token__ - password: ${{ secrets.PYPI_PASSWORD }} \ No newline at end of file + password: ${{ secrets.PYPI_PASSWORD }} diff --git a/.github/workflows/pypi-test.yml b/.github/workflows/pypi-test.yml index 812d62d..27791f1 100644 --- a/.github/workflows/pypi-test.yml +++ b/.github/workflows/pypi-test.yml @@ -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 @@ -32,4 +37,4 @@ jobs: # # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with tox run: | - tox \ No newline at end of file + tox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d7f72c3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/AUTHORS.md b/AUTHORS.md index 33a7be7..e3d9698 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,4 +1,4 @@ # Contributors * Jayaram Kancherla -* Max Hargreaves \ No newline at end of file +* Max Hargreaves diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca3707..7a9e220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,4 @@ ## Version 0.1 (development) -- Initial release \ No newline at end of file +- Initial release diff --git a/README.md b/README.md index 85cc62b..976823d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/requirements.txt b/docs/requirements.txt index 2662cf2..0aec8ef 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -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 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 2c63dbb..a7cea75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/setup.cfg b/setup.cfg index f906052..5ec4014 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py index 996c5f0..2525df1 100644 --- a/setup.py +++ b/setup.py @@ -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__": diff --git a/src/pybiocfilecache/BiocFileCache.py b/src/pybiocfilecache/BiocFileCache.py index d70393e..fa4ef6b 100644 --- a/src/pybiocfilecache/BiocFileCache.py +++ b/src/pybiocfilecache/BiocFileCache.py @@ -1,6 +1,4 @@ -""" -Python Implementation of BiocFileCache -""" +"""Python Implementation of BiocFileCache.""" import os from pathlib import Path @@ -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. @@ -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 @@ -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. diff --git a/src/pybiocfilecache/db/Base.py b/src/pybiocfilecache/db/Base.py index 27f528d..0251f90 100644 --- a/src/pybiocfilecache/db/Base.py +++ b/src/pybiocfilecache/db/Base.py @@ -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 diff --git a/src/pybiocfilecache/db/schema.py b/src/pybiocfilecache/db/schema.py index bc544f8..548ac6f 100644 --- a/src/pybiocfilecache/db/schema.py +++ b/src/pybiocfilecache/db/schema.py @@ -33,4 +33,3 @@ class Resource(Base): def __repr__(self): return "" % (self.id, self.rname) - diff --git a/src/pybiocfilecache/utils.py b/src/pybiocfilecache/utils.py index 622997b..c0b71da 100644 --- a/src/pybiocfilecache/utils.py +++ b/src/pybiocfilecache/utils.py @@ -9,7 +9,7 @@ def create_tmp_dir() -> str: - """create a temporary directory. + """Create a temporary directory. Returns: str: path to the directory @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 2c26440..bf9f673 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/data/test1.txt b/tests/data/test1.txt index f079749..a5bce3f 100644 --- a/tests/data/test1.txt +++ b/tests/data/test1.txt @@ -1 +1 @@ -test1 \ No newline at end of file +test1 diff --git a/tests/data/test2.txt b/tests/data/test2.txt index d606037..180cf83 100644 --- a/tests/data/test2.txt +++ b/tests/data/test2.txt @@ -1 +1 @@ -test2 \ No newline at end of file +test2 diff --git a/tests/test_cache.py b/tests/test_cache.py index d896f78..bbeebc7 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,5 +1,4 @@ import os -import shutil from pybiocfilecache.BiocFileCache import BiocFileCache @@ -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() @@ -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() @@ -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()