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

Deprecate python_requirements and poetry_requirements using old macro in favor of target generation #14075

Merged
merged 12 commits into from
Jan 14, 2022

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Jan 5, 2022

Closes #12915.

Benefits of switching to target generation

Deprecation plan

This PR adds a new global option --use-deprecated-python-macros with a default of True. When True, parser.py is taught to load the old macros; else it loads the new targets.

The PR deprecates the default of --use-deprecated-python-macros so that it will default to False in Pants 2.11. Then, we'll deprecate the option outright and remove it in Pants 2.12, meaning the macros will be removed then too.

How users upgrade

❯ ./pants
17:06:21.30 [WARN] DEPRECATED: the option `--use-deprecated-python-macros` defaulting to true will be removed in version 2.11.0.dev0.

In Pants 2.11, the default for the global option `--use-deprecated-python-macros` will change to false.

To fix this deprecation, explicitly set `use_deprecated_python_macros = true` in the `[GLOBAL]` section of `pants.toml`. Or, When you are ready to upgrade to the improved target generation mechanism, follow these steps:

  1. Run `./pants update-build-files --fix-python-macros`
  2. Check the logs for an ERROR log to see if you have to manually add `name=` anywhere.
  3. Set `use_deprecated_python_macros = false` in `[GLOBAL]` in pants.toml.

(Why upgrade from the old macro mechanism to target generation? Among other benefits, it makes sure that the Pants daemon is properly invalidated when you change `requirements.txt` and `pyproject.toml`.)

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!

src/python/pants/backend/python/macros/common_fields.py Outdated Show resolved Hide resolved
@@ -1268,6 +1268,24 @@ def register_bootstrap_options(cls, register):
"may not be enabled.",
)

register(
"--use-deprecated-python-macros",
Copy link
Member

Choose a reason for hiding this comment

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

Since this flag will land as un-deprecated, it's starting out misnamed. Maybe invert to --use-new-python-macros?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh I don't think it matters much. But in my head, it makes sense to see this in pants.toml:

[GLOBAL]
use_deprecated_python_macros = false

It makes clear that you're opting out of deprecated functionality. Technically, the macros aren't yet formally deprecated. But in spirit, they are deprecated. It's only a logistical reason why we can't formally deprecate them more quickly.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. What does the alternative look like..

[GLOBAL]
use_new_python_macros = true

Makes it clear that you're opting in to use the new macros before that is the default thing.

Hmm.. nah, that option name is more wrong, the new thing is not macros at all..

Eric-Arellano added a commit that referenced this pull request Jan 5, 2022
…f `sources: list[str]` (#14082)

To minimize behavior changes while implementing #14075, we want to make sure that `--changed-since=HEAD --changed-dependees=direct` will still claim that all generated `python_requirement` targets are impacted if the `requirements.txt` changed.

This would happen naturally if a generated target depended on its target generator: #13118. But that will require a lot more design work and is a big change we're not ready to make.

So we can work around this by still having `_python_requirements_file` even with target generators. But before doing that, we should change to `source: str` to actually represent the expected API of the target.

Because this is a private API, we make a breaking change.

[ci skip-rust]
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
[ci skip-rust]
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano changed the title [wip] Deprecate python_requirements and poetry_requirements using old macro in favor of target generation Deprecate python_requirements and poetry_requirements using old macro in favor of target generation Jan 6, 2022
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano marked this pull request as ready for review January 6, 2022 00:29
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano
Copy link
Contributor Author

Bump @stuhood, this needs a re-review as it was approved while still a WIP.

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

Comment on lines 70 to +71

use_deprecated_python_macros = false
Copy link
Member

Choose a reason for hiding this comment

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

This is still weird to me (seems like a double-negative), but oh well!

…enerators

[ci skip-rust]
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano enabled auto-merge (squash) January 14, 2022 00:54
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano merged commit 9ad9204 into pantsbuild:main Jan 14, 2022
@Eric-Arellano Eric-Arellano deleted the python-reqs-generators branch January 14, 2022 18:59
Comment on lines +1638 to +1639
"2.11.0.dev0",
"the option `--use-deprecated-python-macros` defaulting to true",
Copy link
Member

Choose a reason for hiding this comment

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

One thing that would be good to fix before 2.10.0 is that this warning currently triggers in repos without the python backend enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants