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

[WIP] Add --interpreter-compatibility option to repl goal #6234

Closed
wants to merge 2 commits into from

Conversation

alanbato
Copy link
Member

Problem

As explained in #6081, currently there isn't a way to further constrain the python interpreter version selection when firing up a repl session.

Solution

This PR includes the addition of a new option under the repl goal scope, and also the merging of the three ways of specifying interpreter version constraints (pants.ini, by-target, by options).

@@ -30,6 +31,8 @@ def register_options(cls, register):
help='The IPython REPL entry point.')
register('--ipython-requirements', advanced=True, type=list, default=['ipython==1.0.0'],
help='The IPython interpreter version to use.')
register('--interpreter-compatibility', advanced=True, type=list, default=[],
Copy link
Contributor

Choose a reason for hiding this comment

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

After exploring options further, I noticed that these are namespaced to --repl-py, so we might be able to shorten this to just --compatibility. Keeping these options short and sweet makes them easier to use for the end developer. The conceptual model should carry over from the target-level compatibility settings, but I would like some input from other Pants contributors before we change it.

@@ -46,8 +49,19 @@ def setup_repl_session(self, targets):
entry_point = self.get_options().ipython_entry_point
else:
entry_point = 'code:interact'
# Merge interpreter constraints
Copy link
Contributor

Choose a reason for hiding this comment

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

Micro-nit: period after comments please.

repl_constraints = self.get_options().interpreter_compatibility
target_constraints = [constraint for target in targets for constraint in target.compatibility]
if repl_constraints and target_constraints:
interpreter_constraints = [",".join(pair) for pair in zip(repl_constraints, target_constraints)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like merging will become a bit more intricate than first expected. We want a single string like you have here so that we AND the constraints, however we need to do things like de-duplicate interpreter class (CPython) and this will currently fail to parse: CPython>=2.7,<3,CPython>3. Also, this is a sizable chunk that would be a great opportunity for abstraction into a helper instance method, say merge_interpreter_constraints(targets) or similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will follow up with you about this offline.

@jsirois
Copy link
Contributor

jsirois commented Jul 26, 2018

Why is a new option needed? IOW, why is PythonSetup.global_instance().interpreter_constraints not enough here? You can determine if the constraints were flagged (vs they come from pants.ini) with:

python_setup = PythonSetup.global_instance()
custom_repl_constraints_supplied = python_setup.get_options().is_flagged('interpreter_constraints')
...

@CMLivingston
Copy link
Contributor

CMLivingston commented Jul 26, 2018

AFAICT the new option is needed to either merge or override compatibility constraints at the target level. The use case is that we have internal 2/3 compatible libraries that specify CPython>=2.7,<4 and we want to give users a CLI option to toggle whether they repl for Python 2 or 3. Alan suggested doing something similar to overriding target-level options as seen in #6065 for the jvm target class.

@alanbato
Copy link
Member Author

We've decided to take @jsirois and opened a new PR (#6250) to solve the issue in a way with less complexity and maintainance cost.

@alanbato alanbato closed this Jul 27, 2018
stuhood pushed a commit that referenced this pull request Aug 28, 2018
I commandeered @alanbato's PR at #6250

## Problem
The original issue is documented at #6081, an attempt to solve this was #6234, but we've decided to take another path instead.

## Solution
Instead of relying on interpreter constraints when building a pex in the repl task, we're checking if the --python-setup-interpreter-constraints is flagged. If so, it overrides the interpreter filters at interpreter selection time.

## Result
Users should now be able to further filter the python interpreter to use even if the task does not declare an option to do so (like in the repl task)
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.

3 participants