Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bhzheng1 committed Apr 17, 2024
1 parent 8cf962d commit df94fa8
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/testing-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python application test with Github Actions

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10.8
uses: actions/setup-python@v1
with:
python-version: 3.10.8
- name: Install dependencies
run: |
make install
- name: Lint with pylint
run: |
make lint
- name: Test with pytest
run: |
make test
- name: Format code
run: |
make format
155 changes: 155 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
62 changes: 62 additions & 0 deletions DashApp/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from dash import Dash, html, dcc
import dash_bootstrap_components as dbc
import plotly.express as px
from dash.dependencies import Input, Output
import pandas as pd

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")


def serve_layout():
return html.Div(children=[
html.H1(children='Hello Dash'),

html.Div(children='''
Dash: A web application framework for your data.
'''),
html.Div([dcc.Graph(id='example-graph',figure=fig)]),
html.Div(
children=[
html.P(children=[
"Last Updated: ",
html.Span(id='time',children=["hello"]),
]),
html.P("Please email the digitalization team with any errors that you find including a screenshot"),
dcc.Dropdown(
id='main-viewer',
options=[
{'label': 'Area-Adjusted', 'value': 'Area'},
{'label': 'APO', 'value': 'APO'}
],
value='Area'
),
]
),
])


external_stylesheets = [dbc.themes.BOOTSTRAP]
app = Dash(__name__, external_stylesheets=external_stylesheets,
suppress_callback_exceptions=True)
app.layout = serve_layout()


@app.callback([Output('time', 'children')],
Input('main-viewer', 'value'))
def update_time(view):
if view == 'APO':
return ["helloworld"]
else:
return ["heihei"]


if __name__ == '__main__':
app.run_server(debug=True)
21 changes: 21 additions & 0 deletions FastAPIApp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dockerfile

# pull the official docker image
FROM python:3.9.4-slim

# set work directory
WORKDIR /app

# set env variables
# PYTHONDONTWRITEBYTECODE: Prevents Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE 1

# PYTHONUNBUFFERED: Prevents Python from buffering stdout and stderr (equivalent to python -u option)
ENV PYTHONUNBUFFERED 1

# install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt

# copy project
COPY . .
Empty file added FastAPIApp/app/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions FastAPIApp/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import asyncio
import uvicorn
from fastapi import FastAPI

app = FastAPI(title="FastAPI, Docker")


@app.get("/")
async def root():
return {"message": "Hello World"}


async def main():
config = uvicorn.Config("app.main:app", port=5000, log_level="info")
server = uvicorn.Server(config)
await server.serve()

if __name__ == "__main__":
asyncio.run(main())
8 changes: 8 additions & 0 deletions FastAPIApp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.8"

services:
web:
build: .
command: python -m app.main
ports:
- 8080:5000
2 changes: 2 additions & 0 deletions FastAPIApp/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fastapi
uvicorn
Empty file added FastAPIApp/test.py
Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# python_test

0 comments on commit df94fa8

Please sign in to comment.