Skip to content

Commit

Permalink
fix(deps): use optional dependencies correctly (for docs too)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Apr 12, 2024
1 parent e0a0219 commit 9f92f65
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 53 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Install documentation dependencies
run: |
pip install -r docs/requirements.txt
pip install -e .[docs]
- name: Setup doc deploy
run: |
git config user.name 'github-actions[bot]'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/matrix-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
pip install -e .[test,api]
- name: Run tests
run: python run_tests.py dev
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e .[test]
pip install gunicorn
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
exclude: \.svg$
- repo: local
# Using local repos because these won't work for me from remote repo -EJ
# They're also more convenient because we install them via requirements.dev.txt
# They're also more convenient because we install them via optional deps
# and they are then available on the command line as well as in pre-commit.
hooks:
- id: isort
Expand Down
55 changes: 48 additions & 7 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ Please consider using the `dev` environment with `hatch` to do
development, which enables some checking of Git commits and messages:

```sh
hatch run dev:setup
hatch -e dev shell
```

If you have a pre-existing virtual environment (sandbox), you can also
install the required packages with `pip`:

```sh
pip install -e .[dev]
pre-commit install
gitlint install-hook
```

## Pre-commit hooks

The g2p team has agreed to systematically use a number of pre-commit hooks to
Expand Down Expand Up @@ -52,14 +60,30 @@ 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 added all the developper dependencies for the project to the
`dev` environment to make them easy to install with `hatch`:
We've added all the developer dependencies for the project to the
`dev` environment to make them easy to install with `hatch`. In
addition, `pre-commit` and `gitlint` hooks will be installed on
creation of this environment. Note that you will have to use the
`dev` environment when committing since pre-commit is installed there.
You can either start a shell:

```sh
hatch -e dev run pre-commit install
hatch -e dev shell
```

Note that you have to run the second command in every g2p sandbox you create.
Or run commands in the environment:

```sh
hatch -e dev run git commit -m 'chore: foo bar baz'
```

If you have a pre-existing virtual environment (sandbox), you can also
install the required packages with `pip`:

```sh
pip install -e .[dev]
pre-commit install
```

## commitlint

Expand Down Expand Up @@ -113,10 +137,27 @@ These rules are inspired by these commit formatting guides:
We run commitlint on each commit message that you write by enabling the commit-msg hook in
Git.

Run this command in your g2p sandbox to install and enable the commit-msg hook:
The commit-msg hook is enabled on creation of the `dev` environment
with `hatch`. Note that you will have to use the `dev` environment
when committing since pre-commit is installed there. You can either
start a shell:

```sh
hatch -e dev shell
```

Or run commands in the environment:

```sh
hatch -e dev run git commit -m 'chore: foo bar baz'
```

If you have a pre-existing virtual environment (sandbox), you can also
install the required packages with `pip`:

```sh
hatch -e dev run gitlint install-hook
pip install -e .[dev]
gitlint install-hook
```

- Now, next time you make a change and commit it, your commit log will be checked:
Expand Down
5 changes: 0 additions & 5 deletions docs/requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions g2p/tests/test_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Test suite for the g2p-studio web app.
Requirements: python 3.8 and requirements/requirements.test.txt
Requirements: python 3.8 and `test` dependencies
Before running this test suite, launch the g2p-studio server:
minimal dev mode:
Expand All @@ -27,7 +27,7 @@
# flake8: noqa: C901
from unittest import IsolatedAsyncioTestCase, main

from playwright.async_api import async_playwright
from playwright.async_api import async_playwright # type: ignore

from g2p.app import APP, SOCKETIO
from g2p.log import LOGGER
Expand Down
86 changes: 55 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,56 @@ classifiers = [
dependencies = [
"click>=8.0.4",
"coloredlogs>=15.0.1",
"networkx>=2.6",
"openpyxl",
"panphon>=0.19",
"pydantic>=2.3",
"pyyaml>=5.2",
"regex",
"text_unidecode",
"tqdm",
]

[project.optional-dependencies]
api = [
"eventlet>=0.33.0,!=0.36.0",
"flask-cors>=3.0.9",
"flask-restful>=0.3.9",
"flask-talisman>=0.7.0",
"flask<2.3; python_version < '3.8'",
"flask; python_version >= '3.8'",
"flask_socketio>=5.0.0",
"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",
]
test = [
"g2p[api]",
"coverage[toml]>=6.5",
"playwright>=1.26.1",
"jsonschema>=4.17.3",
"pep440>=0.1.2",
]
dev = [
"g2p[test]",
"black>=23; python_version < '3.8'",
"black>24.2; python_version >= '3.8'",
"flake8>=4.0.1",
"gitlint-core==0.17.0",
"isort>=5.10.1",
"mypy>=1; python_version < '3.8'",
"mypy>=1.8.0; python_version >= '3.8'",
"pre-commit>=2.6.0",
]
prod = [
"g2p[api]",
"gunicorn>=21.1.0",
]
docs = [
"mkdocs>=1.5.2",
"mkdocs-click>=0.8.0",
"mkdocs-material>=9.2.5",
"mkdocstrings[python]>=0.22.0",
"mike>=1.1.2",
]

[project.scripts]
Expand Down Expand Up @@ -84,32 +117,24 @@ requires = [
"hatch-pip-compile"
]

[tool.hatch.envs.api]
features = [ "api" ]

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

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

[tool.hatch.envs.dev]
dependencies = [
"black>=23; python_version < '3.8'",
"black>24.2; python_version >= '3.8'",
"flake8>=4.0.1",
"gitlint-core==0.17.0",
"isort>=5.10.1",
"mypy>=1; python_version < '3.8'",
"mypy>=1.8.0; python_version >= '3.8'",
"pre-commit>=2.6.0",
features = [ "dev" ]
post-install-commands = [
"pre-commit install",
"gitlint install-hook || true",
]

[tool.hatch.envs.dev.scripts]
Expand All @@ -122,15 +147,14 @@ cov = [
"test-cov",
"cov-report",
]
setup = [
"pre-commit install",
"gitlint install-hook",
]

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

[tool.hatch.envs.prod.scripts]
serve = "gunicorn --worker-class eventlet -w 1 g2p.app:APP --no-sendfile"

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

Expand Down
4 changes: 3 additions & 1 deletion readme-heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ Our production Heroku deployment is controlled by the following files:
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
hatch env remove prod
rm -f requirements.txt
hatch env create prod
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
# 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
Expand All @@ -21,6 +20,7 @@
# - regex
# - text-unidecode
# - tqdm
# - gunicorn>=21.1.0
#

aniso8601==9.0.1
Expand Down

0 comments on commit 9f92f65

Please sign in to comment.