Skip to content

Conversation

@stuartcampbell
Copy link
Collaborator

@stuartcampbell stuartcampbell commented May 30, 2025

The method I was using for dynamic versioning didn't seem to be working reliably. This PR changes the method to use a different package for version determination.

This also fixed an issue with the CLI where just running the command with no command and a flag would return an error (i.e. the --version would always fail)

To Test

If you checkout the branch, cd into it and then type uv run nsls2api --version should return the version.

Also, if you stand up the server, then the /v1/about endpoint should also return the version.

@stuartcampbell stuartcampbell self-assigned this May 30, 2025
@stuartcampbell stuartcampbell requested review from Copilot and vshekar May 30, 2025 14:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the version determination mechanism for the NSLS-II API, replacing the previous dynamic versioning via nsls2api._version with importlib.metadata and new dynamic versioning packages. The changes include:

  • Replacing nsls2api._version with importlib.metadata for version retrieval in both CLI and API endpoints.
  • Adjusting the Typer CLI configuration to support version printing without subcommands.
  • Updating dependency and configuration settings in requirements.in and pyproject.toml to use uv-dynamic-versioning.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

File Description
src/nsls2api/cli/cli.py Updated CLI version retrieval and Typer CLI configuration.
src/nsls2api/api/v1/stats_api.py Updated API version retrieval logic and logging.
requirements.in Added uv-dynamic-versioning dependency.
pyproject.toml Updated project dynamic versioning settings and build backend.

@stuartcampbell stuartcampbell requested a review from Copilot May 30, 2025 17:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issues with dynamic versioning by switching the method of version determination to use the uv-dynamic-versioning package, and it addresses the CLI's handling of the --version flag.

  • Updates version retrieval across the codebase
  • Removes legacy import of nsls2api._version
  • Adjusts CLI configuration to enable the version option without a subcommand

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/nsls2api/version.py Implements a new get_version function using importlib.metadata
src/nsls2api/cli/cli.py Updates CLI initialization and version retrieval logic
src/nsls2api/api/v1/stats_api.py Switches to use get_version and logs API version
requirements.in Adds uv-dynamic-versioning dependency
pyproject.toml Configures uv-dynamic-versioning as the new version source

Copy link
Collaborator

@padraic-shafer padraic-shafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI command works as advertised.

$ uv run nsls2api --version
NSLS-II API CLI version: 0.2.2.dev663+a330bb4

I raised a couple questions in the comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the previous dynamic versioning approach with the uv-dynamic-versioning package and updates both the CLI and API to use a centralized get_version function.

  • Introduce get_version() in version.py using importlib.metadata
  • Update CLI (cli.py) to invoke version flag without subcommands and use get_version
  • Update API (stats_api.py) /about endpoint to log and return version via get_version
  • Add uv-dynamic-versioning to dependencies and configure it in pyproject.toml

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/nsls2api/version.py Added get_version() function for package version retrieval
src/nsls2api/cli/cli.py Switched CLI to use get_version, enabled --version without subcommands
src/nsls2api/api/v1/stats_api.py Updated /about endpoint to use get_version, removed old import
requirements.in Added uv-dynamic-versioning to requirements
pyproject.toml Configured uv-dynamic-versioning in build system, removed hatch-vcs
Comments suppressed due to low confidence (1)

src/nsls2api/version.py:4

  • Consider adding unit tests for 'get_version' to verify correct version retrieval when the package is installed and that it falls back to 'unknown' on PackageNotFoundError.
def get_version() -> str:

padraic-shafer and others added 2 commits June 2, 2025 09:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@padraic-shafer padraic-shafer merged commit 53bba5d into NSLS2:main Jun 2, 2025
4 checks passed
@stuartcampbell stuartcampbell deleted the fix-versioning branch June 2, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants