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

✨ universal locks across environments #17

Merged
merged 6 commits into from
Nov 25, 2023
Merged

✨ universal locks across environments #17

merged 6 commits into from
Nov 25, 2023

Conversation

juftin
Copy link
Owner

@juftin juftin commented Nov 24, 2023

Closes #12

Summary

  • This PR implements the use of the default lock file as a constraint file on a non-detached environment
    • This use of lock files as constraints files also requires that we disable the pip-compile-strip-extras feature as all lock files will need to be constraints compatible.
  • This PR separates some key lockfile operations into a new class, lock.PipCompileLock. This will help to eventually integrate the header functionality into a CLI outside of a hatch plugin

See requirements-docs.txt as an example.

@oprypin
Copy link
Contributor

oprypin commented Nov 24, 2023

I see there are some missed assumptions about "default" stuff in Hatch.

https://hatch.pypa.io/1.7/config/environment/overview/#inheritance

Hatch environments have inheritance of all values. Any environment can choose to inherit from another environment. Multiple levels of inheritance are possible. The config for that is called template.

The environment named "default" has only these special things about it:

  • It always exists.
  • You don't need to spell out its name when using hatch run.
  • Every environment has the default value of template = "default".

I can create a new environment named "shmefault" and never use "default".

And here's an example of 2-level-deep inheritance:

[envs.shmefault]
template = "shmefault"
dependencies = ["dep1"]

[envs.env2]
template = "shmefault"
extra-dependencies = ["dep2"]

[envs.env3]
template = "env2"

hatch env show env3 has dependencies dep1 dep2

Further:
It's not specifically the environment named "default" that gets the project itself as a dependency. Any environment directly controls whether it will have the project itself installed. So we can get this:

[envs.default]
skip-install = true
dependencies = ["dep1"]

[envs.env2]
skip-install = false
extra-dependencies = ["dep2"]

So here the "default" env will have only dep1, but the "env2" env will have the project itself installed and dep1 inherited and dep2

@oprypin
Copy link
Contributor

oprypin commented Nov 24, 2023

Separate comment: the config detached is only a shorthand for writing skip-install = true template = "{env_name}", so it is incorrect to check for it. Luckily it's easy to change, you just check for self.skip_install instead.
https://hatch.pypa.io/latest/config/environment/overview/#detached-environments

pyproject.toml Show resolved Hide resolved
@juftin juftin marked this pull request as ready for review November 25, 2023 03:11
@juftin juftin self-assigned this Nov 25, 2023
@juftin juftin added the enhancement New feature or request label Nov 25, 2023
Copy link
Contributor

@oprypin oprypin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

pyproject.toml Show resolved Hide resolved
@juftin juftin merged commit ee0a3e3 into main Nov 25, 2023
1 check passed
@juftin juftin deleted the feat/constraints branch November 25, 2023 23:24
github-actions bot added a commit that referenced this pull request Nov 25, 2023
# [v1.1.0](v1.0.2...v1.1.0) (2023-11-25)

## ✨ New Features
- [`ee0a3e3`](ee0a3e3)  universal locks across environments (Issues: [`#17`](#17) [`#12`](#12))

[skip ci]
@juftin
Copy link
Owner Author

juftin commented Nov 25, 2023

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

universal locks across environments
2 participants