Skip to content

Commit

Permalink
Fake pkg_resources to fix bagit-python in py3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Dec 13, 2023
1 parent 836e49e commit 8b7a7c5
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12.0
3.12.1
20 changes: 19 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ See the fragment files in the `changelog.d directory`_.

.. scriv-insert-here
.. _changelog-0.7.4:
.. _changelog-0.7.5:

0.7.5 — 2023-12-13
==================

Changed
-------

- Use Python 3.12.1.
- Update dependencies.

Fixed
-----

- Fake ``pkg_resources`` to enable the use of bagit-python in Python 3.12.

0.7.4 — 2023-12-12
==================
Expand All @@ -30,6 +44,10 @@ Changed
- Use ``platformdirs`` instead of ``appdirs`` to determine the user data
directory.
- Update dependencies.

Fixed
-----

- Update the Submit RPC handler to use the default processing configuration when
the user-provided ``config`` field is unset.

Expand Down
2 changes: 1 addition & 1 deletion a3m/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.7.4"
__version__ = "0.7.5"

__all__ = ["__version__"]
28 changes: 28 additions & 0 deletions a3m/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
from importlib.metadata import version


def shim_pkg_resources():
"""Injects a pkg_resources fake needed by bagit-python in Python 3.12.
The underlying error is only reproducible if setuptools is not installed.
"""

class Distribution:
def __init__(self, name):
self.version = version(name)

class FakeDistributionNotFound(Exception):
pass

def fake_get_distribution(_, name):
return Distribution(name)

class PkgResources:
DistributionNotFound = FakeDistributionNotFound
get_distribution = fake_get_distribution

sys.modules["pkg_resources"] = PkgResources() # type: ignore


shim_pkg_resources()
1 change: 0 additions & 1 deletion a3m/server/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def _prepare_config(self, provided=None):
if provided is not None:
for config_field in config.DESCRIPTOR.fields:
field_name = config_field.name
print("setattr", field_name, getattr(provided, field_name))
setattr(config, field_name, getattr(provided, field_name))

return config
Expand Down
24 changes: 12 additions & 12 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ attrs==23.1.0
# jsonschema
# referencing
# scriv
babel==2.13.1
babel==2.14.0
# via sphinx
bagit==1.8.1
# via a3m (pyproject.toml)
bandit==1.7.5
bandit==1.7.6
# via a3m (pyproject.toml)
boto3==1.33.9
boto3==1.33.13
# via a3m (pyproject.toml)
botocore==1.33.9
botocore==1.33.13
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -59,7 +59,7 @@ coverage[toml]==7.3.2
# pytest-cov
cryptography==41.0.7
# via secretstorage
distlib==0.3.7
distlib==0.3.8
# via virtualenv
django==4.2.8
# via
Expand All @@ -85,21 +85,21 @@ gitdb==4.0.11
# via gitpython
gitpython==3.1.40
# via bandit
googleapis-common-protos==1.61.0
googleapis-common-protos==1.62.0
# via
# a3m (pyproject.toml)
# grpcio-status
grpcio==1.59.3
grpcio==1.60.0
# via
# a3m (pyproject.toml)
# grpcio-reflection
# grpcio-status
# grpcio-tools
grpcio-reflection==1.59.3
grpcio-reflection==1.60.0
# via a3m (pyproject.toml)
grpcio-status==1.59.3
grpcio-status==1.60.0
# via a3m (pyproject.toml)
grpcio-tools==1.59.3
grpcio-tools==1.60.0
# via a3m (pyproject.toml)
identify==2.5.33
# via pre-commit
Expand Down Expand Up @@ -178,7 +178,7 @@ pluggy==1.3.0
# via
# pytest
# tox
pre-commit==3.5.0
pre-commit==3.6.0
# via a3m (pyproject.toml)
prometheus-client==0.19.0
# via a3m (pyproject.toml)
Expand Down Expand Up @@ -313,7 +313,7 @@ types-psycopg2==2.9.21.20
# via django-types
types-requests==2.31.0.10
# via a3m (pyproject.toml)
typing-extensions==4.8.0
typing-extensions==4.9.0
# via
# django-stubs-ext
# mypy
Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ attrs==23.1.0
# referencing
bagit==1.8.1
# via a3m (pyproject.toml)
boto3==1.33.9
boto3==1.33.13
# via a3m (pyproject.toml)
botocore==1.33.9
botocore==1.33.13
# via
# boto3
# s3transfer
Expand All @@ -32,18 +32,18 @@ django==4.2.8
# django-stubs-ext
django-stubs-ext==4.2.7
# via a3m (pyproject.toml)
googleapis-common-protos==1.61.0
googleapis-common-protos==1.62.0
# via
# a3m (pyproject.toml)
# grpcio-status
grpcio==1.59.3
grpcio==1.60.0
# via
# a3m (pyproject.toml)
# grpcio-reflection
# grpcio-status
grpcio-reflection==1.59.3
grpcio-reflection==1.60.0
# via a3m (pyproject.toml)
grpcio-status==1.59.3
grpcio-status==1.60.0
# via a3m (pyproject.toml)
idna==3.6
# via requests
Expand Down Expand Up @@ -101,7 +101,7 @@ sqlparse==0.4.4
# via django
tenacity==8.2.3
# via a3m (pyproject.toml)
typing-extensions==4.8.0
typing-extensions==4.9.0
# via django-stubs-ext
unidecode==1.3.7
# via a3m (pyproject.toml)
Expand Down

0 comments on commit 8b7a7c5

Please sign in to comment.