Skip to content

Commit

Permalink
Clean up the exporter and use uvicorn instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarwick committed Jun 1, 2024
1 parent 6091501 commit bf25ffa
Show file tree
Hide file tree
Showing 18 changed files with 1,847 additions and 609 deletions.
32 changes: 32 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[flake8]
# it's not a bug that we aren't using all of hacking,
# ignore H101,H238,H301,H306
ignore = E226,E302,E41,H101,H238,H301,H306
max-line-length = 120
exclude =
.git,
__pycache__,
old,
build,
dist,
migrations,
*.pyc,
*.pyo,
*.pyd,
*.egg,
*.egg-info,
.cache,
.eggs,
.tox,
.venv,
_build,
buck-out,
venv,
*.mo,
*.so,
*.com,
*.class,
*.dll,
*.exe
max-complexity = 10
select = B,C,E,F,W,T4,B9
154 changes: 152 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,156 @@
/files/
mkpass.bat
*.iml
/venv/
/.secret
__pycache__

# 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
.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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# VS Code
.vscode/

# JetBrains IDEs
.idea/

# Other files and directories
*.log
*.sqlite3
*.bat
*.iml
/target/
/out/
/bin/
/files/
/.secret
26 changes: 13 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Use the official Python image from the Docker Hub
FROM python:3.11-slim

# Set the working directory in the container to /app
# Set the working directory in the container
WORKDIR /app

# Add the current directory contents into the container at /app
ADD . /app
# Copy the distribution file into the container
COPY dist/*.whl /app/

# Install any needed packages specified in requirements.txt
RUN pip install -q --no-cache-dir -r requirements.txt
# Install the distribution file using pip
RUN pip install --no-cache-dir /app/*.whl

# Make port 80 available to the world outside this container
EXPOSE 9992
# Copy the rest of the application code into the container
COPY . .

# Define environment variable
ENV NAME FastAPIApp
# Expose port 9992 to the outside world
EXPOSE 9992

# Run main.py when the container launches
CMD ["hypercorn", "asgi:app", "--bind", "0.0.0.0:9992"]
# Command to run the FastAPI application using Uvicorn
CMD ["uvicorn", "asgi:app", "--host", "0.0.0.0", "--port", "9992"]
5 changes: 5 additions & 0 deletions asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
""" ASGI entrypoint for Lutron QS Exporter."""
from lutron_qs_exporter import app

__all__ = ["app"]

2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"port": 23,
"username": "default",
"password": "default",
"log_level": "INFO"
"log_level": "DEBUG"
}
3 changes: 2 additions & 1 deletion develop.ps1
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
hypercorn asgi:app --reload
$env:LOG_LEVEL = "WARN"
uvicorn --reload asgi:app
13 changes: 11 additions & 2 deletions docker-build.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Define image and container name
$ImageName = "lutron_qs_exporter"

# Delete 'dist' folder if it exists
if (Test-Path -Path .\dist -PathType Container) {
Remove-Item -Path .\dist -Recurse -Force
}

# Run poetry build
Write-Output "Running poetry build..."
poetry build
Write-Output "Poetry build completed."

Write-Output "Building Docker image: $ImageName"

# Build the Docker image
docker build -t $ImageName .

Write-Output "Image $ImageName built successfully."

Write-Output "Image $ImageName built successfully."
Loading

0 comments on commit bf25ffa

Please sign in to comment.