MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / is_compatible

Function is_compatible

src/packagedcode/models.py:1856–1910  ·  view source on GitHub ↗

Return True if the ``purl1`` PackageURL-like object is compatible with the ``purl2`` PackageURL-like object, e.g. it is about the same package. PackageData objectys are PackageURL-like. For example:: >>> p1 = PackageURL.from_string('pkg:deb/libncurses5@6.1-1ubuntu1.18.04?arch=a

(
    purl1,
    purl2,
    include_version=True,
    include_qualifiers=True,
    include_subpath=True,
    ignore_name_check=False,
)

Source from the content-addressed store, hash-verified

1854
1855
1856def is_compatible(
1857 purl1,
1858 purl2,
1859 include_version=True,
1860 include_qualifiers=True,
1861 include_subpath=True,
1862 ignore_name_check=False,
1863):
1864 """
1865 Return True if the ``purl1`` PackageURL-like object is compatible with
1866 the ``purl2`` PackageURL-like object, e.g. it is about the same package.
1867 PackageData objectys are PackageURL-like.
1868
1869 For example::
1870 >>> p1 = PackageURL.from_string('pkg:deb/libncurses5@6.1-1ubuntu1.18.04?arch=arm64')
1871 >>> p2 = PackageURL.from_string('pkg:deb/libncurses5@6.1-1ubuntu1.18.04')
1872 >>> p3 = PackageURL.from_string('pkg:deb/libssl')
1873 >>> p4 = PackageURL.from_string('pkg:deb/libncurses5')
1874 >>> p5 = PackageURL.from_string('pkg:deb/libncurses5@6.1-1ubuntu1.18.04?arch=arm64#/sbin')
1875 >>> is_compatible(p1, p2)
1876 False
1877 >>> is_compatible(p1, p2, include_qualifiers=False)
1878 True
1879 >>> is_compatible(p1, p4)
1880 False
1881 >>> is_compatible(p1, p4, include_version=False, include_qualifiers=False)
1882 True
1883 >>> is_compatible(p3, p4)
1884 False
1885 >>> is_compatible(p1, p5)
1886 False
1887 >>> is_compatible(p1, p5, include_subpath=False)
1888 True
1889 """
1890 if ignore_name_check:
1891 is_compatible = (
1892 purl1.type == purl2.type
1893 and purl1.namespace == purl2.namespace
1894 )
1895 else:
1896 is_compatible = (
1897 purl1.type == purl2.type
1898 and purl1.namespace == purl2.namespace
1899 and purl1.name == purl2.name
1900 )
1901 if include_version:
1902 is_compatible = is_compatible and (purl1.version == purl2.version)
1903
1904 if include_qualifiers:
1905 is_compatible = is_compatible and (purl1.qualifiers == purl2.qualifiers)
1906
1907 if include_subpath:
1908 is_compatible = is_compatible and (purl1.subpath == purl2.subpath)
1909
1910 return is_compatible
1911
1912
1913@attr.attributes(slots=True)

Callers 1

updateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected