Skip to content

Commit

Permalink
feat(build): autogenerate requirements.txt with hatch-pip-compile
Browse files Browse the repository at this point in the history
also switch to using environments for test instead of requirements
  • Loading branch information
dhdaines committed Apr 12, 2024
1 parent 561817c commit e0a0219
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 78 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/matrix-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/requirements.test.txt
pip install -e .
pip install -e .[test]
- name: Run tests
run: python run_tests.py dev
7 changes: 2 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements/requirements.test.txt
pip install -e .
pip install -e .[test]
pip install pip-licenses
if pip-licenses | grep -v 'Artistic License' | grep -v LGPL | grep GNU; then echo 'Please avoid introducing *GPL dependencies'; false; fi
pip install coverage
Expand Down Expand Up @@ -97,8 +95,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/requirements.test.txt
pip install -e .
pip install -e .[test]
- name: Run tests on Windows
run: python run_tests.py dev
- name: Make sure the CLI outputs utf8 on Windows
Expand Down
19 changes: 8 additions & 11 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ them in.

## TL;DR

Please considering running these commands in each of your sandboxes to enable our
pre-commit hooks and commitlint:
Please consider using the `dev` environment with `hatch` to do
development, which enables some checking of Git commits and messages:

```sh
pip install -r requirements/requirements.dev.txt
pre-commit install
gitlint install-hook
hatch run dev:setup
hatch -e dev shell
```

## Pre-commit hooks
Expand Down Expand Up @@ -53,12 +52,11 @@ All the pre-commit hooks are executed using a tool called
[pre-commit](https://pre-commit.com/). Once you enable pre-commit, it will run all the
hooks each time you try to commit anything in this repo.

We've listed all the developper dependencies for the project in
[requirements/requirements.dev.txt](requirements/requirements.dev.txt) to make them easy to install:
We've added all the developper dependencies for the project to the
`dev` environment to make them easy to install with `hatch`:

```sh
pip install -r requirements/requirements.dev.txt
pre-commit install
hatch -e dev run pre-commit install
```

Note that you have to run the second command in every g2p sandbox you create.
Expand Down Expand Up @@ -118,8 +116,7 @@ Git.
Run this command in your g2p sandbox to install and enable the commit-msg hook:

```sh
pip install -r requirements/requirements.dev.txt
gitlint install-hook
hatch -e dev run gitlint install-hook
```

- Now, next time you make a change and commit it, your commit log will be checked:
Expand Down
46 changes: 33 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,29 @@ include = [
"/g2p",
]

[tool.hatch.envs.default]
[tool.hatch.env]
requires = [
"hatch-pip-compile"
]

[tool.hatch.envs.prod]
type = "pip-compile"
python = "3.10"
lock-filename = "requirements.txt"
dependencies = [
"gunicorn>=21.1.0",
]

[tool.hatch.envs.test]
dependencies = [
"coverage[toml]>=6.5",
"playwright>=1.26.1",
"jsonschema>=4.17.3",
"pep440>=0.1.2",
]

[tool.hatch.envs.dev]
dependencies = [
"black>=23; python_version < '3.8'",
"black>24.2; python_version >= '3.8'",
"flake8>=4.0.1",
Expand All @@ -95,13 +112,7 @@ dependencies = [
"pre-commit>=2.6.0",
]

[tool.hatch.envs.default.scripts]
serve = "flask --app g2p.app run"
routes = "flask --app g2p.app routes"
serve-cov = "coverage run -m flask --app g2p.app run"
test = "python run_tests.py dev"
test-cov = "coverage run run_tests.py dev"
test-studio = "python g2p/tests/test_studio.py"
[tool.hatch.envs.dev.scripts]
check = "mypy --install-types --non-interactive {args:g2p}"
cov-report = [
"- coverage combine",
Expand All @@ -111,15 +122,24 @@ cov = [
"test-cov",
"cov-report",
]

[tool.hatch.envs.prod]
dependencies = [
"gunicorn>=21.1.0",
setup = [
"pre-commit install",
"gitlint install-hook",
]

[[tool.hatch.envs.all.matrix]]
[tool.hatch.envs.default.scripts]
serve = "flask --app g2p.app run"
routes = "flask --app g2p.app routes"

[[tool.hatch.envs.test.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.test.scripts]
serve-cov = "coverage run -m flask --app g2p.app run"
test = "python run_tests.py dev"
test-cov = "coverage run run_tests.py dev"
test-studio = "python g2p/tests/test_studio.py"

[tool.coverage.run]
source_pkgs = ["g2p"]
branch = true
Expand Down
7 changes: 6 additions & 1 deletion readme-heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ Our production Heroku deployment is controlled by the following files:
- `runtime.txt`: tells Heroku which run-time engine to use (i.e., which version of Python);

Heroku detects Python by default, but `runtime.txt` lets us specify/bump the version as needed;
- `requirements.txt`: tells Heroku what our production dependencies are.
- `requirements.txt`: tells Heroku what our production dependencies
are. This is managed by `hatch` now. You will need to make sure
the Python version in the `[tool.hatch.envs.prod]` section matches
the one in `runtime.txt`. Now you can update the requirements with:

hatch env run --env prod -- true
136 changes: 132 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,132 @@
# Minimal requirements for all uses of g2p
-r requirements/requirements.txt
# Additional requirements for production deployment
-r requirements/requirements.prod.txt
#
# This file is autogenerated by hatch-pip-compile with Python 3.10
#
# - gunicorn>=21.1.0
# - click>=8.0.4
# - coloredlogs>=15.0.1
# - eventlet!=0.36.0,>=0.33.0
# - flask-cors>=3.0.9
# - flask-restful>=0.3.9
# - flask-socketio>=5.0.0
# - flask-talisman>=0.7.0
# - flask; python_version >= "3.8"
# - flask<2.3; python_version < "3.8"
# - networkx>=2.6
# - openpyxl
# - panphon>=0.19
# - pydantic>=2.3
# - python-engineio>=4.0.0
# - python-socketio>=5.0.0
# - pyyaml>=5.2
# - regex
# - text-unidecode
# - tqdm
#

aniso8601==9.0.1
# via flask-restful
annotated-types==0.6.0
# via pydantic
bidict==0.23.1
# via python-socketio
blinker==1.7.0
# via flask
click==8.1.7
# via
# hatch.envs.prod
# flask
coloredlogs==15.0.1
# via hatch.envs.prod
dnspython==2.6.1
# via eventlet
editdistance==0.8.1
# via panphon
et-xmlfile==1.1.0
# via openpyxl
eventlet==0.35.2
# via hatch.envs.prod
flask==3.0.2 ; python_version >= "3.8"
# via
# hatch.envs.prod
# flask-cors
# flask-restful
# flask-socketio
flask-cors==4.0.0
# via hatch.envs.prod
flask-restful==0.3.10
# via hatch.envs.prod
flask-socketio==5.3.6
# via hatch.envs.prod
flask-talisman==1.1.0
# via hatch.envs.prod
greenlet==3.0.3
# via eventlet
gunicorn==21.2.0
# via hatch.envs.prod
h11==0.14.0
# via wsproto
humanfriendly==10.0
# via coloredlogs
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
munkres==1.1.4
# via panphon
networkx==3.2.1
# via hatch.envs.prod
numpy==1.26.4
# via panphon
openpyxl==3.1.2
# via hatch.envs.prod
packaging==24.0
# via gunicorn
panphon==0.20.0
# via hatch.envs.prod
pydantic==2.6.4
# via hatch.envs.prod
pydantic-core==2.16.3
# via pydantic
python-engineio==4.9.0
# via
# hatch.envs.prod
# python-socketio
python-socketio==5.11.2
# via
# hatch.envs.prod
# flask-socketio
pytz==2024.1
# via flask-restful
pyyaml==6.0.1
# via
# hatch.envs.prod
# panphon
regex==2023.12.25
# via
# hatch.envs.prod
# panphon
simple-websocket==1.0.0
# via python-engineio
six==1.16.0
# via flask-restful
text-unidecode==1.3
# via hatch.envs.prod
tqdm==4.66.2
# via hatch.envs.prod
typing-extensions==4.10.0
# via
# pydantic
# pydantic-core
unicodecsv==0.14.1
# via panphon
werkzeug==3.0.1
# via flask
wsproto==1.2.0
# via simple-websocket

# The following packages are considered to be unsafe in a requirements file:
# setuptools
7 changes: 0 additions & 7 deletions requirements/readme.md

This file was deleted.

9 changes: 0 additions & 9 deletions requirements/requirements.dev.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements/requirements.prod.txt

This file was deleted.

3 changes: 0 additions & 3 deletions requirements/requirements.test.txt

This file was deleted.

22 changes: 0 additions & 22 deletions requirements/requirements.txt

This file was deleted.

0 comments on commit e0a0219

Please sign in to comment.