Skip to content
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Exclude the project virtual environment from image builds
.venv
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN uv pip install wheel gssapi
RUN uv pip install -r /code/requirements.txt

COPY . .
RUN uv build
RUN uv pip install '.'

CMD ["uvicorn", "nsls2api.main:app", "--proxy-headers", \
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ vcs = "git"
style = "pep440"
bump = true

[tool.hatch.build.hooks.version]
path = "src/nsls2api/_version.py"
template = '''
version = "{version}"
'''

[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
Expand Down
3 changes: 3 additions & 0 deletions src/nsls2api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .version import get_version

__app_name__ = "nsls2api"
__version__ = get_version()
5 changes: 5 additions & 0 deletions src/nsls2api/infrastructure/app_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

from nsls2api.infrastructure import mongodb_setup
from nsls2api.infrastructure.config import get_settings
from nsls2api.infrastructure.logging import logger
from nsls2api.services import background_service
from nsls2api.services.helpers import httpx_client_wrapper
from nsls2api.version import get_version

settings = get_settings()

Expand All @@ -15,6 +17,9 @@

@asynccontextmanager
async def app_lifespan(app: FastAPI):
# Log the version of the nsls2api package
logger.info(f"NSLS-II API Version: {get_version()}")

# Initialize the MongoDB connection
await mongodb_setup.init_connection(settings.mongodb_dsn)

Expand Down
12 changes: 9 additions & 3 deletions src/nsls2api/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

def get_version() -> str:
"""Get the version of the nsls2api package"""

try:
return importlib.metadata.version("nsls2api")
except importlib.metadata.PackageNotFoundError:
return "unknown"
from nsls2api._version import version

return version
except ImportError:
try:
return importlib.metadata.version("nsls2api")
except importlib.metadata.PackageNotFoundError:
return "0.0.0" # Fallback version if the package is not found