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

VERSION file not included in distribution #248

Open
jmahlik opened this issue Feb 24, 2025 · 0 comments · May be fixed by #249
Open

VERSION file not included in distribution #248

jmahlik opened this issue Feb 24, 2025 · 0 comments · May be fixed by #249
Labels
bug Something isn't working

Comments

@jmahlik
Copy link

jmahlik commented Feb 24, 2025

Describe the bug
Trying to access the _version attribute fails since the VERSION file isn't included in the package.

I found this when coming up with a workaround for #244 since I was using runpy to run the files and ensure they are importable.

To reproduce
A clear, step-by-step set of instructions to reproduce the bug.
The provided code need to be complete and runnable, if additional data is needed, please include them in the issue.

$ python -c 'import sagemaker_core._version'
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│\venv\Lib\site-pack │
│ ages\sagemaker_core\_version.py:10 in <module>                                                   │
│                                                                                                  │
│    7                                                                                             │
│    8 version_file_path = os.path.join(root_dir, "VERSION")                                       │
│    9                                                                                             │
│ ❱ 10 with open(version_file_path) as version_file:                                               │
│   11 │   __version__ = version_file.read().strip()                                               │
│   12                                                                                             │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
FileNotFoundError: [Errno 2] No such file or directory:
\\venv\\Lib\\VERSION'

Expected behavior
The VERSION file should be included with the distribution.

Simplest solution would be to make it dynamic and fetch the version with importlib.metadata at runtime. I'll submit a PR for this.

pyproject.toml: Setuptools will make sure this file is included with no extra config needed.

[tool.setuptools.dynamic]
version = {file = ["VERSION"]}

_version.py

from importlib import metadata
__version__ = metadata.version("sagemaker_core")

Another alternative would be using package_data. This is not as clean though.

pyproject.toml

[tool.setuptools.package-data]
sagemaker_core = ["VERSION"]

And the version could be gotten by using importlib.resources.files: https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files

import importlib.resources

__version__ = importlib.resources.files("sagemaker_core.VERSION").read_text().strip()

Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.

Bug information
A description of your system. Please provide:

  • SageMaker Core version: master
  • Python version: 3.11-3.13
  • Is the issue with autogen code or with generate code ?: no

Additional context
Add any other context about the problem here.

@jmahlik jmahlik added the bug Something isn't working label Feb 24, 2025
jmahlik added a commit to StateFarmIns/sagemaker-core that referenced this issue Feb 24, 2025

Verified

This commit was signed with the committer’s verified signature.
jmahlik Justin
The __version__ can now be accessed at runtime.

Tested with the following. We can see the version being copied by build.
It also shows up in the sdist.

```bash
python -m pip install build
python -m build
tar -xzf ./dist/sagemaker_core-1.0.24.tar.gz
ls -l sagemaker_core-1.0.24
total 31
-rw-r--r-- 1 RM13 1049089 11558 Feb 12 16:54 LICENSE
-rw-r--r-- 1 RM13 1049089    15 Feb 12 16:54 MANIFEST.in
-rw-r--r-- 1 RM13 1049089  4945 Feb 24 13:57 PKG-INFO
-rw-r--r-- 1 RM13 1049089  1441 Feb 24 13:54 pyproject.toml
-rw-r--r-- 1 RM13 1049089  3647 Feb 12 16:54 README.rst
-rw-r--r-- 1 RM13 1049089   133 Feb 24 13:57 setup.cfg
drwxr-xr-x 1 RM13 1049089     0 Feb 24 13:57 src/
-rw-r--r-- 1 RM13 1049089     6 Feb 24 13:53 VERSION
```

Closes aws#248
@jmahlik jmahlik linked a pull request Feb 24, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant