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

Populate marker environment with extra as "" by default #548

Closed
pradyunsg opened this issue May 12, 2022 · 2 comments · Fixed by #550
Closed

Populate marker environment with extra as "" by default #548

pradyunsg opened this issue May 12, 2022 · 2 comments · Fixed by #550

Comments

@pradyunsg
Copy link
Member

IMO, packaging should assume an empty list of extras by default, rather than requiring the caller to specify it explicitly

Originally posted by @pfmoore in pypa/pip#11112 (comment)

I agree with @pfmoore. :)

@MrMino
Copy link
Contributor

MrMino commented May 18, 2022

I believe this requires adding an empty string under the right key in markers.default_environment? Seems a bit too simple, what am I missing?

@MrMino
Copy link
Contributor

MrMino commented May 18, 2022

I believe that, with this change, the markers.UndefinedEnvironmentName becomes redundant. It's impossible to trigger it.

The default environment already contains all of the possible marker names (checked using the code below), and the grammar set out in the module via pyparsing makes it impossible to use any other. evaluate() doesn't seem to have a way of explicitly specifying undefined name in the environment either.

Should it be removed?

The code below loops through all possible "variable" names, and does not raise any exception:

from packaging.markers import Marker

names = [
    "implementation_version",
    "platform_python_implementation",
    "implementation_name",
    "python_full_version",
    "platform_release",
    "platform_version",
    "platform_machine",
    "platform_system",
    "python_version",
    "sys_platform",
    "os_name",
    "os.name",
    "sys.platform",
    "platform.version",
    "platform.machine",
    "platform.python_implementation",
    "python_implementation",
    "extra",
]
for name in names:
    Marker(f"{name} == '1.2.3'").evaluate()

Edit: funnily enough, I had to remove the last place where raise UndefinedEnvironmentName was, because of coverage. I don't see a way of creating a proper unit test that goes through that clause.

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

Successfully merging a pull request may close this issue.

2 participants