wiz.utility¶
-
wiz.utility.get_requirement(content)[source]¶ Return the corresponding requirement instance from content.
Parameters: content – String representing a requirement, with or without version specifier or variant (e.g. “maya”, “nuke >= 10, < 11”, “ldpk-nuke[10.0]”). Returns: Instance of packaging.requirements.Requirement.Raise: wiz.exception.InvalidRequirementif the requirement is incorrect.
-
wiz.utility.get_requirements(contents)[source]¶ Return the corresponding requirement instance from content.
Parameters: contents – List of strings representing requirements, with or without version specifier or variant (e.g. “maya”, “nuke >= 10, < 11”, “ldpk-nuke[10.0]”). Returns: List of packaging.requirements.Requirementinstances.Raise: wiz.exception.InvalidRequirementif the requirement is incorrect.
-
wiz.utility.get_version(content)[source]¶ Return the corresponding version instance from content.
Parameters: content – String representing a version (e.g. “2018”, “0.1.0”). Returns: Instance of packaging.version.Version.Raise: wiz.exception.InvalidVersionif the version is incorrect.
-
wiz.utility.is_overlapping(requirement1, requirement2)[source]¶ Indicate whether requirements are overlapping.
A requirement is overlapping with another one if their intersection of version ranges are not empty.
Example:
>>> is_overlapping(Requirement("foo >= 10"), Requirement("foo < 9")) True >>> is_overlapping(Requirement("foo >= 10"), Requirement("foo < 8")) False >>> is_overlapping(Requirement("foo[V2]"), Requirement("foo[V1]")) False
Parameters: - requirement1 – Instance of
packaging.requirements.Requirement. - requirement2 – Instance of
packaging.requirements.Requirement.
Returns: Boolean value.
Raise: ValueErrorif requirements cannot be compared.- requirement1 – Instance of
-
wiz.utility.extract_version_ranges(requirement)[source]¶ Extract version ranges from requirement.
Requirement could contain the following specifiers:
- Compatible release
- Version matching
- Version exclusion
- Inclusive ordered comparison
- Exclusive ordered comparison
Example:
>>> extract_version_ranges(Requirement("foo")) [(None, None)] >>> extract_version_ranges(Requirement("foo==2.1.1")) [((2, 1, 1), (2, 1, 1))] >>> extract_version_ranges(Requirement("foo!=2.1.1")) [(None, (2, 1, 0, 9999)), ((2, 1, 1, 1), None)] >>> extract_version_ranges(Requirement("foo ==2.*")) [((2,), (2, 9999))] >>> extract_version_ranges(Requirement("foo >= 2, < 3")) [((2,), (2, 9999))]
Parameters: requirement – Instance of packaging.requirements.Requirement.Returns: List of version tuples. Raise: wiz.exception.InvalidVersionif the version extracted from the specifier is incorrect.Raise: wiz.exception.InvalidRequirementif the specifier operator is not accepted or if the requirement does not allow any versions to be reached.
-
wiz.utility.compare_versions(version1, version2)[source]¶ Compare two versions following logic defined in PEP 440.
Invalid versions are always considered as lower than valid versions.
Example:
>>> sorted( ... ["2.3.4", "12.3", "1.0.0b0", "invalid"], ... key=functools.cmp_to_key(compare_versions) ... ) ["invalid", "1.0.0b0", "2.3.4", "12.3"]
Parameters: - version1 – String representing a versio .
- version2 – String representing a version to compare version1 with.
Returns: Returns 0 if bother versions are equal, -1 if version1 is lower than version2, or 1 if version1 is higher than version2.
-
wiz.utility.encode(element)[source]¶ Return serialized and encoded element.
element is serialized first, then encoded into base64.
Parameters: element – Content to encode. Returns: Encoded string. Raise: TypeErrorif element is not JSON serializable.
-
wiz.utility.decode(element)[source]¶ Return deserialized and decoded element.
element is decoded first from base64, then deserialized.
Parameters: element – Content to decode. Raise: TypeErrorif element cannot be decoded or deserialized.
-
wiz.utility.compute_label(definition)[source]¶ Return unique label for definition.
The name should be in the form of:
"'foo'" "'bar' [0.1.0]" "'baz' [0.2.0] (linux : el =! 7)" "'bim' (linux : el >= 6, < 7)"
Parameters: definition – Instance of wiz.definition.Definition.Returns: String representing definition.
-
wiz.utility.compute_system_label(definition)[source]¶ Return unique system label from definition.
The system identifier should be in the form of:
"noarch" "linux : x86_64 : el >= 7, < 8" "centos >= 7, < 8" "x86_64 : el >= 7, < 8" "windows"
Parameters: definition – Instance of wiz.definition.Definition.Returns: String representing system identifier.
-
wiz.utility.compute_file_name(definition)[source]¶ Return unique file name from definition.
The file name should be in the form of:
"foo.json" "namespace-foo-0.1.0.json" "foo-0.1.0.json" "foo-0.1.0-M2Uq9Esezm-m00VeWkTzkQIu3T4.json"
Parameters: definition – Instance of wiz.definition.Definition.Returns: File name representing definition.
-
wiz.utility.combine_command(elements)[source]¶ Return command elements as a string.
Example:
>>> combine_command( ... ['python2.7', '-c', 'import os; print(os.environ["HOME"])']) ... ) python2.7 -c 'import os; print(os.environ["HOME"])'
Parameters: elements – List of strings constituting the command line to execute (e.g. [“app_exe”, “–option”, “value”])
-
wiz.utility.deep_update(mapping1, mapping2)[source]¶ Recursively update mapping1 from mapping2.
Contrary to
dict.update(), this function will attempt to update sub-dictionaries defined in both mappings instead of overwriting the value defined in mapping1:>>> deep_update({"A": {"B": 2}}, {"A": {"C": 3}}) {"A": {"B": 2, "C": 3}}
Parameters: - mapping1 – Mapping to update
- mapping2 – Mapping to update mapping1 from
Returns: mapping1 mutated.
Note
mapping1 will be mutated, but mapping2 will not.
-
wiz.utility.sanitize_requirement(requirement, package)[source]¶ Return qualified requirement depending on package’s namespace.
Example:
# If the package has a namespace of 'foo' >>> sanitize_requirement(Requirement("A >=1, <2"), package) Requirement("foo::A >=1, <2") # If the package has no namespace >>> sanitize_requirement(Requirement("A >=1, <2"), package) Requirement("::A >=1, <2")
Parameters: - requirement – Instance of
packaging.requirements.Requirement. - package – Instance of
wiz.package.Package.
Returns: new instance of
packaging.requirements.Requirement.Raise: ValueErrorif requirement is incompatible with package.- requirement – Instance of
-
wiz.utility.compute_namespace_counter(requirements, definition_mapping)[source]¶ Compute namespace frequency counter from requirements.
Parameters: - requirements – List of
packaging.requirements.Requirementinstances. - definition_mapping – Mapping regrouping all available definitions associated with their unique identifier.
Returns: Instance of
collections.Counter.- requirements – List of
-
wiz.utility.match(requirement, package)[source]¶ Return whether requirement is compatible with package.
Parameters: - requirement – Instance of
packaging.requirements.Requirement. - package – Instance of
wiz.package.Package.
Returns: Boolean value.
- requirement – Instance of
-
wiz.utility.extract_namespace(requirement)[source]¶ Extract namespace and identifier from requirement.
Example:
>>> extract_namespace(Requirement("foo")) None, "foo" >>> extract_namespace(Requirement("::foo")) None, "foo" >>> extract_namespace(Requirement("bar::foo")) "bar", "foo" >>> extract_namespace(Requirement("bar1::bar2::foo")) "bar1::bar2", "foo"
-
wiz.utility.check_conflicting_requirements(package1, package2)[source]¶ Check whether some requirements are conflicting between packages.
Parameters: - package1 – Instance of
wiz.package.Package. - package2 – Instance of
wiz.package.Packageto compare package1 with.
Returns: Boolean value.
- package1 – Instance of