python类find_distributions()的实例源码

packages.py 文件源码 项目:mbot 作者: michaelkuty 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def check_package_exists(package, lib_dir):
    """Check if a package is installed globally or in lib_dir.
    Returns True when the requirement is met.
    Returns False when the package is not installed or doesn't meet req.
    """
    try:
        req = pkg_resources.Requirement.parse(package)
    except ValueError:
        # This is a zip file
        req = pkg_resources.Requirement.parse(urlparse(package).fragment)

    # Check packages from lib dir
    if lib_dir is not None:
        if any(dist in req for dist in
               pkg_resources.find_distributions(lib_dir)):
            return True

    # Check packages from global + virtual environment
    # pylint: disable=not-an-iterable
    return any(dist in req for dist in pkg_resources.working_set)
package.py 文件源码 项目:homeassistant 作者: NAStools 项目源码 文件源码 阅读 55 收藏 0 点赞 0 评论 0
def check_package_exists(package: str, lib_dir: str) -> bool:
    """Check if a package is installed globally or in lib_dir.

    Returns True when the requirement is met.
    Returns False when the package is not installed or doesn't meet req.
    """
    try:
        req = pkg_resources.Requirement.parse(package)
    except ValueError:
        # This is a zip file
        req = pkg_resources.Requirement.parse(urlparse(package).fragment)

    # Check packages from lib dir
    if lib_dir is not None:
        if any(dist in req for dist in
               pkg_resources.find_distributions(lib_dir)):
            return True

    # Check packages from global + virtual environment
    # pylint: disable=not-an-iterable
    return any(dist in req for dist in pkg_resources.working_set)
test_dist_info.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
ah_bootstrap.py 文件源码 项目:whoseline 作者: bmorris3 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
ah_bootstrap.py 文件源码 项目:dust_extinction 作者: karllark 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
ah_bootstrap.py 文件源码 项目:thejoker 作者: adrn 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
test_dist_info.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
test_dist_info.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
ah_bootstrap.py 文件源码 项目:fiasco 作者: wtbarnes 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
ah_bootstrap.py 文件源码 项目:lombscargle 作者: jakevdp 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
test_dist_info.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
test_dist_info.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
test_dist_info.py 文件源码 项目:NeuroMobile 作者: AndrewADykman 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:NeuroMobile 作者: AndrewADykman 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
test_dist_info.py 文件源码 项目:dymo-m10-python 作者: pbrf 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = {}
        for d in pkg_resources.find_distributions(self.tmpdir):
            dists[d.project_name] = d

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:dymo-m10-python 作者: pbrf 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        requires = [pkg_resources.Requirement.parse('splort==4'),
                    pkg_resources.Requirement.parse('quux>=1.1')]

        for d in pkg_resources.find_distributions(self.tmpdir):
            self.assertEqual(d.requires(), requires[:1])
            self.assertEqual(d.requires(extras=('baz',)), requires)
            self.assertEqual(d.extras, ['baz'])
test_dist_info.py 文件源码 项目:Sudoku-Solver 作者: ayush1997 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_distinfo(self):
        dists = dict(
            (d.project_name, d)
            for d in pkg_resources.find_distributions(self.tmpdir)
        )

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718' # from filename
        assert unversioned.version == '0.3' # from METADATA
test_dist_info.py 文件源码 项目:Sudoku-Solver 作者: ayush1997 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self):
        specs = 'splort==4', 'quux>=1.1'
        requires = list(map(pkg_resources.Requirement.parse, specs))

        for d in pkg_resources.find_distributions(self.tmpdir):
            assert d.requires() == requires[:1]
            assert d.requires(extras=('baz',)) == requires
            assert d.extras == ['baz']
ah_bootstrap.py 文件源码 项目:ChiantiPy 作者: chianti-atomic 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
ah_bootstrap.py 文件源码 项目:specviz 作者: spacetelescope 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def _directory_import(self):
        """
        Import astropy_helpers from the given path, which will be added to
        sys.path.

        Must return True if the import succeeded, and False otherwise.
        """

        # Return True on success, False on failure but download is allowed, and
        # otherwise raise SystemExit
        path = os.path.abspath(self.path)

        # Use an empty WorkingSet rather than the man
        # pkg_resources.working_set, since on older versions of setuptools this
        # will invoke a VersionConflict when trying to install an upgrade
        ws = pkg_resources.WorkingSet([])
        ws.add_entry(path)
        dist = ws.by_key.get(DIST_NAME)

        if dist is None:
            # We didn't find an egg-info/dist-info in the given path, but if a
            # setup.py exists we can generate it
            setup_py = os.path.join(path, 'setup.py')
            if os.path.isfile(setup_py):
                with _silence():
                    run_setup(os.path.join(path, 'setup.py'),
                              ['egg_info'])

                for dist in pkg_resources.find_distributions(path, True):
                    # There should be only one...
                    return dist

        return dist
test_find_distributions.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_non_egg_dir_named_egg(self, target_dir):
        dists = pkg_resources.find_distributions(target_dir)
        assert not list(dists)
test_find_distributions.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_standalone_egg_directory(self, project_dir, target_dir):
        # install this distro as an unpacked egg:
        args = [
            sys.executable,
            '-c', 'from setuptools.command.easy_install import main; main()',
            '-mNx',
            '-d', target_dir,
            '--always-unzip',
            project_dir,
        ]
        subprocess.check_call(args)
        dists = pkg_resources.find_distributions(target_dir)
        assert [dist.project_name for dist in dists] == ['my-test-package']
        dists = pkg_resources.find_distributions(target_dir, only=True)
        assert not list(dists)
test_find_distributions.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_zipped_egg(self, project_dir, target_dir):
        # install this distro as an unpacked egg:
        args = [
            sys.executable,
            '-c', 'from setuptools.command.easy_install import main; main()',
            '-mNx',
            '-d', target_dir,
            '--zip-ok',
            project_dir,
        ]
        subprocess.check_call(args)
        dists = pkg_resources.find_distributions(target_dir)
        assert [dist.project_name for dist in dists] == ['my-test-package']
        dists = pkg_resources.find_distributions(target_dir, only=True)
        assert not list(dists)
test_dist_info.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_distinfo(self, metadata):
        dists = dict(
            (d.project_name, d)
            for d in pkg_resources.find_distributions(metadata)
        )

        assert len(dists) == 2, dists

        unversioned = dists['UnversionedDistribution']
        versioned = dists['VersionedDistribution']

        assert versioned.version == '2.718'  # from filename
        assert unversioned.version == '0.3'  # from METADATA
test_dist_info.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_conditional_dependencies(self, metadata):
        specs = 'splort==4', 'quux>=1.1'
        requires = list(map(pkg_resources.Requirement.parse, specs))

        for d in pkg_resources.find_distributions(metadata):
            assert d.requires() == requires[:1]
            assert d.requires(extras=('baz',)) == [
                requires[0],
                pkg_resources.Requirement.parse('quux>=1.1;extra=="baz"'),
            ]
            assert d.extras == ['baz']


问题


面经


文章

微信
公众号

扫码关注公众号