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

Link requirements targets to their source. #6405

Merged
merged 1 commit into from
Aug 28, 2018

Conversation

jsirois
Copy link
Contributor

@jsirois jsirois commented Aug 28, 2018

Previsouly the python_requirements macro would not link the
PythonRequirementLibrary targets it generated from a requirements
file to the requirement file itself, leading to invalidation bugs. We
now do this by adding a dependency on the requirements file to each
PythonRequirementLibrary generated.

Fixes #6404

Previsouly the `python_requirements` macro would not link the
`PythonRequirementLibrary` targets it generated from a requirements
file to the requirement file itself, leading to invalidation bugs. We
now do this by adding a dependency on the requirements file to each
`PythonRequirementLibrary` generated.

Fixes pantsbuild#6404
@stuhood stuhood added this to the 1.9.x milestone Aug 28, 2018
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!

An alternative implementation might be to add a default_sources_glob and a sources argument.

@stuhood stuhood modified the milestones: 1.9.x, 1.8.x Aug 28, 2018
@jsirois
Copy link
Contributor Author

jsirois commented Aug 28, 2018

An alternative implementation might be to add a default_sources_glob and a sources argument.

Adding a source - singular - optional argument to PythonRequirementLibrary might make sense to take the place of the dependency python_requirements injects. The tradeoff here is a wonky public BUILD dictionary source field that users should never use (see 2. below) vs a synthetic target (the Files target dependency) user's might not know what to make of when executing goals like list, dependencies or filemap.

The default_sources_glob makes less sense. You don't describe what that would be used for, but I can only see two cases and both have problems:

  1. The PythonRequirementLibrary is declared in a BUILD directly where the BUILD has a sibling requirements.txt. Now you get a bogus source dependency on requirments.txt for that PythonRequirementLibrary.
  2. If handed a source, whether via default globs or an explicit source argument, the PythonRequirementLibrary expands the source to requirements like the python_requirements macro currently does. This would lead to fat PythonRequirementLibrary targets that own all the requirements in a requirements.txt file which is almost always not what you want.

@jsirois jsirois requested a review from benjyw August 28, 2018 15:03
@stuhood stuhood requested a review from illicitonion August 28, 2018 16:00
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.

The PythonRequirementLibrary is declared in a BUILD directly where the BUILD has a sibling requirements.txt. Now you get a bogus source dependency on requirments.txt for that PythonRequirementLibrary.

Got it. I was forgetting the relationship between the macro and the target type.

Thanks!

@@ -58,9 +58,16 @@ def __call__(self, requirements_relpath='requirements.txt'):
raise ValueError('Only 1 --find-links url is supported per requirements file')
repository = value

requirements_file_target_name = requirements_relpath
self._parse_context.create_object('files',
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how likely collisions are, but it would be good to make this name a bit more synthetic, and include the owning target's name as well... '__{}_files'.format(requirements_file_target_name)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Saw this comment late. Right now the mainline case is a target named requirements.txt (or foo.bob if their requirements file is foo.bob). Having that filename match a requirement name or hand-written target name seemed pretty unlikely to me. I can circle back with a follow-up PR if you think my unlikely guess underestimates things.

Copy link
Member

Choose a reason for hiding this comment

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

Should be fine, unless we can imagine a case with multiple target owners of the same requirements files.

Copy link
Contributor Author

@jsirois jsirois Aug 29, 2018

Choose a reason for hiding this comment

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

That's not possible even prior to this change since the requirements would each be exported as targets named by their requirement key leading to a dup target for each of those.

@benjyw
Copy link
Contributor

benjyw commented Aug 28, 2018

Thanks for the quick turnaround!

@jsirois jsirois merged commit 1e4fa18 into pantsbuild:master Aug 28, 2018
@jsirois jsirois deleted the issues/6404 branch August 28, 2018 17:11
@stuhood stuhood modified the milestones: 1.8.x, 1.9.x Aug 28, 2018
stuhood pushed a commit that referenced this pull request Aug 28, 2018
Previously the `python_requirements` macro would not link the
`PythonRequirementLibrary` targets it generated from a requirements
file to the requirement file itself, leading to invalidation bugs. We
now do this by adding a dependency on the requirements file to each
`PythonRequirementLibrary` generated.

Fixes #6404
@stuhood
Copy link
Member

stuhood commented Aug 28, 2018

I've picked this to 1.8.x.

stuhood pushed a commit that referenced this pull request Aug 28, 2018
Previsouly the `python_requirements` macro would not link the
`PythonRequirementLibrary` targets it generated from a requirements
file to the requirement file itself, leading to invalidation bugs. We
now do this by adding a dependency on the requirements file to each
`PythonRequirementLibrary` generated.

Fixes #6404
benjyw added a commit to benjyw/pants that referenced this pull request Mar 15, 2020
We don't want to invalidate sources based on arbitrary
changes to requirements.txt, but we do need to depend on
it so we know to recompute requirements.

Previously this was achieved by synthesizing a files()
target and adding a dep on it, in the python_requirements macro.
However when we gather sources to operate on we have to include
all files(), meaning we were invalidating the sources even on
a whitespace change to requirements.txt.

This change adds a new, internal, target type specially for
the synthetic requirements.txt change, so that we can maintain
a dependency, but rules can still filter out the actual file.

Context: pantsbuild#6405
benjyw added a commit that referenced this pull request Mar 17, 2020
We don't want to invalidate sources based on arbitrary
changes to requirements.txt, but we do need to depend on
it so we know to recompute requirements.

Previously this was achieved by synthesizing a files()
target and adding a dep on it, in the python_requirements macro.
However when we gather sources to operate on we have to include
all files(), meaning we were invalidating the sources even on
a whitespace change to requirements.txt.

This change adds a new, internal, target type specially for
the synthetic requirements.txt change, so that we can maintain
a dependency, but rules can still filter out the actual file.

Context: #6405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants