Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Poetry 1.1 to Hatch #58

Merged
merged 4 commits into from
Dec 30, 2022
Merged

Migrate from Poetry 1.1 to Hatch #58

merged 4 commits into from
Dec 30, 2022

Conversation

br3ndonland
Copy link
Owner

@br3ndonland br3ndonland commented Dec 30, 2022

Description

This PR will migrate inboard from Poetry 1.1 to Hatch. See #56 for more details and context around the motivations for this change.

Note that projects using inboard are not required to migrate to Hatch. The Docker images will retain Poetry 1.1 for backwards compatibility for now. Poetry 1.1 is unmaintained, and so it will eventually need to be removed, but there will be notice given at least one minor version ahead of time. If projects using inboard require poetry>1.2, they can add pipx upgrade poetry or pipx install poetry>1.2 --force to their Dockerfiles as described in the updated docs in this PR (on the Docker page, under "Docker and Poetry").

Changes

Update configuration files for Hatch

  • Remove poetry.lock
  • Remove poetry.toml
  • Remove [tool.poetry] sections from pyproject.toml
  • Update [build-system] section in pyproject.toml for Hatchling
  • Move version number to inboard/__init__.py, which allows Python projects to import it with import inboard then inboard.__version__
  • Add project metadata to new [project] section in pyproject.toml, bringing this project in line with Python project metadata standards
  • Add optional dependencies to [project.optional-dependencies] groups
  • Pin asgiref and mypy to avoid breaking changes to type checking that could be introduced by changes to mypy strict mode (2cbc99c) or by changes to asgiref TypedDict keys (d729fdf)
  • Add environments to [tool.hatch.envs.*] tables, using features for optional dependency groups, and path = ".venv" for an in-project virtualenv in the same location as a Poetry in-project virtualenv
  • Add Hatch environment names to .gitignore

Update Dockerfile for Hatch

  • Remove poetry.lock and poetry.toml from COPY step
  • Add README.md to COPY step (README.md is part of the Python package)
  • Break ARG and ENV commands onto multiple lines for readability
  • Add HATCH_VERSION build arg
  • Set HATCH_ENV_TYPE_VIRTUAL_PATH=".venv" to ensure consistent in-project virtualenv location
  • Install Hatch with pipx
  • Continue installing Poetry 1.1 with pipx for backwards compatibility for now. Poetry 1.1 is unmaintained, and so it will eventually need to be removed, but there will be notice given at least one minor version ahead of time.
  • Replace poetry install commands with hatch env create commands. There is no direct command to manually install or sync dependencies. The Hatch docs say, "You never need to manually create environments as spawning a shell or running commands within one will automatically trigger creation." The hatch env create command will create the virtual environment and install the appropriate dependencies. Note that commands for directly installing or syncing environments may be added in the future.

Update GitHub Actions workflows for Hatch

  • Update test that ensures pipx installs correct version of Hatch
  • Update test for consistent in-project virtualenv directory (.venv)
  • Update caching for pip so that GitHub Actions caches dependencies
  • Update poetry run commands for Hatch, ensuring correct environment is selected with the HATCH_ENV environment variable
  • Update package build and PyPI publish commands for Hatch

Update docs for Hatch

  • Add new user words to cspell.json
  • Add Hatch description and instructions to contributing.md
  • Update Poetry references in docs for Hatch
  • Move instructions for code quality checks below instructions for Hatch so that contributors understand how to set up the project prior to running code quality checks

Related

- Remove `poetry.lock`
- Remove `poetry.toml`
- Remove `[tool.poetry]` sections from `pyproject.toml`
- Update `[build-system]` section in `pyproject.toml` for Hatchling
- Move version number to `inboard/__init__.py`, which allows Python
  projects to import it with `import inboard` then `inboard.__version__`
- Add project metadata to new `[project]` section in `pyproject.toml`,
  bringing this project in line with Python project metadata standards
- Add optional dependencies to `[project.optional-dependencies]` groups
- Pin asgiref and mypy to avoid breaking changes to type checking that
  could be introduced by changes to mypy strict mode (2cbc99c) or by
  changes to asgiref `TypedDict` keys (d729fdf)
- Add environments to `[tool.hatch.envs.*]` tables, using `features` for
  optional dependency groups, and `path = ".venv"` for an in-project
  virtualenv in the same location as a Poetry in-project virtualenv
  https://hatch.pypa.io/latest/config/environment/overview/
  https://hatch.pypa.io/latest/plugins/environment/virtual/
- Add Hatch environment names to `.gitignore`
- Remove `poetry.lock` and `poetry.toml` from `COPY` step
- Add README.md to `COPY` step (README.md is part of the Python package)
- Break `ARG` and `ENV` commands onto multiple lines for readability
- Add `HATCH_VERSION` build arg
- Set `HATCH_ENV_TYPE_VIRTUAL_PATH=".venv"` to ensure consistent
  in-project virtualenv location
- Install Hatch with `pipx`
- Continue installing Poetry 1.1 with `pipx` for backwards compatibility
  for now. Poetry 1.1 is unmaintained, and so it will eventually need to
  be removed. Notice will be given at least one minor version ahead.
- Replace `poetry install` commands with `hatch env create` commands.
  There is no direct command to manually install or sync dependencies.
  The Hatch docs say, "You never need to manually create environments as
  spawning a shell or running commands within one will automatically
  trigger creation." The `hatch env create` command will create the
  virtual environment and install the appropriate dependencies.
  https://hatch.pypa.io/latest/environment/
@vercel
Copy link

vercel bot commented Dec 30, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
inboard ✅ Ready (Inspect) Visit Preview Dec 30, 2022 at 7:20PM (UTC)

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 30, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.48%.

Quality metrics Before After Change
Complexity 2.00 ⭐ 2.00 ⭐ 0.00
Method Length 43.00 ⭐ 46.00 ⭐ 3.00 👎
Working memory 4.00 ⭐ 4.00 ⭐ 0.00
Quality 89.89% 89.41% -0.48% 👎
Other metrics Before After Change
Lines 24 26 2
Changed files Quality Before Quality After Quality Change
inboard/__init__.py 89.89% ⭐ 89.41% ⭐ -0.48% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@br3ndonland
Copy link
Owner Author

The Sourcery report from @sourcery-ai[bot] suggests that adding __version__ to inboard/__init__.py decreases code quality. It actually increases code quality, because the version number is now available directly.

- Update test that ensures `pipx` installs correct version of Hatch
- Update test for consistent in-project virtualenv directory (`.venv`)
- Update caching for `pip` so that GitHub Actions caches dependencies
- Update `poetry run` commands for Hatch, ensuring correct environment
  is selected with the `HATCH_ENV` environment variable or by prefixing
  each command with the environment name
- Update package build and PyPI publish commands for Hatch
- Add new user words to `cspell.json`
- Add Hatch description and instructions to contributing.md
- Update Poetry references in docs for Hatch
- Move instructions for code quality checks below instructions for Hatch
  so that contributors understand how to set up the project prior to
  running code quality checks
@br3ndonland br3ndonland merged commit 78be3c2 into develop Dec 30, 2022
@br3ndonland br3ndonland deleted the hatch branch December 30, 2022 19:32
br3ndonland added a commit that referenced this pull request Dec 31, 2022
Move project install command after Hatch install command

#58
br3ndonland added a commit that referenced this pull request Dec 31, 2022
PR #58 reorganized `pyproject.toml` for Hatch, bringing it _almost_ in
line with PEP 621 standards. There was one oversight - the `repository`
URL used to be in the `[tool.poetry]` table, and should have been moved
to the `[project.urls]` table for Hatch. This commit will do so.

#58
https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
https://peps.python.org/pep-0621/
br3ndonland added a commit that referenced this pull request Jan 14, 2023
br3ndonland added a commit that referenced this pull request May 6, 2023
This commit provides a small follow-up to #58. The Hatch environment was
specified directly in the `hatch env create` command, but other commands
specified the environment implicitly with the `$HATCH_ENV` variable.

This commit will update `hatch env create` and `hatch run` commands to
reference the same environment variable directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant