MCPcopy Create free account
hub / github.com/nodejs/node / _compare_equal

Method _compare_equal

tools/gyp/pylib/packaging/specifiers.py:397–436  ·  view source on GitHub ↗
(self, prospective: Version, spec: str)

Source from the content-addressed store, hash-verified

395 )
396
397 def _compare_equal(self, prospective: Version, spec: str) -> bool:
398
399 # We need special logic to handle prefix matching
400 if spec.endswith(".*"):
401 # In the case of prefix matching we want to ignore local segment.
402 normalized_prospective = canonicalize_version(
403 prospective.public, strip_trailing_zero=False
404 )
405 # Get the normalized version string ignoring the trailing .*
406 normalized_spec = canonicalize_version(spec[:-2], strip_trailing_zero=False)
407 # Split the spec out by bangs and dots, and pretend that there is
408 # an implicit dot in between a release segment and a pre-release segment.
409 split_spec = _version_split(normalized_spec)
410
411 # Split the prospective version out by bangs and dots, and pretend
412 # that there is an implicit dot in between a release segment and
413 # a pre-release segment.
414 split_prospective = _version_split(normalized_prospective)
415
416 # 0-pad the prospective version before shortening it to get the correct
417 # shortened version.
418 padded_prospective, _ = _pad_version(split_prospective, split_spec)
419
420 # Shorten the prospective version to be the same length as the spec
421 # so that we can determine if the specifier is a prefix of the
422 # prospective version or not.
423 shortened_prospective = padded_prospective[: len(split_spec)]
424
425 return shortened_prospective == split_spec
426 else:
427 # Convert our spec string into a Version
428 spec_version = Version(spec)
429
430 # If the specifier does not have a local segment, then we want to
431 # act as if the prospective version also does not have a local
432 # segment.
433 if not spec_version.local:
434 prospective = Version(prospective.public)
435
436 return prospective == spec_version
437
438 def _compare_not_equal(self, prospective: Version, spec: str) -> bool:
439 return not self._compare_equal(prospective, spec)

Callers 1

_compare_not_equalMethod · 0.95

Calls 4

canonicalize_versionFunction · 0.85
_version_splitFunction · 0.85
_pad_versionFunction · 0.85
VersionClass · 0.70

Tested by

no test coverage detected