pyBiocFileCache 0.3.1__tar.gz → 0.4.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.
Files changed (47) hide show
  1. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/.github/workflows/pypi-test.yml +2 -2
  2. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/.pre-commit-config.yaml +14 -13
  3. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/AUTHORS.md +1 -0
  4. pybiocfilecache-0.4.1/CHANGELOG.md +9 -0
  5. {pybiocfilecache-0.3.1/src/pyBiocFileCache.egg-info → pybiocfilecache-0.4.1}/PKG-INFO +1 -1
  6. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/authors.md +1 -0
  7. pybiocfilecache-0.4.1/docs/changelog.md +9 -0
  8. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/conf.py +3 -8
  9. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1/src/pyBiocFileCache.egg-info}/PKG-INFO +1 -1
  10. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pyBiocFileCache.egg-info/SOURCES.txt +2 -2
  11. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pybiocfilecache/BiocFileCache.py +14 -17
  12. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pybiocfilecache/__init__.py +2 -2
  13. pybiocfilecache-0.4.1/src/pybiocfilecache/const.py +1 -0
  14. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pybiocfilecache/db/__init__.py +1 -1
  15. pybiocfilecache-0.4.1/src/pybiocfilecache/db/db_config.py +82 -0
  16. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pybiocfilecache/utils.py +2 -6
  17. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/tests/conftest.py +1 -2
  18. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/tests/test_cache.py +3 -0
  19. pybiocfilecache-0.3.1/CHANGELOG.md +0 -5
  20. pybiocfilecache-0.3.1/docs/changelog.md +0 -5
  21. pybiocfilecache-0.3.1/src/pybiocfilecache/db/Base.py +0 -36
  22. pybiocfilecache-0.3.1/src/pybiocfilecache/db/schema.py +0 -35
  23. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/.coveragerc +0 -0
  24. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/.github/workflows/pypi-publish.yml +0 -0
  25. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/.gitignore +0 -0
  26. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/.readthedocs.yml +0 -0
  27. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/CONTRIBUTING.rst +0 -0
  28. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/LICENSE.txt +0 -0
  29. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/README.md +0 -0
  30. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/Makefile +0 -0
  31. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/_static/.gitignore +0 -0
  32. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/contributing.rst +0 -0
  33. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/index.md +0 -0
  34. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/license.rst +0 -0
  35. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/readme.md +0 -0
  36. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/docs/requirements.txt +0 -0
  37. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/pyproject.toml +0 -0
  38. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/setup.cfg +0 -0
  39. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/setup.py +0 -0
  40. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pyBiocFileCache.egg-info/dependency_links.txt +0 -0
  41. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pyBiocFileCache.egg-info/not-zip-safe +0 -0
  42. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pyBiocFileCache.egg-info/requires.txt +0 -0
  43. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pyBiocFileCache.egg-info/top_level.txt +0 -0
  44. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/src/pybiocfilecache/_exceptions.py +0 -0
  45. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/tests/data/test1.txt +0 -0
  46. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/tests/data/test2.txt +0 -0
  47. {pybiocfilecache-0.3.1 → pybiocfilecache-0.4.1}/tox.ini +0 -0
@@ -5,9 +5,9 @@ name: Test the library
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [ main ]
8
+ branches: [ master ]
9
9
  pull_request:
10
- branches: [ main ]
10
+ branches: [ master ]
11
11
 
12
12
  jobs:
13
13
  build:
@@ -17,26 +17,27 @@ repos:
17
17
  - id: mixed-line-ending
18
18
  args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
19
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
20
+ # - repo: https://github.com/PyCQA/docformatter
21
+ # rev: master
22
+ # hooks:
23
+ # - id: docformatter
24
+ # additional_dependencies: [tomli]
25
+ # args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
26
+ # # --config, ./pyproject.toml
27
27
 
28
- - repo: https://github.com/psf/black
29
- rev: 24.4.0
30
- hooks:
31
- - id: black
32
- language_version: python3
28
+ # - repo: https://github.com/psf/black
29
+ # rev: 24.8.0
30
+ # hooks:
31
+ # - id: black
32
+ # language_version: python3
33
33
 
34
34
  - repo: https://github.com/astral-sh/ruff-pre-commit
35
35
  # Ruff version.
36
- rev: v0.3.7
36
+ rev: v0.6.8
37
37
  hooks:
38
38
  - id: ruff
39
39
  args: [--fix, --exit-non-zero-on-fix]
40
+ - id: ruff-format
40
41
 
41
42
  ## If like to embrace black styles even in the docs:
42
43
  # - repo: https://github.com/asottile/blacken-docs
@@ -2,3 +2,4 @@
2
2
 
3
3
  * Jayaram Kancherla <jayaram.kancherla@gmail.com>
4
4
  * Max Hargreaves <max_hargreaves@outlook.com>
5
+ * Oleksandr Khoroshevskyi <khorosh@virginia.edu>
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## Version 0.4 (development)
4
+
5
+ - Migrate the schema to match R/Bioconductor's BiocFileCache (Check out [this issue](https://github.com/BiocPy/pyBiocFileCache/issues/11)). Thanks to [@khoroshevskyi ](https://github.com/khoroshevskyi) for the PR.
6
+
7
+ ## Version 0.1
8
+
9
+ - Initial release of the package, Setting up all the actions.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyBiocFileCache
3
- Version: 0.3.1
3
+ Version: 0.4.1
4
4
  Summary: File based cache for resources and metadata
5
5
  Home-page: https://github.com/epiviz/pyBiocFileCache
6
6
  Author: jkanche
@@ -2,3 +2,4 @@
2
2
 
3
3
  * Jayaram Kancherla <jayaram.kancherla@gmail.com>
4
4
  * Max Hargreaves <max_hargreaves@outlook.com>
5
+ * Oleksandr Khoroshevskyi <khorosh@virginia.edu>
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## Version 0.4 (development)
4
+
5
+ - Migrate the schema to match R/Bioconductor's BiocFileCache (Check out [this issue](https://github.com/BiocPy/pyBiocFileCache/issues/11)). Thanks to [@khoroshevskyi ](https://github.com/khoroshevskyi) for the PR.
6
+
7
+ ## Version 0.1
8
+
9
+ - Initial release of the package, Setting up all the actions.
@@ -179,10 +179,7 @@ html_theme = "furo"
179
179
  # Theme options are theme-specific and customize the look and feel of a theme
180
180
  # further. For a list of options available for each theme, see the
181
181
  # documentation.
182
- html_theme_options = {
183
- "sidebar_width": "300px",
184
- "page_width": "1200px"
185
- }
182
+ html_theme_options = {"sidebar_width": "300px", "page_width": "1200px"}
186
183
 
187
184
  # Add any paths that contain custom themes here, relative to this directory.
188
185
  # html_theme_path = []
@@ -266,9 +263,7 @@ latex_elements = {
266
263
 
267
264
  # Grouping the document tree into LaTeX files. List of tuples
268
265
  # (source start file, target name, title, author, documentclass [howto/manual]).
269
- latex_documents = [
270
- ("index", "user_guide.tex", "pyBiocFileCache Documentation", "jkanche", "manual")
271
- ]
266
+ latex_documents = [("index", "user_guide.tex", "pyBiocFileCache Documentation", "jkanche", "manual")]
272
267
 
273
268
  # The name of an image file (relative to this directory) to place at the top of
274
269
  # the title page.
@@ -304,4 +299,4 @@ intersphinx_mapping = {
304
299
  "pyscaffold": ("https://pyscaffold.org/en/stable", None),
305
300
  }
306
301
 
307
- print(f"loading configurations for {project} {version} ...", file=sys.stderr)
302
+ print(f"loading configurations for {project} {version} ...", file=sys.stderr)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyBiocFileCache
3
- Version: 0.3.1
3
+ Version: 0.4.1
4
4
  Summary: File based cache for resources and metadata
5
5
  Home-page: https://github.com/epiviz/pyBiocFileCache
6
6
  Author: jkanche
@@ -32,10 +32,10 @@ src/pyBiocFileCache.egg-info/top_level.txt
32
32
  src/pybiocfilecache/BiocFileCache.py
33
33
  src/pybiocfilecache/__init__.py
34
34
  src/pybiocfilecache/_exceptions.py
35
+ src/pybiocfilecache/const.py
35
36
  src/pybiocfilecache/utils.py
36
- src/pybiocfilecache/db/Base.py
37
37
  src/pybiocfilecache/db/__init__.py
38
- src/pybiocfilecache/db/schema.py
38
+ src/pybiocfilecache/db/db_config.py
39
39
  tests/conftest.py
40
40
  tests/test_cache.py
41
41
  tests/data/test1.txt
@@ -9,8 +9,7 @@ from sqlalchemy import func
9
9
  from sqlalchemy.orm import Session
10
10
 
11
11
  from ._exceptions import NoFpathError, RnameExistsError, RpathTimeoutError
12
- from .db import create_schema
13
- from .db.schema import Resource
12
+ from .db.db_config import create_schema, Resource
14
13
  from .utils import copy_or_move, create_tmp_dir, generate_id
15
14
 
16
15
  __author__ = "Jayaram Kancherla"
@@ -96,11 +95,7 @@ class BiocFileCache:
96
95
  raise NoFpathError(f"Resource at '{fpath}' does not exist.")
97
96
 
98
97
  rid = generate_id()
99
- rpath = (
100
- f"{self.cache}/{rid}" + (f".{fpath.suffix}" if ext else "")
101
- if action != "asis"
102
- else str(fpath)
103
- )
98
+ rpath = f"{self.cache}/{rid}" + (f".{fpath.suffix}" if ext else "") if action != "asis" else str(fpath)
104
99
 
105
100
  # create new record in the database
106
101
  res = Resource(
@@ -152,11 +147,7 @@ class BiocFileCache:
152
147
  List of matching resources from cache.
153
148
  """
154
149
  with self.sessionLocal() as session:
155
- return (
156
- session.query(Resource)
157
- .filter(Resource[field].ilike("%{}%".format(query)))
158
- .all()
159
- )
150
+ return session.query(Resource).filter(Resource[field].ilike("%{}%".format(query))).all()
160
151
 
161
152
  def _get(self, session: Session, rname: str) -> Optional[Resource]:
162
153
  """Get a resource with `rname` from given `Session`.
@@ -171,9 +162,7 @@ class BiocFileCache:
171
162
  Returns:
172
163
  The `Resource` for the `rname` if available.
173
164
  """
174
- resource: Optional[Resource] = (
175
- session.query(Resource).filter(Resource.rname == rname).first()
176
- )
165
+ resource: Optional[Resource] = session.query(Resource).filter(Resource.rname == rname).first()
177
166
 
178
167
  if resource is not None:
179
168
  # `Resource` may exist but `rpath` could still be being
@@ -183,8 +172,7 @@ class BiocFileCache:
183
172
  while not Path(str(resource.rpath)).exists():
184
173
  if time() - start >= timeout:
185
174
  raise RpathTimeoutError(
186
- f"For resource: '{rname}' the rpath does not exist "
187
- f"after {timeout} seconds."
175
+ f"For resource: '{rname}' the rpath does not exist " f"after {timeout} seconds."
188
176
  )
189
177
  sleep(0.1)
190
178
 
@@ -275,3 +263,12 @@ class BiocFileCache:
275
263
  # but lets just add it to the cache.
276
264
  res = self.add(rname=rname, fpath=fpath, action=action)
277
265
  return res
266
+
267
+ def list_all(self) -> List[Resource]:
268
+ """List all resources currently in the cache.
269
+
270
+ Returns:
271
+ List of all Resource objects in the cache.
272
+ """
273
+ with self.sessionLocal() as session:
274
+ return session.query(Resource).all()
@@ -17,8 +17,8 @@ finally:
17
17
 
18
18
  from .BiocFileCache import BiocFileCache as BiocFileCache
19
19
 
20
- from .db.schema import Metadata as Metadata
21
- from .db.schema import Resource as Resource
20
+ from .db.db_config import Metadata as Metadata
21
+ from .db.db_config import Resource as Resource
22
22
 
23
23
  from ._exceptions import NoFpathError as NoFpathError
24
24
  from ._exceptions import RnameExistsError as RnameExistsError
@@ -0,0 +1 @@
1
+ SCHEMA_VERSION = "0.99.4"
@@ -2,4 +2,4 @@ __author__ = "jkanche"
2
2
  __copyright__ = "jkanche"
3
3
  __license__ = "MIT"
4
4
 
5
- from .Base import create_schema
5
+ from .db_config import create_schema
@@ -0,0 +1,82 @@
1
+ from typing import Tuple
2
+
3
+ from sqlalchemy import create_engine, select, Column, Integer, Text, DateTime, func
4
+ from sqlalchemy.engine import Engine
5
+ from sqlalchemy.orm.session import Session
6
+
7
+ from sqlalchemy.orm import declarative_base, sessionmaker
8
+
9
+ from ..const import SCHEMA_VERSION
10
+
11
+ __author__ = "jkanche"
12
+ __copyright__ = "jkanche"
13
+ __license__ = "MIT"
14
+
15
+ Base = declarative_base()
16
+
17
+
18
+ class Metadata(Base):
19
+ __tablename__ = "metadata"
20
+ key = Column(Text(), primary_key=True, index=True)
21
+ value = Column(Text())
22
+
23
+ def __repr__(self):
24
+ return "<Metadata(key='%s', valye='%s')>" % (self.key, self.value)
25
+
26
+
27
+ class Resource(Base):
28
+ __tablename__ = "resource"
29
+ id = Column(Integer, primary_key=True, index=True, autoincrement=True)
30
+ rid = Column(Text())
31
+ rname = Column(Text())
32
+ create_time = Column(DateTime, server_default=func.now())
33
+ access_time = Column(DateTime, server_default=func.now())
34
+ rpath = Column(Text())
35
+ rtype = Column(Text())
36
+ fpath = Column(Text())
37
+ last_modified_time = Column(DateTime, onupdate=func.now())
38
+ etag = Column(Text())
39
+ expires = Column(DateTime)
40
+
41
+ def __repr__(self):
42
+ return "<Resource(id='%s', rname='%s')>" % (self.id, self.rname)
43
+
44
+
45
+ def add_metadata(key: str, value: str, engine: Engine) -> None:
46
+ """Add metadata to the database.
47
+
48
+ Args:
49
+ key:
50
+ Key of the metadata.
51
+ value:
52
+ Value of the metadata.
53
+ engine:
54
+ Engine
55
+ """
56
+ with Session(engine) as session:
57
+ if session.scalar(select(Metadata).where(Metadata.key == key)):
58
+ pass
59
+ else:
60
+ new_metadata = Metadata(key=key, value=value)
61
+ session.add(new_metadata)
62
+ session.commit()
63
+
64
+
65
+ def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
66
+ """Create the schema in the sqlite database.
67
+
68
+ Args:
69
+ cache_dir:
70
+ Location where the cache directory.
71
+
72
+ Returns:
73
+ A tuple of sqlalchemy engine and session maker.
74
+ """
75
+ engine = create_engine(f"sqlite:///{cache_dir}", connect_args={"check_same_thread": False})
76
+
77
+ Base.metadata.create_all(bind=engine, checkfirst=True)
78
+ sessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
79
+
80
+ add_metadata("schema_version", SCHEMA_VERSION, engine)
81
+
82
+ return (engine, sessionLocal)
@@ -60,9 +60,7 @@ def copy_or_move(
60
60
  """
61
61
 
62
62
  if action not in ["copy", "move", "asis"]:
63
- raise ValueError(
64
- f"Action must be either 'move', 'copy' or 'asis', provided {action}."
65
- )
63
+ raise ValueError(f"Action must be either 'move', 'copy' or 'asis', provided {action}.")
66
64
 
67
65
  try:
68
66
  if action == "copy":
@@ -84,6 +82,4 @@ def setup_logging(loglevel):
84
82
  loglevel (int): minimum loglevel for emitting messages
85
83
  """
86
84
  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
- )
85
+ logging.basicConfig(level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S")
@@ -1,6 +1,5 @@
1
- """Dummy conftest.py for pybiocfilecache.
1
+ """Dummy conftest.py for pybiocfilecache. If you don't know what this is for, just leave it empty.
2
2
 
3
- If you don't know what this is for, just leave it empty.
4
3
  Read more about conftest.py under:
5
4
  - https://docs.pytest.org/en/stable/fixture.html
6
5
  - https://docs.pytest.org/en/stable/writing_plugins.html
@@ -41,6 +41,9 @@ def test_add_get_operations():
41
41
  frec3 = open(rec3.rpath, "r").read().strip()
42
42
  assert frec3 == "test2"
43
43
 
44
+ rtrip = bfc.list_all()
45
+ assert len(rtrip) == 3
46
+
44
47
  bfc.purge()
45
48
 
46
49
 
@@ -1,5 +0,0 @@
1
- # Changelog
2
-
3
- ## Version 0.1 (development)
4
-
5
- - Initial release
@@ -1,5 +0,0 @@
1
- # Changelog
2
-
3
- ## Version 0.1 (development)
4
-
5
- - Initial release
@@ -1,36 +0,0 @@
1
- from typing import Tuple
2
-
3
- from sqlalchemy import create_engine
4
- from sqlalchemy.engine import Engine
5
-
6
- # from sqlalchemy.ext.declarative import declarative_base
7
- from sqlalchemy.orm import declarative_base, sessionmaker
8
-
9
- __author__ = "jkanche"
10
- __copyright__ = "jkanche"
11
- __license__ = "MIT"
12
-
13
- Base = declarative_base()
14
-
15
-
16
- def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
17
- """Create the schema in the sqlite database.
18
-
19
- Args:
20
- cache_dir:
21
- Location where the cache directory.
22
-
23
- Returns:
24
- A tuple of sqlalchemy engine and session maker.
25
- """
26
- try:
27
- engine = create_engine(
28
- f"sqlite:///{cache_dir}", connect_args={"check_same_thread": False}
29
- )
30
-
31
- Base.metadata.create_all(bind=engine, checkfirst=True)
32
- sessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
33
-
34
- return (engine, sessionLocal)
35
- except Exception as e:
36
- raise e
@@ -1,35 +0,0 @@
1
- from sqlalchemy import Column, DateTime, Integer, String
2
- from sqlalchemy.sql import func
3
-
4
- from .Base import Base
5
-
6
- __author__ = "jkanche"
7
- __copyright__ = "jkanche"
8
- __license__ = "MIT"
9
-
10
-
11
- class Metadata(Base):
12
- __tablename__ = "metadata"
13
- key = Column(String(), primary_key=True, index=True)
14
- value = Column(String())
15
-
16
- def __repr__(self):
17
- return "<Metadata(key='%s', valye='%s')>" % (self.key, self.value)
18
-
19
-
20
- class Resource(Base):
21
- __tablename__ = "resource"
22
- id = Column(Integer, primary_key=True, index=True, autoincrement=True)
23
- rid = Column(String())
24
- rname = Column(String())
25
- create_time = Column(DateTime, server_default=func.now())
26
- access_time = Column(DateTime, server_default=func.now())
27
- rpath = Column(String())
28
- rtype = Column(String())
29
- fpath = Column(String())
30
- last_modified_time = Column(DateTime, onupdate=func.now())
31
- etag = Column(String())
32
- expires = Column(DateTime)
33
-
34
- def __repr__(self):
35
- return "<Resource(id='%s', rname='%s')>" % (self.id, self.rname)
File without changes