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

Use FrozenOrderedSet with PexRequirements and PexInterpreterConstraints #9229

Merged

Conversation

Eric-Arellano
Copy link
Contributor

For both PexRequirements and PexInterpreterConstraints—which are both collections of strs—we desire these properties:

  1. Must be hashable.
  2. Should be immutable.
  3. Must have consistent ordering, otherwise, we get very few cache hits.
  4. Must de-duplicate all elements.

We previously achieved this by using tuple(sorted(set(elements))) because at the time that was the best we could do now. Now, we can simply use FrozenOrderedSet(sorted(elements)) to get all 4 properties.

FrozenOrderedSet is both more ergonomic and better expresses the intent of what we're doing.

--

We also provide custom constructors for both types to allow accepting a flexible Iterable[str], rather than something specific like Tuple[str, ...]. This makes for cleaner call sites. More importantly, it allows us to move the sorting into the constructor, rather than expecting the call sites to have been pre-sorted.

constraint
for target_adaptor in adaptors
for constraint in python_setup.compatibility_or_constraints(
getattr(target_adaptor, "compatibility", None)
)
if isinstance(target_adaptor, PythonTargetAdaptor)
}
return PexInterpreterConstraints(constraint_set=tuple(sorted(interpreter_constraints)))
return PexInterpreterConstraints(constraints)
Copy link
Contributor

Choose a reason for hiding this comment

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

all these named arguments going away feels orthogonal to this change. I kind of like them going away because the constructors only take one argument, but still it's a bit odd.

Not a problem at all though :)

@Eric-Arellano Eric-Arellano merged commit bf29173 into pantsbuild:master Mar 4, 2020
@Eric-Arellano Eric-Arellano deleted the pex-frozen-ordered-set branch March 4, 2020 18:36
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.

2 participants