From 36e4dcc162ce67c1602d7d14f0b4186450c103b4 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 22 Mar 2024 16:34:11 -0400 Subject: [PATCH 01/11] feat: switch to hatch and dynamic versioning --- .flake8 | 3 + .github/workflows/pythonpublish.yml | 35 ++++--- .github/workflows/tests.yml | 9 ++ .gitignore | 1 + README.md | 17 +++- docs/installation.md | 7 ++ g2p/_version.py | 1 - pyproject.toml | 142 ++++++++++++++++++++++++++++ setup.cfg | 18 ---- setup.py | 46 --------- 10 files changed, 194 insertions(+), 85 deletions(-) create mode 100644 .flake8 delete mode 100644 g2p/_version.py create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..9cf3b9e0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +extend-ignore = E203, E704 +max-line-length = 88 diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index ad34822b..4568856d 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -24,20 +24,22 @@ jobs: runs-on: ubuntu-latest needs: tests steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install build tool - run: pip install build - - name: Build a binary wheel and a source tarball - run: python -m build --sdist --wheel - - name: Store the distribution packages - uses: actions/upload-artifact@v4 - with: - name: python-package-distributions - path: dist/ + - uses: actions/checkout@v4 + with: + fetch-tags: true + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Install build tool + run: pip install build + - name: Build a binary wheel and a source tarball + run: python -m build --sdist --wheel + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ github-release: name: Make a signed GitHub release @@ -92,10 +94,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]' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 844c0abd..c71e22e7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,6 +4,13 @@ on: - push - workflow_call +# Since we don't checkout the full history, set a default version so +# certain tests (pep440, update_schema) will still function. NOTE: +# This **must** match the version of the JSON schema file in +# g2p/mappings/.schema!!! +env: + SETUPTOOLS_SCM_PRETEND_VERSION: "2.0" + jobs: test-all-on-linux: # This is our main test job, exercising everything and uploading to coverage @@ -81,6 +88,8 @@ jobs: if: ${{ !contains(github.event.head_commit.message, '#no-ci') }} steps: - uses: actions/checkout@v4 + with: + fetch-tags: true - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/.gitignore b/.gitignore index 470931ca..ef425ae8 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ docs/_build/ # mkdocs build site +g2p/_version.py diff --git a/README.md b/README.md index 277c7e34..9cced0a3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,19 @@ The initial version of this package was developed by [Patrick Littell](https://g The best thing to do is install with pip `pip install g2p`. This command will install the latest release published on [PyPI g2p releases](https://pypi.org/project/g2p/). -You can also clone the repo and pip install it locally: +You can also use [hatch](https://hatch.pypa.io/latest/) to set up an +isolated local development environment, which may be useful if you +wish to contribute new mappings: + +```sh +$ git clone https://github.com/roedoejet/g2p.git +$ cd g2p +$ hatch shell +``` + +You can also simply install an "editable" version with `pip` (but it +is recommended to do this in a [virtual +environment](https://docs.python.org/3/library/venv.html)): ```sh $ git clone https://github.com/roedoejet/g2p.git @@ -52,6 +64,7 @@ $ cd g2p $ pip install -e . ``` + ## Usage The easiest way to create a transducer is to use the `g2p.make_g2p` function. @@ -251,7 +264,7 @@ mappings: 4. Add a mapping file. Look at the other mappings for examples, or visit the [g2p studio](https://g2p-studio.herokuapp.com) to practise your mappings. Mappings are defined in either a CSV or json file. See [writing mapping files](#writing-mapping-files) for more info. -5. After installing your local version (`pip3 install -e .`), update with `g2p update` +5. Start a development shell with `hatch shell` (or install an editable version with `pip install -e .`) then update with `g2p update` 6. Add some tests in `g2p/testspublic/data/.psv`. Each line in the file will run a test with the following structure: `|||` 7. Run `python3 run_tests.py langs` to make sure your tests pass. 8. Make sure you have [checked all the boxes](https://github.com/roedoejet/g2p/blob/main/.github/pull_request_template.md) and make a [pull request]((https://github.com/roedoejet/g2p/pulls)! diff --git a/docs/installation.md b/docs/installation.md index 8ce65b6a..39653738 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -19,3 +19,10 @@ cd g2p pip install -e . ``` + +To install in an isolated environment (recommended for development) +you may use [hatch](https://hatch.pypa.io/latest/): + +``` +hatch shell +``` diff --git a/g2p/_version.py b/g2p/_version.py deleted file mode 100644 index 21014090..00000000 --- a/g2p/_version.py +++ /dev/null @@ -1 +0,0 @@ -VERSION = "2.0.0" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..c0e39ca1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,142 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "g2p" +dynamic = ["version"] +description = "Module for creating context-aware, rule-based G2P mappings that preserve indices" +readme = "README.md" +license = "MIT" +requires-python = ">= 3.7" +authors = [ + { name = "Aidan Pine", email = "hello@aidanpine.ca" }, +] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", +] +dependencies = [ + "click>=8.0.4", + "coloredlogs<=14.0", + "dnspython>=2.1.0,<=2.3.0", + "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", + "numpy>=1.20.2,<2", + "openpyxl", + "panphon>=0.19", + "pydantic>=2.3", + "python-engineio>=4.0.0", + "python-socketio>=5.0.0", + "pyyaml>=5.2", + "regex", + "requests", + "text_unidecode", + "tqdm", +] + +[project.scripts] +g2p = "g2p.cli:cli" + +[project.urls] +Homepage = "https://github.com/roedoejet/g2p" + +[tool.setuptools] +packages = ["g2p"] +include-package-data = true + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "g2p/_version.py" +template = """ +# file generated by setuptools_scm +# don't change, don't track in version control +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Tuple, Union + VERSION_TUPLE = Tuple[Union[int, str], ...] +else: + VERSION_TUPLE = object + +VERSION: str +version: str +__version__: str +__version_tuple__: VERSION_TUPLE +version_tuple: VERSION_TUPLE + +VERSION = __version__ = version = {version!r} +__version_tuple__ = version_tuple = {version_tuple!r} +""" + +[tool.hatch.build.targets.sdist] +include = [ + "/g2p", +] + +[tool.hatch.envs.default] +dependencies = [ + "coverage[toml]>=6.5", + "playwright>=1.26.1", + "jsonschema>=4.17.3", + "pep440>=0.1.2", + "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", +] + +[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" +check = "mypy --install-types --non-interactive {args:g2p}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] + +[tool.hatch.envs.prod] +dependencies = [ + "gunicorn>=21.1.0", +] + +[[tool.hatch.envs.all.matrix]] +python = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + +[tool.coverage.run] +source_pkgs = ["g2p"] +branch = true +parallel = true +omit = [ + "g2p/_version.py", + "g2p/tests", +] + +[tool.coverage.report] +precision = 2 + +[tool.mypy] +plugins = ["pydantic.mypy"] + +[tool.isort] +profile = "black" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c2a70350..00000000 --- a/setup.cfg +++ /dev/null @@ -1,18 +0,0 @@ -[isort] -known_first_party = readalongs -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -use_parentheses=True -line_length=88 -ensure_newline_before_comments=True - -[mypy] -ignore_missing_imports = True -plugins = pydantic.mypy - -[flake8] -ignore = E203, E302, E501, E999, W503 -max-line-length = 88 -max-complexity = 12 -select = B,C,E,F,W,B9 diff --git a/setup.py b/setup.py deleted file mode 100644 index 5ac549ad..00000000 --- a/setup.py +++ /dev/null @@ -1,46 +0,0 @@ -""" Setup for g2p -""" - -from os import path - -from setuptools import find_packages, setup - -# Ugly hack to read the current version number without importing g2p: -with open("g2p/_version.py", "r", encoding="utf8") as version_file: - namespace = {} # type: ignore - exec(version_file.read(), namespace) - VERSION = namespace["VERSION"] - -this_directory = path.abspath(path.dirname(__file__)) - -with open(path.join(this_directory, "README.md"), encoding="utf8") as f: - long_description = f.read() - -with open( - path.join(this_directory, "requirements", "requirements.txt"), encoding="utf8" -) as f: - REQS = f.read().splitlines() - -setup( - name="g2p", - python_requires=">=3.7", - version=VERSION, - author="Aidan Pine", - author_email="hello@aidanpine.ca", - license="MIT", - url="https://github.com/roedoejet/g2p", - description="Module for creating context-aware, rule-based G2P mappings that preserve indices", - long_description=long_description, - long_description_content_type="text/markdown", - platform=["any"], - packages=find_packages(), - include_package_data=True, - install_requires=REQS, - entry_points={"console_scripts": ["g2p = g2p.cli:cli"]}, - zip_safe=False, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], -) From 24ada71c178e79b8e57b2ce65575c8a07bc5867f Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 26 Mar 2024 11:48:50 -0400 Subject: [PATCH 02/11] chore(deps): remove dependencies that were never used directly --- .github/workflows/pythonpublish.yml | 2 -- pyproject.toml | 3 --- 2 files changed, 5 deletions(-) diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index 4568856d..ad3aa117 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -25,8 +25,6 @@ jobs: needs: tests steps: - uses: actions/checkout@v4 - with: - fetch-tags: true - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/pyproject.toml b/pyproject.toml index c0e39ca1..adad779d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,6 @@ classifiers = [ dependencies = [ "click>=8.0.4", "coloredlogs<=14.0", - "dnspython>=2.1.0,<=2.3.0", "eventlet>=0.33.0,!=0.36.0", "flask-cors>=3.0.9", "flask-restful>=0.3.9", @@ -29,7 +28,6 @@ dependencies = [ "flask; python_version >= '3.8'", "flask_socketio>=5.0.0", "networkx>=2.6", - "numpy>=1.20.2,<2", "openpyxl", "panphon>=0.19", "pydantic>=2.3", @@ -37,7 +35,6 @@ dependencies = [ "python-socketio>=5.0.0", "pyyaml>=5.2", "regex", - "requests", "text_unidecode", "tqdm", ] From 561817c6711707b17bdefdf0761f6f519d2c38c6 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 26 Mar 2024 12:09:31 -0400 Subject: [PATCH 03/11] fix(deps): specific anti-dependency on broken coloredlogs version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index adad779d..6ba9136a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ ] dependencies = [ "click>=8.0.4", - "coloredlogs<=14.0", + "coloredlogs>=15.0.1", "eventlet>=0.33.0,!=0.36.0", "flask-cors>=3.0.9", "flask-restful>=0.3.9", From e0a021962f36ee05685f2e07f7a022f5508a1c15 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 26 Mar 2024 12:48:48 -0400 Subject: [PATCH 04/11] feat(build): autogenerate requirements.txt with hatch-pip-compile also switch to using environments for test instead of requirements --- .github/workflows/matrix-tests.yml | 3 +- .github/workflows/tests.yml | 7 +- Contributing.md | 19 ++-- pyproject.toml | 46 +++++++--- readme-heroku.md | 7 +- requirements.txt | 136 ++++++++++++++++++++++++++++- requirements/readme.md | 7 -- requirements/requirements.dev.txt | 9 -- requirements/requirements.prod.txt | 1 - requirements/requirements.test.txt | 3 - requirements/requirements.txt | 22 ----- 11 files changed, 182 insertions(+), 78 deletions(-) delete mode 100644 requirements/readme.md delete mode 100644 requirements/requirements.dev.txt delete mode 100644 requirements/requirements.prod.txt delete mode 100644 requirements/requirements.test.txt delete mode 100644 requirements/requirements.txt diff --git a/.github/workflows/matrix-tests.yml b/.github/workflows/matrix-tests.yml index cf8b475b..0640b241 100644 --- a/.github/workflows/matrix-tests.yml +++ b/.github/workflows/matrix-tests.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c71e22e7..5366137a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 diff --git a/Contributing.md b/Contributing.md index 5fda71fd..76d57d41 100644 --- a/Contributing.md +++ b/Contributing.md @@ -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 @@ -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. @@ -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: diff --git a/pyproject.toml b/pyproject.toml index 6ba9136a..f7dea12d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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", @@ -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 diff --git a/readme-heroku.md b/readme-heroku.md index 314784ae..d39dedfb 100644 --- a/readme-heroku.md +++ b/readme-heroku.md @@ -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 diff --git a/requirements.txt b/requirements.txt index 952b4b34..57288a56 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/requirements/readme.md b/requirements/readme.md deleted file mode 100644 index 239883f4..00000000 --- a/requirements/readme.md +++ /dev/null @@ -1,7 +0,0 @@ -All requirements for normal use are in `requirements.txt`. - -We use a specific version of gunicorn to run the g2p studio in production, and don't want to introduce git as a dependency, so we separate these requirements here into `requirements.prod.txt`. - -Requirements recommended for use during development but not needed for running g2p are separated into `requirements.dev.txt`. - -Requirements needed for running tests are in `requirements.test.txt`. diff --git a/requirements/requirements.dev.txt b/requirements/requirements.dev.txt deleted file mode 100644 index 544708ed..00000000 --- a/requirements/requirements.dev.txt +++ /dev/null @@ -1,9 +0,0 @@ -black~=24.3; python_version >= "3.8" -flake8>=4.0.1 -gitlint-core==0.17.0 -isort>=5.10.1 -mypy>=1.4.1 -mypy>=1.8.0; python_version >= "3.8" -pre-commit>=2.6.0 -types-PyYAML --r requirements.test.txt diff --git a/requirements/requirements.prod.txt b/requirements/requirements.prod.txt deleted file mode 100644 index 9f21dec9..00000000 --- a/requirements/requirements.prod.txt +++ /dev/null @@ -1 +0,0 @@ -gunicorn>=21.1.0 diff --git a/requirements/requirements.test.txt b/requirements/requirements.test.txt deleted file mode 100644 index eae11b39..00000000 --- a/requirements/requirements.test.txt +++ /dev/null @@ -1,3 +0,0 @@ -playwright>=1.26.1 -jsonschema>=4.17.3 -pep440>=0.1.2 diff --git a/requirements/requirements.txt b/requirements/requirements.txt deleted file mode 100644 index 0915cd11..00000000 --- a/requirements/requirements.txt +++ /dev/null @@ -1,22 +0,0 @@ -openpyxl -click>=8.0.4 -coloredlogs>=15.0.1 -dnspython>=2.1.0,<=2.3.0 -eventlet>=0.33.0,!=0.36.0 -flask-cors>=3.0.9 -flask-talisman>=0.7.0 -flask-restful>=0.3.9 -networkx>=2.6 -numpy>=1.20.2,<2 -panphon>=0.19 -pyyaml>=5.2 -regex -requests -tqdm -text_unidecode - -Flask==2.2.5 -flask_socketio>=5.0.0 -python-engineio>=4.0.0 -python-socketio>=5.0.0 -pydantic>=2.3 From 9f92f65dd16dc91eb3bd8e442e55415bd8fe2ad1 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 26 Mar 2024 13:04:43 -0400 Subject: [PATCH 05/11] fix(deps): use optional dependencies correctly (for docs too) --- .github/workflows/docs.yml | 5 +- .github/workflows/matrix-tests.yml | 2 +- .github/workflows/tests.yml | 1 + .pre-commit-config.yaml | 2 +- Contributing.md | 55 ++++++++++++++++--- docs/requirements.txt | 5 -- g2p/tests/test_studio.py | 4 +- pyproject.toml | 86 +++++++++++++++++++----------- readme-heroku.md | 4 +- requirements.txt | 2 +- 10 files changed, 113 insertions(+), 53 deletions(-) delete mode 100644 docs/requirements.txt diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0e3e2427..f174e61a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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]' diff --git a/.github/workflows/matrix-tests.yml b/.github/workflows/matrix-tests.yml index 0640b241..b34e21d1 100644 --- a/.github/workflows/matrix-tests.yml +++ b/.github/workflows/matrix-tests.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5366137a..975ab7e0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fa57c55..38dc39f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/Contributing.md b/Contributing.md index 76d57d41..92cf9c87 100644 --- a/Contributing.md +++ b/Contributing.md @@ -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 @@ -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 @@ -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: diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index 43d088b3..00000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -mkdocs>=1.5.2 -mkdocs-click>=0.8.0 -mkdocs-material>=9.2.5 -mkdocstrings[python]>=0.22.0 -mike>=1.1.2 diff --git a/g2p/tests/test_studio.py b/g2p/tests/test_studio.py index e7b66eb8..f9144370 100755 --- a/g2p/tests/test_studio.py +++ b/g2p/tests/test_studio.py @@ -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: @@ -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 diff --git a/pyproject.toml b/pyproject.toml index f7dea12d..6fc059f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,18 @@ 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", @@ -27,16 +39,37 @@ dependencies = [ "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] @@ -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] @@ -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"] diff --git a/readme-heroku.md b/readme-heroku.md index d39dedfb..53b78ebf 100644 --- a/readme-heroku.md +++ b/readme-heroku.md @@ -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 diff --git a/requirements.txt b/requirements.txt index 57288a56..cf42bb17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 @@ -21,6 +20,7 @@ # - regex # - text-unidecode # - tqdm +# - gunicorn>=21.1.0 # aniso8601==9.0.1 From c8cba5ff6783ca89cf3b417fedeeb3df0fdd901f Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 26 Mar 2024 16:13:29 -0400 Subject: [PATCH 06/11] fix(test): no longer require flask needlessly for some tests --- g2p/tests/test_cli.py | 4 ++-- g2p/tests/test_doctor_expensive.py | 5 +++-- g2p/tests/test_z_local_config.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/g2p/tests/test_cli.py b/g2p/tests/test_cli.py index bafa44a7..93d400b2 100755 --- a/g2p/tests/test_cli.py +++ b/g2p/tests/test_cli.py @@ -10,10 +10,10 @@ import jsonschema import yaml +from click.testing import CliRunner from tqdm import tqdm from g2p._version import VERSION -from g2p.app import APP from g2p.cli import ( convert, doctor, @@ -39,7 +39,7 @@ class CliTest(TestCase): """Test suite for the g2p Command Line Interface""" def setUp(self): - self.runner = APP.test_cli_runner() + self.runner = CliRunner() def test_update(self): result = self.runner.invoke(update) diff --git a/g2p/tests/test_doctor_expensive.py b/g2p/tests/test_doctor_expensive.py index 13eee00b..88090518 100755 --- a/g2p/tests/test_doctor_expensive.py +++ b/g2p/tests/test_doctor_expensive.py @@ -2,7 +2,8 @@ from unittest import TestCase, main -from g2p.app import APP +from click.testing import CliRunner + from g2p.cli import doctor from g2p.log import LOGGER from g2p.mappings.langs.utils import check_ipa_known_segs @@ -23,7 +24,7 @@ def test_doctor_cli(self): # TODO: assert something more useful here... # This test simulates calling "g2p doctor" on the command line with no arguments, # which runs doctor on all mappings. - runner = APP.test_cli_runner() + runner = CliRunner() with self.assertLogs(LOGGER, level="WARNING") as cm: result = runner.invoke(doctor) self.assertEqual(result.exit_code, 0) diff --git a/g2p/tests/test_z_local_config.py b/g2p/tests/test_z_local_config.py index b962e3a2..15690701 100755 --- a/g2p/tests/test_z_local_config.py +++ b/g2p/tests/test_z_local_config.py @@ -21,9 +21,9 @@ from unittest import TestCase, main import yaml +from click.testing import CliRunner from g2p import exceptions -from g2p.app import APP from g2p.cli import convert, generate_mapping from g2p.mappings import Mapping from g2p.mappings.utils import normalize @@ -32,7 +32,7 @@ class LocalConfigTest(TestCase): def setUp(self): - self.runner = APP.test_cli_runner() + self.runner = CliRunner() self.mappings_dir = Path(PUBLIC_DIR) / "mappings" def test_local_config(self): From 1a602ca2e66ac1b275cd6372d85cf47ec58f9023 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Wed, 27 Mar 2024 09:28:08 -0400 Subject: [PATCH 07/11] fix(build): various build fixes --- .coveragerc | 7 --- .flake8 | 8 ++- .github/workflows/pythonpublish.yml | 28 +++++----- .pre-commit-config.yaml | 5 +- .pylintrc | 8 --- g2p/tests/test_utils.py | 5 -- pyproject.toml | 86 +++++++++++++++++++---------- requirements.txt | 18 +++--- 8 files changed, 90 insertions(+), 75 deletions(-) delete mode 100644 .coveragerc delete mode 100644 .pylintrc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index da51e986..00000000 --- a/.coveragerc +++ /dev/null @@ -1,7 +0,0 @@ -[run] -branch = True -source_pkgs = g2p -omit = g2p/tests/* - -[report] -precision = 2 diff --git a/.flake8 b/.flake8 index 9cf3b9e0..118cfdfb 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,7 @@ +# NOTE: This is actually ignored by flake8 in pre-commit for some +# reason but it will get used in editors. How to make flake8 read it? +# Who knows? flake8 is a mystery. + [flake8] -extend-ignore = E203, E704 -max-line-length = 88 +max-line-length = 120 +extend-ignore = E203,E704 diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index ad3aa117..7e460a49 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -24,20 +24,20 @@ jobs: runs-on: ubuntu-latest needs: tests steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install build tool - run: pip install build - - name: Build a binary wheel and a source tarball - run: python -m build --sdist --wheel - - name: Store the distribution packages - uses: actions/upload-artifact@v4 - with: - name: python-package-distributions - path: dist/ + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Install build tool + run: pip install build + - name: Build a binary wheel and a source tarball + run: python -m build --sdist --wheel + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ github-release: name: Make a signed GitHub release diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38dc39f5..0d87253d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,7 @@ repos: stages: [commit] - repo: https://github.com/pycqa/flake8 # do flake8 last to avoid duplicate reports - rev: 3.8.3 + rev: 5.0.4 hooks: - - id: flake8 + - id: flake8 + args: ["--max-line-length=120", "--extend-ignore=E203,E704"] diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 1a320518..00000000 --- a/.pylintrc +++ /dev/null @@ -1,8 +0,0 @@ -[MAIN] -disable= - # We use isort for sorting our imports, so nevermind what pylint thinks - wrong-import-order, - # I find the "unnecessary" else makes code more readable - no-else-return, - # We use single letter e for exception, f for file handles - invalid-name diff --git a/g2p/tests/test_utils.py b/g2p/tests/test_utils.py index 4bc80971..3883bdc8 100755 --- a/g2p/tests/test_utils.py +++ b/g2p/tests/test_utils.py @@ -10,10 +10,8 @@ from unittest import TestCase, main import yaml -from pep440 import is_canonical from g2p import get_arpabet_langs -from g2p._version import VERSION from g2p.exceptions import IncorrectFileType, RecursionError from g2p.log import LOGGER from g2p.mappings import Mapping, utils @@ -299,9 +297,6 @@ def test_get_arpabet_langs(self): self.assertIs(LANGS2, LANGS) self.assertIs(LANG_NAMES2, LANG_NAMES) - def test_version_is_pep440_compliant(self): - self.assertTrue(is_canonical(VERSION)) - if __name__ == "__main__": main() diff --git a/pyproject.toml b/pyproject.toml index 6fc059f3..c4c6ac54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ api = [ "flask_socketio>=5.0.0", "python-engineio>=4.0.0", "python-socketio>=5.0.0", + "fastapi", ] test = [ "g2p[api]", @@ -52,16 +53,20 @@ test = [ 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", + "black~=24.3; python_version >= '3.8'", + "gitlint>=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", ] +# This one is a bit special and cannot depend on other features, +# because if it depends on `g2p[api]` then we end up with +# `g2p==SOMEVERSION` in requirements.txt and we DO NOT want that to +# happen. +# See https://github.com/jazzband/pip-tools/issues/2002 +# See https://github.com/juftin/hatch-pip-compile/issues/78 prod = [ - "g2p[api]", "gunicorn>=21.1.0", ] docs = [ @@ -120,25 +125,32 @@ requires = [ [tool.hatch.envs.api] features = [ "api" ] +[tool.hatch.envs.api.scripts] +serve = "flask --app g2p.app run" +routes = "flask --app g2p.app routes" + [tool.hatch.envs.prod] template = "api" +features = [ "api", "prod" ] type = "pip-compile" python = "3.10" lock-filename = "requirements.txt" -features = [ "prod" ] +pip-compile-verbose = false + +[tool.hatch.envs.prod.scripts] +serve = "gunicorn --worker-class eventlet -w 1 g2p.app:APP --no-sendfile" [tool.hatch.envs.test] features = [ "test" ] -[tool.hatch.envs.dev] -features = [ "dev" ] -post-install-commands = [ - "pre-commit install", - "gitlint install-hook || true", -] +[[tool.hatch.envs.test.matrix]] +python = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] -[tool.hatch.envs.dev.scripts] -check = "mypy --install-types --non-interactive {args:g2p}" +[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" cov-report = [ "- coverage combine", "coverage report", @@ -148,21 +160,15 @@ cov = [ "cov-report", ] -[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"] +[tool.hatch.envs.dev] +features = [ "dev" ] +post-install-commands = [ + "pre-commit install", + "gitlint install-hook || true", +] -[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.hatch.envs.dev.scripts] +check = "mypy --install-types --non-interactive {args:g2p}" [tool.coverage.run] source_pkgs = ["g2p"] @@ -170,7 +176,7 @@ branch = true parallel = true omit = [ "g2p/_version.py", - "g2p/tests", + "g2p/tests/**/*.py", ] [tool.coverage.report] @@ -181,3 +187,27 @@ plugins = ["pydantic.mypy"] [tool.isort] profile = "black" + +[tool.pylint.main] +# Unsure how to make pylint recursively ignore +ignore = [ + "g2p/tests", + "g2p/tests/public", + "g2p/tests/public/data", +] + +[tool.pylint.messages_control] +# This is TOO LONG but the code is that way for the moment +max-line-length = 120 +good-names = [ + # We use single letter e for exception, f for file handles + "e", "f", +] +disable = [ + # We do this to speed loading time, sorry pylint but not sorry + "import-outside-toplevel", + # We use isort for sorting our imports, so nevermind what pylint thinks + "wrong-import-order", + # I find the "unnecessary" else makes code more readable + "no-else-return", +] diff --git a/requirements.txt b/requirements.txt index cf42bb17..f8360643 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,14 @@ # # - 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 # - eventlet!=0.36.0,>=0.33.0 # - flask-cors>=3.0.9 # - flask-restful>=0.3.9 @@ -10,16 +18,8 @@ # - 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 # - gunicorn>=21.1.0 # @@ -43,7 +43,7 @@ editdistance==0.8.1 # via panphon et-xmlfile==1.1.0 # via openpyxl -eventlet==0.35.2 +eventlet==0.36.1 # via hatch.envs.prod flask==3.0.2 ; python_version >= "3.8" # via From 9543c96c168fa0a360db2022df7266b2993448a9 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 12 Apr 2024 17:20:53 -0400 Subject: [PATCH 08/11] fix(deps): old versions of eventlet are also broken --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c4c6ac54..79e74800 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ [project.optional-dependencies] api = [ - "eventlet>=0.33.0,!=0.36.0", + "eventlet>=0.36.1", "flask-cors>=3.0.9", "flask-restful>=0.3.9", "flask-talisman>=0.7.0", From 4e6c3aba4c78c86e9ed7af1bb7f410ddbf99fafc Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 12 Apr 2024 17:45:01 -0400 Subject: [PATCH 09/11] fix(docs): add install link for hatch --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9cced0a3..9ba00fe6 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,10 @@ The initial version of this package was developed by [Patrick Littell](https://g The best thing to do is install with pip `pip install g2p`. This command will install the latest release published on [PyPI g2p releases](https://pypi.org/project/g2p/). -You can also use [hatch](https://hatch.pypa.io/latest/) to set up an -isolated local development environment, which may be useful if you -wish to contribute new mappings: +You can also use [hatch](https://hatch.pypa.io/latest/) (see [hatch +installation instructions](https://hatch.pypa.io/latest/install/)) to +set up an isolated local development environment, which may be useful +if you wish to contribute new mappings: ```sh $ git clone https://github.com/roedoejet/g2p.git From 656f07a257c319f91ba390bbf87a806b03096b47 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 12 Apr 2024 19:05:33 -0400 Subject: [PATCH 10/11] fix(ci): ensure version matches schema --- .github/workflows/tests.yml | 4 ++-- g2p/tests/test_cli.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 975ab7e0..b55f9e5b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,8 +6,8 @@ on: # Since we don't checkout the full history, set a default version so # certain tests (pep440, update_schema) will still function. NOTE: -# This **must** match the version of the JSON schema file in -# g2p/mappings/.schema!!! +# This **must** match the Major.Minor version of the JSON schema file +# in g2p/mappings/.schema!!! env: SETUPTOOLS_SCM_PRETEND_VERSION: "2.0" diff --git a/g2p/tests/test_cli.py b/g2p/tests/test_cli.py index 93d400b2..098d7ba7 100755 --- a/g2p/tests/test_cli.py +++ b/g2p/tests/test_cli.py @@ -97,6 +97,19 @@ def test_update(self): result = self.runner.invoke(update, ["-i", bad_langs_dir, "-o", tmpdir]) self.assertEqual(result.exit_code, 0) + def test_schema_ci_version(self): + """Make sure that the version (possibly a fake version - see + .github/workflows/tests.yml) matches the one in the schema.""" + MAJOR_MINOR_VERSION = ".".join(VERSION.split(".")[:2]) + self.assertTrue( + ( + Path(__file__).parent.parent + / "mappings" + / ".schema" + / f"g2p-config-schema-{MAJOR_MINOR_VERSION}.json" + ).exists() + ) + def test_update_schema(self): result = self.runner.invoke(update_schema) self.assertNotEqual(result.exit_code, 0) From 4e23d76b630c54fc8df3a3f4c33efafed7f407f7 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 12 Apr 2024 19:10:08 -0400 Subject: [PATCH 11/11] fix(docs): mention conda --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ba00fe6..8bdb5ebb 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ $ hatch shell You can also simply install an "editable" version with `pip` (but it is recommended to do this in a [virtual -environment](https://docs.python.org/3/library/venv.html)): +environment](https://docs.python.org/3/library/venv.html) or a [conda +environment](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)): ```sh $ git clone https://github.com/roedoejet/g2p.git