Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scuba: Use importlib.metadata over pkg_resources #247

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Removed use of deprecated `pkg_resources` (#247)


## [2.12.0] - 2023-09-15
### Added
- Enable the use of relative paths in a volume hostpath (#227)
Expand Down
3 changes: 2 additions & 1 deletion VERSIONING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ versioning scheme. Consider a base version of `1.2.3`:
created via `python setup.py sdist`. In this case, the version comes from
the egg info generated by setuptools.

In any case, when Scuba is installed, the version comes from `pkg_resources`.
In any case, when Scuba is installed, the version comes from
`importlib.metadata`.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ classifiers = [
]
dependencies = [
"PyYAML",
# TODO(#242): Remove when Python 3.7 support is removed.
"importlib_metadata; python_version<'3.8'",
]
description = "Simplify use of Docker containers for building software"
keywords = ["docker"]
Expand All @@ -42,6 +44,8 @@ changelog = "https://github.com/JonathonReinhart/scuba/blob/main/CHANGELOG.md"
requires = [
"wheel",
"setuptools >= 42.0.0",
# TODO(#242): Remove when Python 3.7 support is removed.
"importlib_metadata; python_version<'3.8'",
]


Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ PyYAML
pytest
pytest-cov
types-PyYAML
types-pkg-resources
coverage
black~=23.0 # Must match .github/workflows/black.yml
-r docs/requirements.txt
16 changes: 7 additions & 9 deletions scuba/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,17 @@ def get_version() -> str:
if not git_archive_rev.startswith("$"):
return f"{BASE_VERSION}+g{git_archive_rev}"

# Package resource
# Otherwise, we're either installed (e.g. via pip), or running from
# an 'sdist' source distribution, and have a local PKG_INFO file.
import pkg_resources

try:
return pkg_resources.get_distribution(DIST_SPEC).version
except pkg_resources.DistributionNotFound:
pass
# TODO(#242): Remove backport when Python 3.7 support is removed.
if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata # backport

# This shouldn't be able to happen
sys.stderr.write("WARNING: Failed to determine version!\n")
return BASE_VERSION
# Can raise importlib.metadata.PackageNotFoundError
return importlib_metadata.version(DIST_SPEC)


__version__ = get_version()
Expand Down