-
-
Notifications
You must be signed in to change notification settings - Fork 361
Add env lock command to generate PEP compliant lock files. #2174
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
base: master
Are you sure you want to change the base?
Conversation
|
Generally this looks good as a first step, but we need to think about the way forward. I think the default way to use lockfiles with hatch should be declarative like the rest of env management. First of all, there is one issue: I think imperatively updating a lockfile like this PR enables is mosty useful for the This would facilitate a design like the following: designPersonally, I think I’d like to see
reusing lockfilesWe should integrate with I’d like to be able to define e.g. a all together:By default, the following config would make In each of the respective environments,
Note if [envs.hatch-test]
locked = true
dependency-groups = [ "test" ]
overrides.matrix.extras.features = [
{ if = [ "all" ], value = "feat1" },
]
[[envs.hatch-test.matrix]]
python = [ "3.14", "3.10" ]
extras = [ "none", "all" ]Running not consideredI used Footnotes |
|
I agree with the direction to be more per environment so I will start working on getting that implemented. I think the one thing that we might want to discuss is if it makes sense to lock internal environments by default and if internal environments should be allowed to be overridden for locking or not. |
|
|
||
| ## Locking a specific environment | ||
|
|
||
| Use the [`env lock`](../../cli/reference.md#hatch-env-lock) command with an environment name to generate a lockfile: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens with using hatch env create or hatch run on an env that’s locked? Will the lockfile not be generated?
What happens when using hatch lock on an env that’s not locked? Will the same lockfile be generated as if it was locked? I think that’d lead to confusion. I think --export should be mandatory for envs that aren’t locked (with an error message that mention lock-envs and locked).
|
|
||
| ## Locking all environments | ||
|
|
||
| To lock every environment at once, use the `--all` flag: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens when some envs aren’t locked using the config? Will this also generate files for them that hatch then ignores? I think that would lead to much confusion.
Because the default behavior is
When no explicit environment name is passed,
hatch env lockwill lock all environments that havelocked = true
I think either
--allshould just be removed and if--export=some/path/ends in a/, lockfiles for all envs should be put into that directory.- or (more explicit)
--allshould be renamed to--export-all=<PATH>, which is mutually exclusive with--exportand writes lockfiles for all envs to the specified directory
| Wrote lockfile: /path/to/project/pylock.toml | ||
| ``` | ||
|
|
||
| To lock all environments at once, use the `--all` flag: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
| # PEP 751 only allows one dot in the filename: pylock.<name>.toml | ||
| safe_name = environment.name.replace(".", "-") | ||
| return environment.root / f"pylock.{safe_name}.toml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this kind of name mangling is probably the best we can do.
| if isinstance(environment, VirtualEnvironment) and environment.use_uv: | ||
| _lock_with_uv(environment, deps_file, output_path, upgrade=upgrade, upgrade_packages=upgrade_packages) | ||
| else: | ||
| _lock_with_pip(environment, deps_file, output_path, upgrade=upgrade, upgrade_packages=upgrade_packages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If multiple envs share one lock-filename, they need to be locked together.
E.g. if I do
[envs.hatch-test]
locked = true
overrides.matrix.deps.env-vars = [
{ if = [ 'pre' ], key = 'UV_PRERELEASE', value = 'allow' },
]
overrides.matrix.deps.lock-filename = [
{ if = [ 'stable' ], value = 'pylock.test-stable.lock' },
{ if = [ 'pre' ], value = 'pylock.test-pre.lock' },
]
overrides.matrix.extras.features = [
{ if = [ 'all' ], value = 'feat1' },
]
[[envs.hatch-test.matrix]]
python = [ '3.14', '3.10' ]
deps = [ 'stable', 'pre' ]
extras = [ 'none', 'all' ]We want to see
pylock.test-stable.lock
pylock.test-pre.lock
And we want hatch to call uv pip compile exactly once per lockfile, with the combined dependencies, extras, and dependency-group of all environments.
As currently implemented, hatch would call it 3 times per environment, with it being a gamble which one wins.
This is a draft to start discussions around the design here for PEP 751 support by creating per environment lockfiles.
As of now this would currently only support a user triggering the lock through
hatch env lock MyEnvNameorhatch env lock --allI would like to get inputs here on if we want to support auto lockfile creation on environment creation or not?