Skip to content

VERSION file not included in distribution #248

Closed
@jmahlik

Description

@jmahlik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions