diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8cbdca97..7e90d990 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,13 +1,15 @@ FROM eligibility_server:latest -# install python tooling -COPY .devcontainer/requirements.txt .devcontainer/requirements.txt -RUN pip install --no-cache-dir -r .devcontainer/requirements.txt +# install devcontainer requirements +RUN pip install -e .[dev,test] -# install docs tooling +# docs requirements are in a separate file for the GitHub Action COPY docs/requirements.txt docs/requirements.txt RUN pip install --no-cache-dir -r docs/requirements.txt -# install test tooling -COPY tests/requirements.txt tests/requirements.txt -RUN pip install -r tests/requirements.txt +# install pre-commit environments in throwaway Git repository +# https://stackoverflow.com/a/68758943 +COPY .pre-commit-config.yaml . +RUN git init . && \ + pre-commit install-hooks && \ + rm -rf .git diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e6ce0513..cb5b195b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,24 +8,27 @@ "postStartCommand": ["/bin/bash", "bin/init.sh"], "postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"], - // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.defaultProfile.linux": "bash", - "terminal.integrated.profiles.linux": { - "bash": { - "path": "/bin/bash" - } + "customizations": { + // Set *default* container specific settings.json values on container create. + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + } + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "bpruitt-goddard.mermaid-markdown-syntax-highlighting", + "eamodio.gitlens", + "esbenp.prettier-vscode", + "hashicorp.terraform", + "mhutchie.git-graph", + "ms-python.python", + "ms-python.vscode-pylance" + ] } - }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "bpruitt-goddard.mermaid-markdown-syntax-highlighting", - "eamodio.gitlens", - "esbenp.prettier-vscode", - "hashicorp.terraform", - "mhutchie.git-graph", - "ms-python.python", - "ms-python.vscode-pylance" - ] + } } diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt deleted file mode 100644 index 0164b67a..00000000 --- a/.devcontainer/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -black -flake8 -pre-commit diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1bfaee9a..563c6a33 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,7 +6,7 @@ version: 2 updates: - package-ecosystem: "pip" - directory: "/" # requirements.txt + directory: "/" # pyproject.toml schedule: interval: "daily" commit-message: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 311bf2a8..be47c86d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,8 +17,7 @@ jobs: - name: Install package and dependencies run: | python -m pip install --upgrade pip - pip install -r tests/requirements.txt - pip install -r requirements.txt + pip install -e .[test] - name: Load environment variables uses: cardinalby/export-env-action@v2 diff --git a/.vscode/settings.json b/.vscode/settings.json index a8b8d514..57f4dcd9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,18 +9,20 @@ "[python]": { "editor.defaultFormatter": "ms-python.python" }, - "python.defaultInterpreterPath": "/usr/local/bin/python", "python.formatting.provider": "black", "python.languageServer": "Pylance", - "python.linting.flake8Enabled": true, "python.linting.enabled": true, + "python.linting.flake8Enabled": true, "python.testing.pytestArgs": ["tests"], - "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false, "[terraform]": { "editor.defaultFormatter": "hashicorp.terraform" }, "[terraform-vars]": { "editor.defaultFormatter": "hashicorp.terraform" + }, + "workbench.editorAssociations": { + "*.db": "sqlite-viewer.option" } } diff --git a/Dockerfile b/Dockerfile index 5c9ada29..feb3b0ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,13 @@ FROM ghcr.io/cal-itp/docker-python-web:main ENV FLASK_APP=eligibility_server/app.py -# install python app dependencies -COPY requirements.txt requirements.txt -RUN pip install --no-cache-dir -r requirements.txt +# upgrade pip +RUN python -m pip install --upgrade pip # copy source files -COPY bin/ bin/ +COPY bin bin COPY eligibility_server/ eligibility_server/ -COPY *.py . -COPY README.md . +COPY pyproject.toml pyproject.toml # install source as a package RUN pip install -e . diff --git a/data/server.csv b/data/server.csv index cfc85ca0..3ef76d78 100644 --- a/data/server.csv +++ b/data/server.csv @@ -1,3 +1,4 @@ +sub,name,type 71162,Box,courtesy_card 32587,Gonzales,courtesy_card 03552,McCulley,courtesy_card diff --git a/eligibility_server/__init__.py b/eligibility_server/__init__.py index e69de29b..db848db4 100644 --- a/eligibility_server/__init__.py +++ b/eligibility_server/__init__.py @@ -0,0 +1,3 @@ +__version__ = "2023.08.1" + +VERSION = __version__ diff --git a/eligibility_server/db/setup.py b/eligibility_server/db/setup.py index 84a1eaac..5441fa75 100644 --- a/eligibility_server/db/setup.py +++ b/eligibility_server/db/setup.py @@ -94,17 +94,18 @@ def import_csv_users(csv_path, remote): # open in read mode explicitly since the file may still be open if we downloaded from remote # newline="" is important here, see https://docs.python.org/3/library/csv.html#id3 with open(csv_path, mode="r", encoding="utf-8", newline="") as file: - data = csv.reader( + data = csv.DictReader( file, delimiter=config.csv_delimiter, quoting=config.csv_quoting, quotechar=config.csv_quotechar, ) - # unpack each record in data to the 3 columns - for sub, name, types in data: + + for row in data: # type lists are expected to be a comma-separated value and quoted if the CSV delimiter is a comma - types = [type.replace(config.csv_quotechar, "") for type in types.split(",") if type] - save_user(sub, name, types) + types = row["type"] + types = [types.replace(config.csv_quotechar, "") for type in types.split(",") if type] + save_user(row["sub"], row["name"], types) # close and remove the temp file if needed if temp_csv: diff --git a/pyproject.toml b/pyproject.toml index 8548c2bc..cd6c8e3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,46 @@ -# Configuration for Black. +[build-system] +requires = ["setuptools>=64", "wheel"] +build-backend = "setuptools.build_meta" -# NOTE: you have to use single-quoted strings in TOML for regular expressions. -# It's the equivalent of r-strings in Python. Multiline strings are treated as -# verbose regular expressions by Black. Use [ ] to denote a significant space -# character. +[project] +classifiers = ["Programming Language :: Python :: 3 :: Only"] +description = "Server implementation of the Eligibility Verification API" +dependencies = [ + "eligibility-api==2023.6.1", + "Flask==2.3.2", + "Flask-RESTful==0.3.10", + "Flask-SQLAlchemy==3.0.5", + "requests==2.31.0" +] +dynamic = ["version"] +keywords = ["flask"] +license = { file = "LICENSE" } +name = "eligibility-server" +readme = "README.md" +requires-python = ">=3.9" +[project.optional-dependencies] +dev = [ + "black", + "flake8", + "pre-commit", +] +test = [ + "coverage", + "pytest", + "pytest-mock", +] + +[project.urls] +Code = "https://github.com/cal-itp/eligibility-server" +Documentation = "https://docs.calitp.org/eligibility-server" +Issues = "https://github.com/cal-itp/eligibility-server/issues" + +# Configuration for black [tool.black] line-length = 127 target-version = ['py310'] include = '\.pyi?$' + +[tool.setuptools] +packages = ["eligibility_server"] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 73edb3dd..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -eligibility-api==2023.6.1 -Flask==2.3.2 -Flask-RESTful==0.3.10 -Flask-SQLAlchemy==3.0.5 -requests==2.31.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 8b5a1f22..00000000 --- a/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -from setuptools import find_packages, setup - - -with open("requirements.txt") as f: - requirements = f.read().strip().split("\n") - install_requires = [r for r in requirements if not r.startswith("git+")] - dependency_links = list(set(requirements) - set(install_requires)) - -with open("README.md") as f: - long_description = f.read() - - -CLASSIFIERS = [ - "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", -] - -setup( - name="eligibility-server", - version="2023.06.1", - description="Server implementation of the Eligibility Verification API", - long_description=long_description, - long_description_content_type="text/markdown", - python_requires=">=3.7", - classifiers=CLASSIFIERS, - project_urls={ - "Source": "https://github.com/cal-itp/eligibility-server", - "Tracker": "https://github.com/cal-itp/eligibility-server/issues", - }, - packages=find_packages(), - include_package_data=True, - install_requires=install_requires, - dependency_links=dependency_links, - license="AGPL-3.0", -) diff --git a/terraform/uptime.tf b/terraform/uptime.tf index 7a0d2176..df8f5190 100644 --- a/terraform/uptime.tf +++ b/terraform/uptime.tf @@ -6,7 +6,7 @@ module "healthcheck" { application_insights = azurerm_application_insights.main # not strictly necessary to include the environment name, but helps to make the alerts more clear name = "mst-courtesy-cards-eligibility-server-${local.env_name}-healthcheck" - url = "https://${azurerm_linux_web_app.main.default_hostname}/healthcheck" + url = "https://${azurerm_cdn_frontdoor_endpoint.main.host_name}/healthcheck" } # ignore when app restarts as data is being reloaded diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 8be74ac0..00000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -coverage -pytest -pytest-mock