Python pip._vendor.pkg_resources.Distribution() Examples
The following are 30
code examples of pip._vendor.pkg_resources.Distribution().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pip._vendor.pkg_resources
, or try the search function
.
Example #1
Source File: req_uninstall.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def uninstallation_paths(dist): # type: (Distribution) -> Iterator[str] """ Yield all the uninstallation paths for dist based on RECORD-without-.py[co] Yield paths to all the files in RECORD. For each .py file in RECORD, add the .pyc and .pyo in the same directory. UninstallPathSet.add() takes care of the __pycache__ .py[co]. """ r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD'))) for row in r: path = os.path.join(dist.location, row[0]) yield path if path.endswith('.py'): dn, fn = os.path.split(path) base = fn[:-3] path = os.path.join(dn, base + '.pyc') yield path path = os.path.join(dn, base + '.pyo') yield path
Example #2
Source File: req_uninstall.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _script_names(dist, script_name, is_gui): # type: (Distribution, str, bool) -> List[str] """Create the fully qualified name of the files created by {console,gui}_scripts for the given ``dist``. Returns the list of file names """ if dist_in_usersite(dist): bin_dir = bin_user else: bin_dir = bin_py exe_name = os.path.join(bin_dir, script_name) paths_to_remove = [exe_name] if WINDOWS: paths_to_remove.append(exe_name + '.exe') paths_to_remove.append(exe_name + '.exe.manifest') if is_gui: paths_to_remove.append(exe_name + '-script.pyw') else: paths_to_remove.append(exe_name + '-script.py') return paths_to_remove
Example #3
Source File: packaging.py From pex with Apache License 2.0 | 6 votes |
def get_metadata(dist): # type: (Distribution) -> Message """ :raises NoneMetadataError: if the distribution reports `has_metadata()` True but `get_metadata()` returns None. """ metadata_name = 'METADATA' if (isinstance(dist, pkg_resources.DistInfoDistribution) and dist.has_metadata(metadata_name)): metadata = dist.get_metadata(metadata_name) elif dist.has_metadata('PKG-INFO'): metadata_name = 'PKG-INFO' metadata = dist.get_metadata(metadata_name) else: logger.warning("No metadata found in %s", display_path(dist.location)) metadata = '' if metadata is None: raise NoneMetadataError(dist, metadata_name) feed_parser = FeedParser() # The following line errors out if with a "NoneType" TypeError if # passed metadata=None. feed_parser.feed(metadata) return feed_parser.close()
Example #4
Source File: req_install.py From deepWordBug with Apache License 2.0 | 6 votes |
def get_dist(self): # type: () -> Distribution """Return a pkg_resources.Distribution for this requirement""" if self.metadata_directory: base_dir, distinfo = os.path.split(self.metadata_directory) metadata = pkg_resources.PathMetadata( base_dir, self.metadata_directory ) dist_name = os.path.splitext(distinfo)[0] typ = pkg_resources.DistInfoDistribution else: egg_info = self.egg_info_path.rstrip(os.path.sep) base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] # https://github.com/python/mypy/issues/1174 typ = pkg_resources.Distribution # type: ignore return typ( base_dir, project_name=dist_name, metadata=metadata, )
Example #5
Source File: req_uninstall.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def uninstallation_paths(dist): # type: (Distribution) -> Iterator[str] """ Yield all the uninstallation paths for dist based on RECORD-without-.py[co] Yield paths to all the files in RECORD. For each .py file in RECORD, add the .pyc and .pyo in the same directory. UninstallPathSet.add() takes care of the __pycache__ .py[co]. """ r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD'))) for row in r: path = os.path.join(dist.location, row[0]) yield path if path.endswith('.py'): dn, fn = os.path.split(path) base = fn[:-3] path = os.path.join(dn, base + '.pyc') yield path path = os.path.join(dn, base + '.pyo') yield path
Example #6
Source File: req_install.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def get_dist(self): # type: () -> Distribution """Return a pkg_resources.Distribution for this requirement""" if self.metadata_directory: base_dir, distinfo = os.path.split(self.metadata_directory) metadata = pkg_resources.PathMetadata( base_dir, self.metadata_directory ) dist_name = os.path.splitext(distinfo)[0] typ = pkg_resources.DistInfoDistribution else: egg_info = self.egg_info_path.rstrip(os.path.sep) base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] # https://github.com/python/mypy/issues/1174 typ = pkg_resources.Distribution # type: ignore return typ( base_dir, project_name=dist_name, metadata=metadata, )
Example #7
Source File: req_uninstall.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _script_names(dist, script_name, is_gui): # type: (Distribution, str, bool) -> List[str] """Create the fully qualified name of the files created by {console,gui}_scripts for the given ``dist``. Returns the list of file names """ if dist_in_usersite(dist): bin_dir = bin_user else: bin_dir = bin_py exe_name = os.path.join(bin_dir, script_name) paths_to_remove = [exe_name] if WINDOWS: paths_to_remove.append(exe_name + '.exe') paths_to_remove.append(exe_name + '.exe.manifest') if is_gui: paths_to_remove.append(exe_name + '-script.pyw') else: paths_to_remove.append(exe_name + '-script.py') return paths_to_remove
Example #8
Source File: req_uninstall.py From pex with Apache License 2.0 | 6 votes |
def uninstallation_paths(dist): # type: (Distribution) -> Iterator[str] """ Yield all the uninstallation paths for dist based on RECORD-without-.py[co] Yield paths to all the files in RECORD. For each .py file in RECORD, add the .pyc and .pyo in the same directory. UninstallPathSet.add() takes care of the __pycache__ .py[co]. """ r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD'))) for row in r: path = os.path.join(dist.location, row[0]) yield path if path.endswith('.py'): dn, fn = os.path.split(path) base = fn[:-3] path = os.path.join(dn, base + '.pyc') yield path path = os.path.join(dn, base + '.pyo') yield path
Example #9
Source File: req_uninstall.py From pex with Apache License 2.0 | 6 votes |
def _script_names(dist, script_name, is_gui): # type: (Distribution, str, bool) -> List[str] """Create the fully qualified name of the files created by {console,gui}_scripts for the given ``dist``. Returns the list of file names """ if dist_in_usersite(dist): bin_dir = bin_user else: bin_dir = bin_py exe_name = os.path.join(bin_dir, script_name) paths_to_remove = [exe_name] if WINDOWS: paths_to_remove.append(exe_name + '.exe') paths_to_remove.append(exe_name + '.exe.manifest') if is_gui: paths_to_remove.append(exe_name + '-script.pyw') else: paths_to_remove.append(exe_name + '-script.py') return paths_to_remove
Example #10
Source File: misc.py From pex with Apache License 2.0 | 5 votes |
def dist_in_usersite(dist): # type: (Distribution) -> bool """ Return True if given Distribution is installed in user site. """ return dist_location(dist).startswith(normalize_path(user_site))
Example #11
Source File: req_install.py From anpr with Creative Commons Attribution 4.0 International | 5 votes |
def get_dist(self): """Return a pkg_resources.Distribution built from self.egg_info_path""" egg_info = self.egg_info_path('').rstrip('/') base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] return pkg_resources.Distribution( os.path.dirname(egg_info), project_name=dist_name, metadata=metadata)
Example #12
Source File: prepare.py From deepWordBug with Apache License 2.0 | 5 votes |
def dist(self): # type: () -> pkg_resources.Distribution return list(pkg_resources.find_distributions( self.req.source_dir))[0]
Example #13
Source File: prepare.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def dist(self): # type: () -> pkg_resources.Distribution return self.req.satisfied_by
Example #14
Source File: prepare.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def dist(self): # type: () -> pkg_resources.Distribution return list(pkg_resources.find_distributions( self.req.source_dir))[0]
Example #15
Source File: req_install.py From pySINDy with MIT License | 5 votes |
def get_dist(self): """Return a pkg_resources.Distribution built from self.egg_info_path""" egg_info = self.egg_info_path.rstrip(os.path.sep) base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] return pkg_resources.Distribution( os.path.dirname(egg_info), project_name=dist_name, metadata=metadata, )
Example #16
Source File: req_install.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def get_dist(self): """Return a pkg_resources.Distribution built from self.egg_info_path""" egg_info = self.egg_info_path('').rstrip(os.path.sep) base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] return pkg_resources.Distribution( os.path.dirname(egg_info), project_name=dist_name, metadata=metadata, )
Example #17
Source File: req_install.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def get_dist(self): """Return a pkg_resources.Distribution built from self.egg_info_path""" egg_info = self.egg_info_path('').rstrip(os.path.sep) base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] return pkg_resources.Distribution( os.path.dirname(egg_info), project_name=dist_name, metadata=metadata, )
Example #18
Source File: req_install.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def get_dist(self): """Return a pkg_resources.Distribution built from self.egg_info_path""" egg_info = self.egg_info_path('').rstrip(os.path.sep) base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] return pkg_resources.Distribution( os.path.dirname(egg_info), project_name=dist_name, metadata=metadata, )
Example #19
Source File: prepare.py From deepWordBug with Apache License 2.0 | 5 votes |
def dist(self): # type: () -> pkg_resources.Distribution return self.req.satisfied_by
Example #20
Source File: misc.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def dist_in_site_packages(dist): # type: (Distribution) -> bool """ Return True if given Distribution is installed in sysconfig.get_python_lib(). """ return normalize_path( dist_location(dist) ).startswith(normalize_path(site_packages))
Example #21
Source File: misc.py From pex with Apache License 2.0 | 5 votes |
def dist_is_local(dist): # type: (Distribution) -> bool """ Return True if given Distribution object is installed locally (i.e. within current virtualenv). Always True if we're not in a virtualenv. """ return is_local(dist_location(dist))
Example #22
Source File: exceptions.py From pex with Apache License 2.0 | 5 votes |
def __init__(self, dist, metadata_name): # type: (Distribution, str) -> None """ :param dist: A Distribution object. :param metadata_name: The name of the metadata being accessed (can be "METADATA" or "PKG-INFO"). """ self.dist = dist self.metadata_name = metadata_name
Example #23
Source File: req_install.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def get_dist(self): """Return a pkg_resources.Distribution built from self.egg_info_path""" egg_info = self.egg_info_path('').rstrip('/') base_dir = os.path.dirname(egg_info) metadata = pkg_resources.PathMetadata(base_dir, egg_info) dist_name = os.path.splitext(os.path.basename(egg_info))[0] return pkg_resources.Distribution( os.path.dirname(egg_info), project_name=dist_name, metadata=metadata)
Example #24
Source File: misc.py From pex with Apache License 2.0 | 5 votes |
def dist_location(dist): # type: (Distribution) -> str """ Get the site-packages location of this distribution. Generally this is dist.location, except in the case of develop-installed packages, where dist.location is the source code location, and we want to know where the egg-link file is. The returned location is normalized (in particular, with symlinks removed). """ egg_link = egg_link_path(dist) if egg_link: return normalize_path(egg_link) return normalize_path(dist.location)
Example #25
Source File: packaging.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def get_installer(dist): # type: (Distribution) -> str if dist.has_metadata('INSTALLER'): for line in dist.get_metadata_lines('INSTALLER'): if line.strip(): return line.strip() return ''
Example #26
Source File: packaging.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def get_metadata(dist): # type: (Distribution) -> Message if (isinstance(dist, pkg_resources.DistInfoDistribution) and dist.has_metadata('METADATA')): metadata = dist.get_metadata('METADATA') elif dist.has_metadata('PKG-INFO'): metadata = dist.get_metadata('PKG-INFO') else: logger.warning("No metadata found in %s", display_path(dist.location)) metadata = '' feed_parser = FeedParser() feed_parser.feed(metadata) return feed_parser.close()
Example #27
Source File: misc.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def egg_link_path(dist): # type: (Distribution) -> Optional[str] """ Return the path for the .egg-link file if it exists, otherwise, None. There's 3 scenarios: 1) not in a virtualenv try to find in site.USER_SITE, then site_packages 2) in a no-global virtualenv try to find in site_packages 3) in a yes-global virtualenv try to find in site_packages, then site.USER_SITE (don't look in global location) For #1 and #3, there could be odd cases, where there's an egg-link in 2 locations. This method will just return the first one found. """ sites = [] if running_under_virtualenv(): if virtualenv_no_global(): sites.append(site_packages) else: sites.append(site_packages) if user_site: sites.append(user_site) else: if user_site: sites.append(user_site) sites.append(site_packages) for site in sites: egglink = os.path.join(site, dist.project_name) + '.egg-link' if os.path.isfile(egglink): return egglink return None
Example #28
Source File: misc.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def dist_is_editable(dist): # type: (Distribution) -> bool """ Return True if given Distribution is an editable install. """ for path_item in sys.path: egg_link = os.path.join(path_item, dist.project_name + '.egg-link') if os.path.isfile(egg_link): return True return False
Example #29
Source File: misc.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def dist_in_usersite(dist): # type: (Distribution) -> bool """ Return True if given Distribution is installed in user site. """ norm_path = normalize_path(dist_location(dist)) return norm_path.startswith(normalize_path(user_site))
Example #30
Source File: prepare.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def dist(self): # type: () -> pkg_resources.Distribution return self.req.satisfied_by