This repository was archived by the owner on Sep 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor: pems_streamlit
package
#184
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0342167
feat(pems_streamlit): pyproject file for metadata
thekaveman 6635de3
refactor(pems_streamlit): move Dockerfile and assets
thekaveman f3981af
refactor(pems_streamlit): move app, update paths
thekaveman d968b02
refactor(tests): rename pems_streamlit directory
thekaveman 02c05dc
refactor(devcontainer): add pems_streamlit dependency
thekaveman 470e03f
fix(ci): remove old requirements install
thekaveman ea1f400
chore(pems_streamlit): remove placeholder app content
thekaveman 3fcf831
fix(devcontainer): ensure packages install as editable
thekaveman 9be9a63
fix(ci): install packages for testing
thekaveman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
ARG PYTHON_VERSION=3.12 | ||
|
||
# multi-stage build | ||
# | ||
# stage 1: builds the package wheel from source | ||
# using the git metadata for version info | ||
FROM python:${PYTHON_VERSION} AS build_wheel | ||
WORKDIR /build | ||
|
||
# upgrade pip, install build dependencies | ||
RUN python -m pip install --upgrade pip build setuptools_scm | ||
|
||
# copy source files | ||
COPY . . | ||
RUN git config --global --add safe.directory /build | ||
|
||
# Move into directory to run the build | ||
WORKDIR /build/pems_streamlit | ||
|
||
# build package | ||
RUN python -m build | ||
|
||
# multi-stage build | ||
# | ||
# stage 2: installs the wheel in a fresh base container | ||
# using the pre-built package, and copying only needed source | ||
FROM python:${PYTHON_VERSION} AS app_container | ||
|
||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
USER=caltrans | ||
|
||
EXPOSE 8501 | ||
|
||
# create non-root $USER and home directory | ||
RUN useradd --create-home --shell /bin/bash $USER && \ | ||
python -m pip install --upgrade pip | ||
|
||
COPY LICENSE LICENSE | ||
|
||
# switch to non-root $USER | ||
USER $USER | ||
|
||
# update env for local pip installs | ||
# see https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUSERBASE | ||
# since all `pip install` commands are in the context of $USER | ||
# $PYTHONUSERBASE is the location used by default | ||
ENV PATH="$PATH:/$USER/.local/bin" \ | ||
PYTHONUSERBASE="/$USER/.local" \ | ||
PYTHONPATH="$PYTHONPATH:/$USER/app" | ||
|
||
WORKDIR /$USER/app | ||
|
||
COPY .streamlit .streamlit | ||
COPY pems_streamlit/container/entrypoint.sh entrypoint.sh | ||
COPY pems_streamlit/container/run.py run.py | ||
COPY --from=build_wheel /build/pems_streamlit/dist /wheels | ||
|
||
RUN pip install $(find /wheels -name pems_streamlit*.whl) | ||
|
||
ENTRYPOINT ["./entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import runpy | ||
|
||
# since we're installing pems_streamlit as a package now, the main.py file won't exist | ||
# in the running container, so we can't point `streamlit run` at it | ||
|
||
# instead, use runpy to run the pems_streamlit.main module directly. | ||
|
||
if __name__ == "__main__": | ||
runpy.run_module("pems_streamlit.main", run_name="__main__", alter_sys=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[project] | ||
name = "pems_streamlit" | ||
description = "The Streamlit application for PeMS data visualizations." | ||
dynamic = ["version"] | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"boto3==1.39.7", | ||
"django==5.2.3", | ||
"pandas==2.3.0", | ||
"streamlit==1.45.1", | ||
] | ||
|
||
[build-system] | ||
requires = ["setuptools>=75", "setuptools_scm>=8"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] | ||
include = ["pems_streamlit*"] | ||
namespaces = false | ||
|
||
[tool.setuptools.package-data] | ||
pems_streamlit = ["*.txt"] | ||
|
||
[tool.setuptools_scm] | ||
# Tell scm to look one directory up for the .git folder | ||
root = ".." |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
streamlit_app/main.py → pems_streamlit/src/pems_streamlit/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ def _convert_to_pages(apps: list[Path]) -> list[StreamlitPage]: | |
|
||
|
||
def _default_app_page() -> StreamlitPage: | ||
"""Creates a no-op default page.""" | ||
return st.Page(APP_DIR / "__init__.py", default=True, title="PeMS Streamlit apps") | ||
|
||
|
||
|
@@ -54,5 +55,6 @@ def discover_apps() -> list[StreamlitPage]: | |
default_app_page = _default_app_page() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we have to add back in _default_app_page(), creating the default app page, and inserting the default app page to have at least one page tagged as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I should have checked. Fixed and rebased. |
||
apps = _discover_apps() | ||
pages = _convert_to_pages(apps) | ||
# Streamlit needs at least one page marked as default | ||
pages.insert(0, default_app_page) | ||
return pages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't need a default app page anymore, we can remove _default_app_page(), creating the default app page, and inserting the default app page in this file.