Skip to content

Commit

Permalink
Add packaging config, freeze deps in requirements.
Browse files Browse the repository at this point in the history
- This makes installation with pip possible.
- Docker builds do use the requirements.txt file to make the builds
  reproducible.
- freeze.py is used update the requirements.txt when the unpinned
  dependencies in the pyproject.toml change.
  • Loading branch information
Varbin committed Feb 4, 2024
1 parent a9b41b9 commit 640daf7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
39 changes: 39 additions & 0 deletions freeze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Pin the dependencies given in pyproject.toml.
"""

from venv import EnvBuilder
from shutil import rmtree
from subprocess import check_call
from tomllib import load
from os import mkdir, path, remove

BUILD = "build"
REQUIREMENTS = "build/requirements.txt"
VENV = "build/.venv"

try:
try:
mkdir(BUILD, mode=0o750)
except FileExistsError:
pass
try:
mkdir(VENV, mode=0o750)
except FileExistsError:
pass

EnvBuilder().create(VENV)
with open("pyproject.toml", "rb") as project:
pyproject = load(project)
with open(REQUIREMENTS, "w") as requirements:
requirements.write("\n".join(pyproject["project"]["dependencies"]))
check_call([VENV + "/bin/python", "-m", "ensurepip"])
check_call([VENV + "/bin/pip3", "install", "-r", REQUIREMENTS])
with open("requirements.txt", "w") as requirements:
check_call([VENV + "/bin/pip3", "freeze", "-r", REQUIREMENTS],
stdout=requirements)
finally:
if path.isdir(VENV):
rmtree(VENV)
if path.exists(REQUIREMENTS):
remove(REQUIREMENTS)
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[build-system]
requires = ["setuptools >= 61.0", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "devicepasswords"
authors = [
{name = "Varbin the Fox"}
]
description = "Simple device password management to replace regular password for systems not capable of single sign-on. "
readme = "README.md"
requires-python = ">=3.11"
keywords = ["python", "docker", "flask", "oidc", "single-sign-on", "devicepassword"]
license = {text = "MPL-2.0"}
classifiers = [
"Development Status :: 4 - Beta",
"Framework :: Flask",
"Framework :: aiohttp",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
"Topic :: Security",
"Topic :: System :: Systems Administration :: Authentication/Directory",
]
dependencies = [
"flask >= 3.0.0",
"flask-sqlalchemy",
"flask-alembic",
"python-jose[cryptography]",
"requests",
"gevent>1.4",
"flask-session",
# Password hashing
"passlib",
"argon2-cffi",
# Database drivers
"psycopg2-binary",
"pymysql",
"pymssql",
# Server for production
"gunicorn",
]
dynamic = ["version"]

[tool.setuptools]
packages = ["devicepasswords"]
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Setup script for the devicepasswords application.
With modern packaging tools,
this file is not really required anymore.
"""

from setuptools import setup

setup()

0 comments on commit 640daf7

Please sign in to comment.