-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporarily disable CORS
- Loading branch information
Showing
31 changed files
with
500 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,52 @@ | ||
# This file is referenced from local.python.container-service-convention. | ||
# It acts as the default Dockerfile for Python-based containers, i.e., those created by build.gradle | ||
# that use the local.python.container-service-convention plugin. | ||
# This file overrides the default Dockerfile in the plugin. | ||
ARG BASE_IMAGE="python:3.10-slim" | ||
# hadolint ignore=DL3006 | ||
FROM ${BASE_IMAGE} | ||
|
||
# hadolint ignore=DL3018,DL3008 | ||
RUN apt-get update && apt-get install --no-install-recommends -y \ | ||
build-essential \ | ||
curl \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# hadolint ignore=DL3013,DL3042 | ||
RUN pip install --upgrade pip | ||
|
||
WORKDIR /app | ||
|
||
# Used to specify the service folder you want to build if running locally | ||
# No longer write *.pyc files to disk | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
# Send logs directly to container | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# Copy and install requirements first (without application code) | ||
# b/c this is a big image layer that doesn't change often | ||
# See https://vsupalov.com/5-tips-to-speed-up-docker-build/ | ||
COPY requirements.txt ./ | ||
# Install python packages using a long timeout so that builds won't fail when pypi.org is slow4 | ||
RUN pip install --default-timeout=100 --no-cache-dir -r requirements.txt | ||
|
||
# https://stackoverflow.com/a/46801962 | ||
# Copy script that runs docker-entrypoint.sh if it exists | ||
COPY set-env-secrets.src entrypoint-wrapper.sh docker-entry*.sh ./ | ||
|
||
# Copy application code, which changes more often, | ||
# along with files specified in local.python.container-service-convention | ||
COPY . ./ | ||
RUN pip install --no-cache-dir . | ||
|
||
RUN adduser --disabled-password tron && \ | ||
chmod +x ./*.sh && chown -R tron /app | ||
USER tron | ||
ENTRYPOINT ["/app/entrypoint-wrapper.sh"] | ||
|
||
ARG HEALTHCHECK_PORT_ARG | ||
ENV HEALTHCHECK_PORT=${HEALTHCHECK_PORT_ARG} | ||
ARG HEALTHCHECK_CMD_ARG="curl --fail http://localhost:${HEALTHCHECK_PORT}/health || exit 1" | ||
ENV HEALTHCHECK_CMD=${HEALTHCHECK_CMD_ARG} | ||
HEALTHCHECK CMD eval $HEALTHCHECK_CMD |
This file contains 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,8 @@ | ||
# streamlit | ||
|
||
## Points of Contact | ||
|
||
## Getting Started | ||
Set up your environment and gather dependencies by following the directions laid out in [Getting Started](getting_started.md). | ||
|
||
## Project Specific Information |
This file contains 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,58 @@ | ||
plugins { | ||
id 'local.python.app-conventions' | ||
id 'local.python.container-service-conventions' | ||
} | ||
|
||
tasks.register('mypy', PythonTask) { | ||
module = 'mypy' | ||
command = 'src' | ||
dependsOn 'requirements' | ||
} | ||
|
||
tasks.register('isort', PythonTask) { | ||
module = 'isort' | ||
command = '.' | ||
dependsOn 'mypy' | ||
} | ||
|
||
tasks.register('ruff', PythonTask) { | ||
module = 'ruff' | ||
command = 'check' | ||
dependsOn 'isort' | ||
} | ||
|
||
tasks.register('appinstall', PythonTask) { | ||
module = 'pip' | ||
command = 'install -e .' | ||
dependsOn 'ruff' | ||
} | ||
|
||
// Override the pytest task in local.python.app-conventions to remove dependency on pyflake8 | ||
tasks.getByPath('pytest').configure { | ||
dependsOn.clear() | ||
dependsOn 'appinstall' | ||
} | ||
|
||
// Runs pytest integration tests when './gradlew integration-test' is run | ||
tasks.register('integrationPytest', PythonTask) { | ||
dependsOn 'appinstall' | ||
module = 'pytest' | ||
command = './integration' | ||
} | ||
|
||
tasks.register('integrationTest', Test) { | ||
dependsOn 'integrationPytest' | ||
group = 'verification' | ||
} | ||
|
||
// Runs pytest end-to-end tests when './gradlew integration-test' is run | ||
tasks.register('endToEndPytest', PythonTask) { | ||
dependsOn 'appinstall' | ||
module = 'pytest' | ||
command = './end_to_end' | ||
} | ||
|
||
tasks.register('endToEndTest', Test) { | ||
dependsOn 'endToEndPytest' | ||
group = 'verification' | ||
} |
This file contains 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,4 @@ | ||
#!/bin/sh | ||
cd app || exit | ||
|
||
python -m streamlit run main.py |
Empty file.
This file contains 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 @@ | ||
"""Pytest configuration. This file is automatically loaded by pytest before any test.""" |
This file contains 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,6 @@ | ||
from streamlit.testing.v1 import AppTest | ||
|
||
def test_main() -> None: | ||
app = AppTest.from_file('src/app/main.py') | ||
app.run() | ||
assert not app.exception |
This file contains 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,54 @@ | ||
# Getting started | ||
|
||
### Install Python3.10 | ||
If you're on a Mac, you can use pyenv to handle multiple python versions | ||
|
||
``` | ||
brew install pyenv | ||
pyenv install python3.10 | ||
``` | ||
|
||
Set the global python so all further commands use installed version, or don't do this if you want a different version available globally for your system. | ||
``` | ||
pyenv global python3.10 | ||
``` | ||
|
||
### Create a virtual env: | ||
``` | ||
python -m venv ~/.virtualenvs/your-virtual-env # or wherever you want | ||
source ~/.virtualenvs/your-virtual-env/bin/activate | ||
``` | ||
Other tools such as [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv#installing-with-homebrew-for-macos-users) can be used to create and activate multiple virtual environments. | ||
|
||
Make sure your python path is set up to pull from your virtualenv: | ||
``` | ||
which python3 | ||
# /Users/<your_username>/.virtualenvs/your-virtual-env/bin/python | ||
``` | ||
|
||
### Install dependencies | ||
From your project folder, install dependencies. | ||
``` | ||
pip install -r src/dev-requirements.txt | ||
pip install -r src/requirements.txt | ||
pip install -e . | ||
``` | ||
|
||
## Unit, Integration, & End-to-End Tests | ||
|
||
Make sure your virtual env is activated. | ||
|
||
Navigate to the project folder and run the tests: | ||
|
||
* Via pytest directly | ||
``` | ||
pytest . | ||
pytest ./integration | ||
pytest ./end_to_end | ||
``` | ||
* Via gradle | ||
``` | ||
./gradlew check | ||
./gradlew integrationTest | ||
./gradlew endToEndTest | ||
``` |
This file contains 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 @@ | ||
build_from_src=true |
Empty file.
This file contains 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 @@ | ||
"""Pytest configuration. This file is automatically loaded by pytest before any test.""" |
This file contains 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,6 @@ | ||
from streamlit.testing.v1 import AppTest | ||
|
||
def test_main() -> None: | ||
app = AppTest.from_file('src/app/main.py') | ||
app.run() | ||
assert not app.exception |
This file contains 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,54 @@ | ||
# pyproject.toml | ||
[project] | ||
name = 'app' | ||
version = '0.1' | ||
requires-python = '>=3.10' | ||
|
||
[tool.setuptools.package-data] | ||
app = [".streamlit/*", "static/*"] | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
|
||
# Additional Options | ||
# Comment line below, and uncomment the line below that to be able to debug pytests | ||
addopts = "-ra --import-mode=importlib --cov=./src --cov-fail-under=80 --no-cov-on-fail --cov-report=term:skip-covered --cov-report=html:build/reports/coverage --cov-branch" | ||
# addopts = "-ra --no-cov" | ||
|
||
# Path to tests run by the command pytest. Tests in the folders `end_to_end` and `integration` typically require other applications to be running and are excluded | ||
testpaths = [ | ||
"test" | ||
] | ||
|
||
# Environment variables to use in pytests | ||
env = [ | ||
"ENV=test-environment", | ||
"DEBUG=True" | ||
] | ||
|
||
[tool.coverage.run] | ||
# The following files are for development purposes and are not part of the coverage report | ||
omit = [] | ||
|
||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.ruff] | ||
line-length = 160 | ||
|
||
[tool.ruff.lint] | ||
# Ruff enables Flake8's F rules, along with a subset of the E rules, omitting any stylistic rules that overlap with the use of Ruff formatter | ||
extend-select = [ | ||
# Add the `line-too-long` rule to the enforced rule set. | ||
"E501" | ||
] | ||
|
||
[tool.ruff.format] | ||
quote-style = "single" | ||
# Use `\n` line endings for all files | ||
line-ending = "lf" | ||
|
||
[tool.mypy] | ||
python_version = "3.10" | ||
strict = true | ||
ignore_missing_imports = true |
Oops, something went wrong.