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

Be stricter about our Python factors #2830

Closed
wants to merge 5 commits into from

Conversation

stephenfin
Copy link
Contributor

@stephenfin stephenfin commented Jan 6, 2023

Fixes #2657 by only using non-prefixed factors that look like Python versions, rather than accepting virtually anything.

We also opt to discourage non-prefixed factors since these are far too likely to conflict with other non-Python factors and the current behavior is very magical. We can fully remove this functionality in a future release.

Thanks for contribution

Please, make sure you address all the checklists (for details on how see
development documentation)!

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

We are relying on 'PythonSpec.from_string_spec' from 'virtualenv' to
determine if a factor is actually a Python factor that implies a
specific base python. The regex 'PythonSpec.from_string_spec' is too
loose for our purposes so use our own.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: tox-dev#2657
We currently allow users to request a Python factor without an
interpreter short name prefix. This is highly unusual and rather error
prone, given it's likely to conflict with e.g. versions of other
packages. We shouldn't really support this so start logging a warning,
effectively deprecating this and allowing us to remove this
functionality later.

Signed-off-by: Stephen Finucane <stephen@that.guru>
@stephenfin
Copy link
Contributor Author

Need to add tests and a release note. Next week's work though.

@gaborbernat
Copy link
Member

@stephenfin do you plan picking up this today, or shall I cut the new release without this?

@stephenfin
Copy link
Contributor Author

I'll wrap this up shortly.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
@stephenfin stephenfin marked this pull request as ready for review January 10, 2023 18:31
Signed-off-by: Stephen Finucane <stephen@that.guru>
@stephenfin
Copy link
Contributor Author

This is done now. However, I think #2848 is a far better, less complex approach. If we did merge this, I'd be proposing removing all of what was added here if/when we'd merge #2848 or some variant of same.

@gaborbernat
Copy link
Member

I cannot accept #2848 as is for the reasons outlined in it. We can fine-tune the range of valid specs, though; but that's a conversation for that PR.

Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

Some stylistic feedback, but otherwise looks good.

Comment on lines +152 to +153
# TODO: Drop in a future version
# PythonSpec.from_string_spec set implementation to None for py and python
Copy link
Member

Choose a reason for hiding this comment

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

Remove the TODO. We haven't decided if we'll do or not.

Comment on lines +154 to +162
if impl is None and not factor.startswith("py") and not factor.startswith("python"):
logging.warning(
"identified the %s factor in the %s testenv as a Python spec but the interpreter implementation "
"was not specified. This will be a ignored in future versions of tox. Please prefix this factor "
"with an interpreter short name (one of: %s)",
factor,
env_name,
", ".join(list(INTERPRETER_SHORT_NAMES) + ["py"]),
)
Copy link
Member

Choose a reason for hiding this comment

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

Remove this warning please. tox r -e 3.8 I think should be valid and we should default to py prefix in that case.

Comment on lines +84 to +85
# TODO: This is acceptable to 'PythonSpec.from_string_spec' but is
# clearly not valid :(
Copy link
Member

Choose a reason for hiding this comment

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

Remove todo 👍 we can discuss this in an issue, don't need code comments for it.

("2000", "2000"),
("4000", None),
],
ids=lambda a: "|".join(a) if isinstance(a, list) else str(a),
Copy link
Member

Choose a reason for hiding this comment

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

use i instead of a?

@stephenfin
Copy link
Contributor Author

stephenfin commented Jan 11, 2023

Thanks for the review. I think doing our own parsing for factors [*] is a better than plugging holes in virtualenv's PythonSpec.from_string_spec, which really is not suitable for this use case. I'm going to close this in favour of #2849. I know that's not quite ready yet but we can work through the kinks together. Obviously this shouldn't block new tox releases and you might want to cut a new tox release now while discussion in ongoing.

[*] Specifically factors. base_python parsing can(/should?) continue to be done by PythonSpec.from_string_spec

@stephenfin stephenfin closed this Jan 11, 2023
@stephenfin stephenfin deleted the issues/2657 branch January 11, 2023 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numeric factor in environment name wrongly causes "conflicting factors" error
2 participants