Skip to content

universal-lock: add marker evaluation for just extras #3352

@BurntSushi

Description

@BurntSushi

The central way that a universal lock file is generated is by ignoring the markers in a list of dependencies. For example, given:

foo>=3 ; sys_platform == 'linux'
foo<3 ; sys_platform == 'darwin'

then a universal lock file needs to be generated by considering both foo>=3 and foo<3. Normally, the marker expressions would cause these dependencies to be disjoint.

However, not all markers should be ignored. The extra marker, for example, should still be evaluated since it isn't directly dependent on the platform.

This ticket is thus about adding a new marker evaluation routine that only looks at platform independent markers:

/// Returns whether the markers apply for the given environment
pub fn evaluate_markers(&self, env: &MarkerEnvironment, extras: &[ExtraName]) -> bool {
if let Some(marker) = &self.marker {
marker.evaluate(env, extras)
} else {
true
}
}

There does exist this routine:

/// Returns whether the requirement would be satisfied, independent of environment markers, i.e.
/// if there is potentially an environment that could activate this requirement.
///
/// Note that unlike [`Self::evaluate_markers`] this does not perform any checks for bogus
/// expressions but will simply return true. As caller you should separately perform a check
/// with an environment and forward all warnings.
pub fn evaluate_extras_and_python_version(
&self,
extras: &HashSet<ExtraName>,
python_versions: &[Version],
) -> bool {
if let Some(marker) = &self.marker {
marker.evaluate_extras_and_python_version(extras, python_versions)
} else {
true
}
}

But it also evaluates Python versions and its signature is a bit different.

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewExperimental behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions