pyBiocFileCache 0.2.2__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/.github/workflows/pypi-publish.yml +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/.github/workflows/pypi-test.yml +8 -3
- pybiocfilecache-0.3.1/.pre-commit-config.yaml +52 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/AUTHORS.md +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/CHANGELOG.md +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/PKG-INFO +12 -3
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/README.md +5 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/authors.md +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/changelog.md +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/readme.md +5 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/requirements.txt +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/pyproject.toml +15 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/setup.cfg +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/setup.py +5 -6
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/PKG-INFO +12 -3
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/SOURCES.txt +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/requires.txt +1 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pybiocfilecache/BiocFileCache.py +91 -46
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pybiocfilecache/db/Base.py +7 -5
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pybiocfilecache/db/schema.py +0 -1
- pybiocfilecache-0.3.1/src/pybiocfilecache/utils.py +89 -0
- pybiocfilecache-0.3.1/tests/conftest.py +9 -0
- pybiocfilecache-0.3.1/tests/data/test1.txt +1 -0
- pybiocfilecache-0.3.1/tests/data/test2.txt +1 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/tests/test_cache.py +16 -9
- pyBiocFileCache-0.2.2/src/pybiocfilecache/utils.py +0 -68
- pyBiocFileCache-0.2.2/temp.txt +0 -0
- pyBiocFileCache-0.2.2/tests/conftest.py +0 -10
- pyBiocFileCache-0.2.2/tests/data/test1.txt +0 -1
- pyBiocFileCache-0.2.2/tests/data/test2.txt +0 -1
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/.coveragerc +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/.gitignore +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/.readthedocs.yml +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/CONTRIBUTING.rst +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/LICENSE.txt +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/Makefile +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/_static/.gitignore +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/conf.py +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/contributing.rst +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/index.md +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/docs/license.rst +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/dependency_links.txt +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/not-zip-safe +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/top_level.txt +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pybiocfilecache/__init__.py +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pybiocfilecache/_exceptions.py +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pybiocfilecache/db/__init__.py +0 -0
- {pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/tox.ini +0 -0
|
@@ -13,13 +13,18 @@ jobs:
|
|
|
13
13
|
build:
|
|
14
14
|
|
|
15
15
|
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
|
|
16
19
|
|
|
20
|
+
name: Python ${{ matrix.python-version }}
|
|
17
21
|
steps:
|
|
18
22
|
- uses: actions/checkout@v2
|
|
19
|
-
- name:
|
|
23
|
+
- name: Setup Python
|
|
20
24
|
uses: actions/setup-python@v2
|
|
21
25
|
with:
|
|
22
|
-
python-version:
|
|
26
|
+
python-version: ${{ matrix.python-version }}
|
|
27
|
+
cache: 'pip'
|
|
23
28
|
- name: Install dependencies
|
|
24
29
|
run: |
|
|
25
30
|
python -m pip install --upgrade pip
|
|
@@ -32,4 +37,4 @@ jobs:
|
|
|
32
37
|
# # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
|
33
38
|
- name: Test with tox
|
|
34
39
|
run: |
|
|
35
|
-
tox
|
|
40
|
+
tox
|
|
@@ -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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyBiocFileCache
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: File based cache for resources and metadata
|
|
5
5
|
Home-page: https://github.com/epiviz/pyBiocFileCache
|
|
6
6
|
Author: jkanche
|
|
@@ -11,9 +11,18 @@ Platform: any
|
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
13
13
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
|
-
Provides-Extra: testing
|
|
15
14
|
License-File: LICENSE.txt
|
|
16
15
|
License-File: AUTHORS.md
|
|
16
|
+
Requires-Dist: importlib-metadata; python_version < "3.8"
|
|
17
|
+
Requires-Dist: sqlalchemy<2.1,>=2
|
|
18
|
+
Provides-Extra: testing
|
|
19
|
+
Requires-Dist: setuptools; extra == "testing"
|
|
20
|
+
Requires-Dist: pytest; extra == "testing"
|
|
21
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
22
|
+
|
|
23
|
+
[](https://pyscaffold.org/)
|
|
24
|
+
[](https://pypi.org/project/pyBiocFileCache/)
|
|
25
|
+

|
|
17
26
|
|
|
18
27
|
# pyBiocFileCache
|
|
19
28
|
|
|
@@ -29,7 +38,7 @@ Package is published to [PyPI](https://pypi.org/project/pyBiocFileCache/)
|
|
|
29
38
|
pip install pybiocfilecache
|
|
30
39
|
```
|
|
31
40
|
|
|
32
|
-
#### Initialize a cache directory
|
|
41
|
+
#### Initialize a cache directory
|
|
33
42
|
|
|
34
43
|
```
|
|
35
44
|
from pybiocfilecache import BiocFileCache
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
[](https://pyscaffold.org/)
|
|
2
|
+
[](https://pypi.org/project/pyBiocFileCache/)
|
|
3
|
+

|
|
4
|
+
|
|
1
5
|
# pyBiocFileCache
|
|
2
6
|
|
|
3
7
|
File system based cache for resources & metadata. Compatible with [BiocFileCache R package](https://github.com/Bioconductor/BiocFileCache)
|
|
@@ -12,7 +16,7 @@ Package is published to [PyPI](https://pypi.org/project/pyBiocFileCache/)
|
|
|
12
16
|
pip install pybiocfilecache
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
#### Initialize a cache directory
|
|
19
|
+
#### Initialize a cache directory
|
|
16
20
|
|
|
17
21
|
```
|
|
18
22
|
from pybiocfilecache import BiocFileCache
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
[](https://pyscaffold.org/)
|
|
2
|
+
[](https://pypi.org/project/pyBiocFileCache/)
|
|
3
|
+

|
|
4
|
+
|
|
1
5
|
# pyBiocFileCache
|
|
2
6
|
|
|
3
7
|
File system based cache for resources & metadata. Compatible with [BiocFileCache R package](https://github.com/Bioconductor/BiocFileCache)
|
|
@@ -12,7 +16,7 @@ Package is published to [PyPI](https://pypi.org/project/pyBiocFileCache/)
|
|
|
12
16
|
pip install pybiocfilecache
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
#### Initialize a cache directory
|
|
19
|
+
#### Initialize a cache directory
|
|
16
20
|
|
|
17
21
|
```
|
|
18
22
|
from pybiocfilecache import BiocFileCache
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
furo
|
|
1
2
|
# Requirements file for ReadTheDocs, check .readthedocs.yml.
|
|
2
3
|
# To build the module reference correctly, make sure every external package
|
|
3
4
|
# under `install_requires` in `setup.cfg` is also listed here!
|
|
4
5
|
# sphinx_rtd_theme
|
|
5
6
|
recommonmark
|
|
6
7
|
sphinx>=3.2.1
|
|
7
|
-
furo
|
|
@@ -6,3 +6,18 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
[tool.setuptools_scm]
|
|
7
7
|
# See configuration details in https://github.com/pypa/setuptools_scm
|
|
8
8
|
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"
|
|
@@ -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.
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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/
|
|
8
6
|
"""
|
|
7
|
+
|
|
9
8
|
from setuptools import setup
|
|
10
9
|
|
|
11
10
|
if __name__ == "__main__":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyBiocFileCache
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: File based cache for resources and metadata
|
|
5
5
|
Home-page: https://github.com/epiviz/pyBiocFileCache
|
|
6
6
|
Author: jkanche
|
|
@@ -11,9 +11,18 @@ Platform: any
|
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
13
13
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
|
-
Provides-Extra: testing
|
|
15
14
|
License-File: LICENSE.txt
|
|
16
15
|
License-File: AUTHORS.md
|
|
16
|
+
Requires-Dist: importlib-metadata; python_version < "3.8"
|
|
17
|
+
Requires-Dist: sqlalchemy<2.1,>=2
|
|
18
|
+
Provides-Extra: testing
|
|
19
|
+
Requires-Dist: setuptools; extra == "testing"
|
|
20
|
+
Requires-Dist: pytest; extra == "testing"
|
|
21
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
22
|
+
|
|
23
|
+
[](https://pyscaffold.org/)
|
|
24
|
+
[](https://pypi.org/project/pyBiocFileCache/)
|
|
25
|
+

|
|
17
26
|
|
|
18
27
|
# pyBiocFileCache
|
|
19
28
|
|
|
@@ -29,7 +38,7 @@ Package is published to [PyPI](https://pypi.org/project/pyBiocFileCache/)
|
|
|
29
38
|
pip install pybiocfilecache
|
|
30
39
|
```
|
|
31
40
|
|
|
32
|
-
#### Initialize a cache directory
|
|
41
|
+
#### Initialize a cache directory
|
|
33
42
|
|
|
34
43
|
```
|
|
35
44
|
from pybiocfilecache import BiocFileCache
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
.coveragerc
|
|
2
2
|
.gitignore
|
|
3
|
+
.pre-commit-config.yaml
|
|
3
4
|
.readthedocs.yml
|
|
4
5
|
AUTHORS.md
|
|
5
6
|
CHANGELOG.md
|
|
@@ -9,7 +10,6 @@ README.md
|
|
|
9
10
|
pyproject.toml
|
|
10
11
|
setup.cfg
|
|
11
12
|
setup.py
|
|
12
|
-
temp.txt
|
|
13
13
|
tox.ini
|
|
14
14
|
.github/workflows/pypi-publish.yml
|
|
15
15
|
.github/workflows/pypi-test.yml
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Python Implementation of BiocFileCache
|
|
3
|
-
"""
|
|
1
|
+
"""Python Implementation of BiocFileCache."""
|
|
4
2
|
|
|
5
3
|
import os
|
|
6
4
|
from pathlib import Path
|
|
7
5
|
from time import sleep, time
|
|
8
|
-
from typing import List, Optional, Union
|
|
6
|
+
from typing import List, Literal, Optional, Union
|
|
9
7
|
|
|
10
8
|
from sqlalchemy import func
|
|
11
9
|
from sqlalchemy.orm import Session
|
|
12
10
|
|
|
11
|
+
from ._exceptions import NoFpathError, RnameExistsError, RpathTimeoutError
|
|
13
12
|
from .db import create_schema
|
|
14
13
|
from .db.schema import Resource
|
|
15
14
|
from .utils import copy_or_move, create_tmp_dir, generate_id
|
|
16
|
-
from ._exceptions import NoFpathError, RnameExistsError, RpathTimeoutError
|
|
17
15
|
|
|
18
|
-
__author__ = "
|
|
16
|
+
__author__ = "Jayaram Kancherla"
|
|
19
17
|
__copyright__ = "jkanche"
|
|
20
18
|
__license__ = "MIT"
|
|
21
19
|
|
|
22
20
|
|
|
23
21
|
class BiocFileCache:
|
|
24
|
-
"""
|
|
25
|
-
Class to manage and cache files.
|
|
26
|
-
"""
|
|
22
|
+
"""Class to manage and cache files."""
|
|
27
23
|
|
|
28
24
|
def __init__(self, cacheDirOrPath: Union[str, Path] = create_tmp_dir()):
|
|
29
25
|
"""Initialize BiocFileCache.
|
|
30
26
|
|
|
31
27
|
Args:
|
|
32
|
-
cacheDirOrPath
|
|
33
|
-
|
|
28
|
+
cacheDirOrPath:
|
|
29
|
+
Path to cache directory.
|
|
30
|
+
|
|
31
|
+
Defaults to tmp location, :py:func:`~.utils.create_tmp_dir`.
|
|
34
32
|
|
|
35
33
|
Raises:
|
|
36
34
|
Exception: Failed to initialize cache.
|
|
@@ -55,42 +53,64 @@ class BiocFileCache:
|
|
|
55
53
|
self,
|
|
56
54
|
rname: str,
|
|
57
55
|
fpath: Union[str, Path],
|
|
58
|
-
rtype:
|
|
59
|
-
action:
|
|
56
|
+
rtype: Literal["local", "web", "relative"] = "local",
|
|
57
|
+
action: Literal["copy", "move", "asis"] = "copy",
|
|
60
58
|
ext: bool = False,
|
|
61
59
|
) -> Resource:
|
|
62
60
|
"""Add a resource from the provided `fpath` to cache as `rname`.
|
|
63
61
|
|
|
64
62
|
Args:
|
|
65
|
-
rname
|
|
66
|
-
|
|
67
|
-
rtype (str, optional): One of `"local"`, `"web"`, or `"relative"`.
|
|
68
|
-
Defaults to `"local"`.
|
|
69
|
-
action (str, optional): Either `"copy"`, `"move"` or `"asis"`.
|
|
70
|
-
Defaults to `"copy"`.
|
|
71
|
-
ext (bool, optional): Use filepath extension when storing in cache.
|
|
72
|
-
Defaults to `False`.
|
|
63
|
+
rname:
|
|
64
|
+
Name of the resource to add to cache.
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
fpath:
|
|
67
|
+
Location of the resource.
|
|
68
|
+
|
|
69
|
+
rtype:
|
|
70
|
+
One of ``local``, ``web``, or ``relative``.
|
|
71
|
+
Defaults to ``local``.
|
|
72
|
+
|
|
73
|
+
action:
|
|
74
|
+
Either ``copy``, ``move`` or ``asis``.
|
|
75
|
+
Defaults to ``copy``.
|
|
76
|
+
|
|
77
|
+
ext:
|
|
78
|
+
Whether to use filepath extension when storing in cache.
|
|
79
|
+
Defaults to `False`.
|
|
76
80
|
|
|
77
81
|
Raises:
|
|
78
|
-
NoFpathError:
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
NoFpathError:
|
|
83
|
+
When the `fpath` does not exist.
|
|
84
|
+
|
|
85
|
+
RnameExistsError:
|
|
86
|
+
When the `rname` already exists in the cache.
|
|
87
|
+
sqlalchemy exceptions: When something is up with the cache.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
Database record of the new resource in cache.
|
|
81
91
|
"""
|
|
82
92
|
if isinstance(fpath, str):
|
|
83
93
|
fpath = Path(fpath)
|
|
84
94
|
|
|
85
95
|
if not fpath.exists():
|
|
86
|
-
raise NoFpathError(f"Resource at {fpath} does not exist.")
|
|
96
|
+
raise NoFpathError(f"Resource at '{fpath}' does not exist.")
|
|
87
97
|
|
|
88
98
|
rid = generate_id()
|
|
89
|
-
rpath =
|
|
99
|
+
rpath = (
|
|
100
|
+
f"{self.cache}/{rid}" + (f".{fpath.suffix}" if ext else "")
|
|
101
|
+
if action != "asis"
|
|
102
|
+
else str(fpath)
|
|
103
|
+
)
|
|
90
104
|
|
|
91
105
|
# create new record in the database
|
|
92
106
|
res = Resource(
|
|
93
|
-
**dict(
|
|
107
|
+
**dict(
|
|
108
|
+
rid=rid,
|
|
109
|
+
rname=rname,
|
|
110
|
+
rpath=rpath,
|
|
111
|
+
rtype=rtype,
|
|
112
|
+
fpath=str(fpath),
|
|
113
|
+
)
|
|
94
114
|
)
|
|
95
115
|
|
|
96
116
|
# If this was higher up a parallel process could have added the key to
|
|
@@ -121,11 +141,15 @@ class BiocFileCache:
|
|
|
121
141
|
"""Search cache for a resource.
|
|
122
142
|
|
|
123
143
|
Args:
|
|
124
|
-
query
|
|
125
|
-
|
|
144
|
+
query:
|
|
145
|
+
Query string or keywords to search.
|
|
146
|
+
|
|
147
|
+
field:
|
|
148
|
+
Field to search.
|
|
149
|
+
Defaults to "rname".
|
|
126
150
|
|
|
127
151
|
Returns:
|
|
128
|
-
List
|
|
152
|
+
List of matching resources from cache.
|
|
129
153
|
"""
|
|
130
154
|
with self.sessionLocal() as session:
|
|
131
155
|
return (
|
|
@@ -138,11 +162,14 @@ class BiocFileCache:
|
|
|
138
162
|
"""Get a resource with `rname` from given `Session`.
|
|
139
163
|
|
|
140
164
|
Args:
|
|
141
|
-
session
|
|
142
|
-
|
|
165
|
+
session:
|
|
166
|
+
The `Session` object to use.
|
|
167
|
+
|
|
168
|
+
rname:
|
|
169
|
+
The `rname` of the `Resource` to get.
|
|
143
170
|
|
|
144
171
|
Returns:
|
|
145
|
-
|
|
172
|
+
The `Resource` for the `rname` if available.
|
|
146
173
|
"""
|
|
147
174
|
resource: Optional[Resource] = (
|
|
148
175
|
session.query(Resource).filter(Resource.rname == rname).first()
|
|
@@ -164,13 +191,14 @@ class BiocFileCache:
|
|
|
164
191
|
return resource
|
|
165
192
|
|
|
166
193
|
def get(self, rname: str) -> Optional[Resource]:
|
|
167
|
-
"""
|
|
194
|
+
"""Get resource by name from cache.
|
|
168
195
|
|
|
169
196
|
Args:
|
|
170
|
-
rname
|
|
197
|
+
rname:
|
|
198
|
+
Name of the file to search.
|
|
171
199
|
|
|
172
200
|
Returns:
|
|
173
|
-
|
|
201
|
+
Matched `Resource` from cache if exists.
|
|
174
202
|
"""
|
|
175
203
|
return self._get(self.sessionLocal(), rname)
|
|
176
204
|
|
|
@@ -178,7 +206,8 @@ class BiocFileCache:
|
|
|
178
206
|
"""Remove a resource from cache by name.
|
|
179
207
|
|
|
180
208
|
Args:
|
|
181
|
-
rname
|
|
209
|
+
rname:
|
|
210
|
+
Name of the resource to remove.
|
|
182
211
|
"""
|
|
183
212
|
with self.sessionLocal() as session:
|
|
184
213
|
res: Optional[Resource] = self._get(session, rname)
|
|
@@ -194,18 +223,30 @@ class BiocFileCache:
|
|
|
194
223
|
for file in os.scandir(self.cache):
|
|
195
224
|
os.remove(file.path)
|
|
196
225
|
|
|
226
|
+
return True
|
|
227
|
+
|
|
197
228
|
def update(
|
|
198
|
-
self,
|
|
229
|
+
self,
|
|
230
|
+
rname: str,
|
|
231
|
+
fpath: Union[str, Path],
|
|
232
|
+
action: Literal["copy", "move", "asis"] = "copy",
|
|
199
233
|
) -> Resource:
|
|
200
234
|
"""Update a resource in cache.
|
|
201
235
|
|
|
202
236
|
Args:
|
|
203
|
-
rname
|
|
204
|
-
|
|
205
|
-
|
|
237
|
+
rname:
|
|
238
|
+
Name of the resource in cache.
|
|
239
|
+
|
|
240
|
+
fpath:
|
|
241
|
+
New resource to replace existing file in cache.
|
|
242
|
+
|
|
243
|
+
action:
|
|
244
|
+
Either ``copy``, ``move`` or ``asis``.
|
|
245
|
+
|
|
246
|
+
Defaults to ``copy``.
|
|
206
247
|
|
|
207
248
|
Returns:
|
|
208
|
-
|
|
249
|
+
Updated resource record in cache.
|
|
209
250
|
"""
|
|
210
251
|
|
|
211
252
|
if isinstance(fpath, str):
|
|
@@ -218,8 +259,12 @@ class BiocFileCache:
|
|
|
218
259
|
res = self._get(session, rname)
|
|
219
260
|
|
|
220
261
|
if res is not None:
|
|
221
|
-
|
|
222
|
-
|
|
262
|
+
if action != "asis":
|
|
263
|
+
# copy the file to cache
|
|
264
|
+
copy_or_move(str(fpath), str(res.rpath), rname, action)
|
|
265
|
+
else:
|
|
266
|
+
res.rpath = str(fpath)
|
|
267
|
+
|
|
223
268
|
res.access_time = res.last_modified_time = func.now()
|
|
224
269
|
session.merge(res)
|
|
225
270
|
session.commit()
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
from typing import Tuple
|
|
2
|
+
|
|
1
3
|
from sqlalchemy import create_engine
|
|
2
4
|
from sqlalchemy.engine import Engine
|
|
3
5
|
|
|
4
6
|
# from sqlalchemy.ext.declarative import declarative_base
|
|
5
|
-
from sqlalchemy.orm import
|
|
6
|
-
from typing import Tuple
|
|
7
|
+
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
7
8
|
|
|
8
9
|
__author__ = "jkanche"
|
|
9
10
|
__copyright__ = "jkanche"
|
|
@@ -13,13 +14,14 @@ Base = declarative_base()
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
|
|
16
|
-
"""Create the schema in the sqlite database
|
|
17
|
+
"""Create the schema in the sqlite database.
|
|
17
18
|
|
|
18
19
|
Args:
|
|
19
|
-
cache_dir
|
|
20
|
+
cache_dir:
|
|
21
|
+
Location where the cache directory.
|
|
20
22
|
|
|
21
23
|
Returns:
|
|
22
|
-
|
|
24
|
+
A tuple of sqlalchemy engine and session maker.
|
|
23
25
|
"""
|
|
24
26
|
try:
|
|
25
27
|
engine = create_engine(
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
import tempfile
|
|
4
|
+
import uuid
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from shutil import copy2, move
|
|
7
|
+
from typing import Literal, Union
|
|
8
|
+
|
|
9
|
+
__author__ = "Jayaram Kancherla"
|
|
10
|
+
__copyright__ = "jkanche"
|
|
11
|
+
__license__ = "MIT"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def create_tmp_dir() -> str:
|
|
15
|
+
"""Create a temporary directory.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
Temporary path to the directory.
|
|
19
|
+
"""
|
|
20
|
+
return tempfile.mkdtemp()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def generate_id() -> str:
|
|
24
|
+
"""Generate uuid.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
Unique string for use as id.
|
|
28
|
+
"""
|
|
29
|
+
return uuid.uuid4().hex
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def copy_or_move(
|
|
33
|
+
source: Union[str, Path],
|
|
34
|
+
target: Union[str, Path],
|
|
35
|
+
rname: str,
|
|
36
|
+
action: Literal["copy", "move", "asis"] = "copy",
|
|
37
|
+
) -> None:
|
|
38
|
+
"""Copy or move a resource from ``source`` to ``target``.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
source:
|
|
42
|
+
Source location of the resource to copy of move.
|
|
43
|
+
|
|
44
|
+
target:
|
|
45
|
+
Destination to copy of move to.
|
|
46
|
+
|
|
47
|
+
rname:
|
|
48
|
+
Name of resource to add to cache.
|
|
49
|
+
|
|
50
|
+
action:
|
|
51
|
+
Copy of move file from source.
|
|
52
|
+
Defaults to copy.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
ValueError:
|
|
56
|
+
If action is not `copy`, `move` or `asis`.
|
|
57
|
+
|
|
58
|
+
Exception:
|
|
59
|
+
Error storing resource in the cache directory.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
if action not in ["copy", "move", "asis"]:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"Action must be either 'move', 'copy' or 'asis', provided {action}."
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
if action == "copy":
|
|
69
|
+
copy2(source, target)
|
|
70
|
+
elif action == "move":
|
|
71
|
+
move(str(source), target)
|
|
72
|
+
elif action == "asis":
|
|
73
|
+
pass
|
|
74
|
+
except Exception as e:
|
|
75
|
+
raise Exception(
|
|
76
|
+
f"Error storing resource: '{rname}' from: '{source}' in '{target}'.",
|
|
77
|
+
) from e
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def setup_logging(loglevel):
|
|
81
|
+
"""Setup basic logging.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
loglevel (int): minimum loglevel for emitting messages
|
|
85
|
+
"""
|
|
86
|
+
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
|
|
87
|
+
logging.basicConfig(
|
|
88
|
+
level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
|
|
89
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Dummy conftest.py for pybiocfilecache.
|
|
2
|
+
|
|
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
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# import pytest
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test2
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import shutil
|
|
3
2
|
|
|
4
3
|
from pybiocfilecache.BiocFileCache import BiocFileCache
|
|
5
4
|
|
|
@@ -12,7 +11,7 @@ CACHE_DIR = os.getcwd() + "/cache"
|
|
|
12
11
|
|
|
13
12
|
def test_create_cache():
|
|
14
13
|
bfc = BiocFileCache(CACHE_DIR)
|
|
15
|
-
assert os.path.exists(CACHE_DIR
|
|
14
|
+
assert os.path.exists(CACHE_DIR)
|
|
16
15
|
|
|
17
16
|
bfc.purge()
|
|
18
17
|
|
|
@@ -22,18 +21,26 @@ def test_add_get_operations():
|
|
|
22
21
|
|
|
23
22
|
bfc.add("test1", os.getcwd() + "/tests/data/test1.txt")
|
|
24
23
|
rec1 = bfc.get("test1")
|
|
25
|
-
assert rec1
|
|
24
|
+
assert rec1 is not None
|
|
26
25
|
|
|
27
26
|
bfc.add("test2", os.getcwd() + "/tests/data/test2.txt")
|
|
28
27
|
rec2 = bfc.get("test2")
|
|
29
|
-
assert rec2
|
|
28
|
+
assert rec2 is not None
|
|
30
29
|
|
|
31
|
-
frec1 = open(rec1.rpath, "r").read()
|
|
30
|
+
frec1 = open(rec1.rpath, "r").read().strip()
|
|
32
31
|
assert frec1 == "test1"
|
|
33
32
|
|
|
34
|
-
frec2 = open(rec2.rpath, "r").read()
|
|
33
|
+
frec2 = open(rec2.rpath, "r").read().strip()
|
|
35
34
|
assert frec2 == "test2"
|
|
36
35
|
|
|
36
|
+
bfc.add("test3_asis", os.getcwd() + "/tests/data/test2.txt", action="asis")
|
|
37
|
+
rec3 = bfc.get("test3_asis")
|
|
38
|
+
assert rec3 is not None
|
|
39
|
+
assert rec3.rpath == os.getcwd() + "/tests/data/test2.txt"
|
|
40
|
+
|
|
41
|
+
frec3 = open(rec3.rpath, "r").read().strip()
|
|
42
|
+
assert frec3 == "test2"
|
|
43
|
+
|
|
37
44
|
bfc.purge()
|
|
38
45
|
|
|
39
46
|
|
|
@@ -42,14 +49,14 @@ def test_remove_operations():
|
|
|
42
49
|
|
|
43
50
|
bfc.add("test1", os.getcwd() + "/tests/data/test1.txt")
|
|
44
51
|
rec1 = bfc.get("test1")
|
|
45
|
-
assert rec1
|
|
52
|
+
assert rec1 is not None
|
|
46
53
|
|
|
47
54
|
bfc.add("test2", os.getcwd() + "/tests/data/test2.txt")
|
|
48
55
|
rec2 = bfc.get("test2")
|
|
49
|
-
assert rec2
|
|
56
|
+
assert rec2 is not None
|
|
50
57
|
|
|
51
58
|
bfc.remove("test1")
|
|
52
59
|
rec1 = bfc.get("test1")
|
|
53
|
-
assert rec1
|
|
60
|
+
assert rec1 is None
|
|
54
61
|
|
|
55
62
|
bfc.purge()
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import tempfile
|
|
2
|
-
import uuid
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from shutil import copy2, move
|
|
5
|
-
|
|
6
|
-
from typing import Union
|
|
7
|
-
import logging
|
|
8
|
-
import sys
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def create_tmp_dir() -> str:
|
|
12
|
-
"""create a temporary directory.
|
|
13
|
-
|
|
14
|
-
Returns:
|
|
15
|
-
str: path to the directory
|
|
16
|
-
"""
|
|
17
|
-
return tempfile.mkdtemp()
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def generate_id() -> str:
|
|
21
|
-
"""Generate uuid.
|
|
22
|
-
|
|
23
|
-
Returns:
|
|
24
|
-
str: unique string for use as id
|
|
25
|
-
"""
|
|
26
|
-
return uuid.uuid4().hex
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def copy_or_move(
|
|
30
|
-
source: Union[str, Path], target: Union[str, Path], rname: str, action: str = "copy"
|
|
31
|
-
) -> None:
|
|
32
|
-
"""Copy or move a resource from `source` to `target`
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
source (Union[str, Path]): source location of the resource to copy of move.
|
|
36
|
-
target (Union[str, Path]): destination to copy of move to.
|
|
37
|
-
rname (str): Name of resource to add to cache
|
|
38
|
-
action (str): copy of move file from source. Defaults to copy.
|
|
39
|
-
|
|
40
|
-
Raises:
|
|
41
|
-
ValueError: if action is not `copy` or `move`.
|
|
42
|
-
Exception: Error storing resource in the cache directory.
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
if action not in ["copy", "move"]:
|
|
46
|
-
raise ValueError(f"Action must be either 'move' or 'copy', provided {action}")
|
|
47
|
-
|
|
48
|
-
try:
|
|
49
|
-
if action == "copy":
|
|
50
|
-
copy2(source, target)
|
|
51
|
-
elif action == "move":
|
|
52
|
-
move(str(source), target)
|
|
53
|
-
except Exception as e:
|
|
54
|
-
raise Exception(
|
|
55
|
-
f"Error storing resource: '{rname}' from: '{source}' in '{target}'",
|
|
56
|
-
) from e
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def setup_logging(loglevel):
|
|
60
|
-
"""Setup basic logging
|
|
61
|
-
|
|
62
|
-
Args:
|
|
63
|
-
loglevel (int): minimum loglevel for emitting messages
|
|
64
|
-
"""
|
|
65
|
-
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
|
|
66
|
-
logging.basicConfig(
|
|
67
|
-
level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
|
|
68
|
-
)
|
pyBiocFileCache-0.2.2/temp.txt
DELETED
|
File without changes
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Dummy conftest.py for pybiocfilecache.
|
|
3
|
-
|
|
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
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
# import pytest
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
test1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
test2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyBiocFileCache-0.2.2 → pybiocfilecache-0.3.1}/src/pyBiocFileCache.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|