-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
[DRAFT] Add version to metadata hook, use version to retrieve deps #1511
base: master
Are you sure you want to change the base?
Conversation
cc: @ofek -> would love to get some comments on that. |
Instead, what do you think about adding a context manager on the metadata class for temporarily setting a property which could be used here? https://github.com/pypa/hatch/blob/hatchling-v1.24.2/backend/src/hatchling/builders/plugin/interface.py#L89-L90 |
Yes. it will remove the need to have a new hook method if we do that, I was a bit hesitant to do that as the "metadata" will be quite a bit overloaded in this case (version is not |
f86ef9a
to
24874f3
Compare
Smth like that ? |
24874f3
to
328e06f
Compare
@@ -193,8 +203,9 @@ def core(self) -> CoreMetadata: | |||
|
|||
if metadata.dynamic: | |||
for metadata_hook in metadata_hooks.values(): | |||
metadata_hook.update(self.core_raw_metadata) | |||
metadata.add_known_classifiers(metadata_hook.get_known_classifiers()) | |||
with set_version(metadata_hook, self.version): |
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.
Here the context manager - and we have version property in the hook which we set (and can query in the hook).
This is a very draft proposal on how to fix pypa#1348 and pypa#1349 - more to see if this is a good direction. It should likely be split to two PRs (and of course tests and docs are needed): * extending custom metadata plugin to allow passing version through hook's version property to distinguish standard and editable builds (also including extending the hatchling CLIs. * adding version to CLI where hatch queries hatchling to include standard/ editable version when querying for available dependencies. Not all changes have been yet applied, this is more to check if this is the right direction.
328e06f
to
762d7a4
Compare
Or did you think to bubble it up to BuilderInterface ? |
Upon closer inspection I think the context manager I was thinking of would go on the first line after this loop and everything under would be indented: https://github.com/pypa/hatch/blob/hatchling-v1.24.2/backend/src/hatchling/builders/plugin/interface.py#L136 The context manager would live directly on the metadata class and would be used on Does that make sense? I haven't thoroughly looked at the moving parts but I think that would work, please let me know what you think! edit: I just thought of something... This line would then need to be inside the loop and within the context manager https://github.com/pypa/hatch/blob/hatchling-v1.24.2/backend/src/hatchling/builders/plugin/interface.py#L90 but then it wouldn't work when building multiple versions because the first invocation triggers metadata hooks. Hmm, since building multiple versions of a target at once is only possible with Hatch (and really not useful for wheels/source distributions) maybe let's forgo purity and send the list of versions here https://github.com/pypa/hatch/blob/hatchling-v1.24.2/backend/src/hatchling/builders/plugin/interface.py#L83 directly to the validate_fields method. |
Hmm. A bit of a problem there is that we do not necessarily have to run |
I can't remember the full execution path - but every time |
Some more details @ofek - Even if Traceback (most recent call last):
File "/Users/jarek/Library/Application Support/hatch/env/virtual/apache-airflow/MvrXOyBN/apache-airflow/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/Users/jarek/Library/Application Support/hatch/env/virtual/apache-airflow/MvrXOyBN/apache-airflow/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/Users/jarek/Library/Application Support/hatch/env/virtual/apache-airflow/MvrXOyBN/apache-airflow/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 176, in prepare_metadata_for_build_editable
whl_basename = build_hook(metadata_directory, config_settings)
File "/private/var/folders/v3/gvj4_mw152q556w2rrh7m46w0000gn/T/pip-build-env-rbopbuup/overlay/lib/python3.8/site-packages/hatchling/build.py", line 83, in build_editable
return os.path.basename(next(builder.build(directory=wheel_directory)))
File "/private/var/folders/v3/gvj4_mw152q556w2rrh7m46w0000gn/T/pip-build-env-rbopbuup/overlay/lib/python3.8/site-packages/hatchling/builders/plugin/interface.py", line 91, in build
self.metadata.validate_fields()
File "/private/var/folders/v3/gvj4_mw152q556w2rrh7m46w0000gn/T/pip-build-env-rbopbuup/overlay/lib/python3.8/site-packages/hatchling/metadata/core.py", line 277, in validate_fields
_ = self.version
File "/private/var/folders/v3/gvj4_mw152q556w2rrh7m46w0000gn/T/pip-build-env-rbopbuup/overlay/lib/python3.8/site-packages/hatchling/metadata/core.py", line 160, in version
self._version = self._get_version()
File "/private/var/folders/v3/gvj4_mw152q556w2rrh7m46w0000gn/T/pip-build-env-rbopbuup/overlay/lib/python3.8/site-packages/hatchling/metadata/core.py", line 256, in _get_version
core_metadata = self.core
File "/private/var/folders/v3/gvj4_mw152q556w2rrh7m46w0000gn/T/pip-build-env-rbopbuup/overlay/lib/python3.8/site-packages/hatchling/metadata/core.py", line 208, in core
metadata_hook.update(self.core_raw_metadata) By the time we get to the for loop you suggested, the This is why I moved the versions up to ProjectMetadata and other places. |
I have experimented a bit more with different approach: where |
Okay I thought about this and have a really good idea! I think this build indicator should be an environment variable that the caller sets. This would mean the Hatch CLI wouldn't have to change (unless you want a flag) and then inside the build method you would temporarily set the variable when calling the field validation method first thing. The environment variable could be called |
Sounds good. Let me see where I can get itl |
Thanks! I know you know what I meant but I made a typo, the environment variable should be edit: I just checked and it doesn't conflict with existing configuration https://hatch.pypa.io/latest/config/build/#environment-variables |
Yep. Understood :) |
This is a very draft proposal on how to fix #1348 and #1349 - more
to see if this is a good direction. It should likely be split to
two PRs (and of course tests and docs are needed):
extending custom metadata plugin to allow passing version through
hook's version property to distinguish standard and editable builds
(also including extending the hatchling CLIs.
adding version to CLI where hatch queries hatchling to include standard/
editable version when querying for available dependencies.
Not all changes have been yet applied, this is more to check if
this is the right direction.