Python pip._internal.utils.temp_dir.TempDirectory() Examples
The following are 30
code examples of pip._internal.utils.temp_dir.TempDirectory().
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._internal.utils.temp_dir
, or try the search function
.
Example #1
Source File: wheel.py From Python24 with MIT License | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if self.__build_one(req, temp_dir.path, python_tag=python_tag): try: wheel_name = os.listdir(temp_dir.path)[0] wheel_path = os.path.join(output_dir, wheel_name) shutil.move( os.path.join(temp_dir.path, wheel_name), wheel_path ) logger.info('Stored in directory: %s', output_dir) return wheel_path except: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #2
Source File: wheel.py From FuYiSpider with Apache License 2.0 | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if self.__build_one(req, temp_dir.path, python_tag=python_tag): try: wheel_name = os.listdir(temp_dir.path)[0] wheel_path = os.path.join(output_dir, wheel_name) shutil.move( os.path.join(temp_dir.path, wheel_name), wheel_path ) logger.info('Stored in directory: %s', output_dir) return wheel_path except: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #3
Source File: wheel.py From hacktoberfest2018 with GNU General Public License v3.0 | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if self.__build_one(req, temp_dir.path, python_tag=python_tag): try: wheel_name = os.listdir(temp_dir.path)[0] wheel_path = os.path.join(output_dir, wheel_name) shutil.move( os.path.join(temp_dir.path, wheel_name), wheel_path ) logger.info('Stored in directory: %s', output_dir) return wheel_path except: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #4
Source File: wheel.py From hacktoberfest2018 with GNU General Public License v3.0 | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if self.__build_one(req, temp_dir.path, python_tag=python_tag): try: wheel_name = os.listdir(temp_dir.path)[0] wheel_path = os.path.join(output_dir, wheel_name) shutil.move( os.path.join(temp_dir.path, wheel_name), wheel_path ) logger.info('Stored in directory: %s', output_dir) return wheel_path except: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #5
Source File: wheel.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if self.__build_one(req, temp_dir.path, python_tag=python_tag): try: wheel_name = os.listdir(temp_dir.path)[0] wheel_path = os.path.join(output_dir, wheel_name) shutil.move( os.path.join(temp_dir.path, wheel_name), wheel_path ) logger.info('Stored in directory: %s', output_dir) return wheel_path except Exception: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #6
Source File: wheel.py From FuYiSpider with Apache License 2.0 | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if self.__build_one(req, temp_dir.path, python_tag=python_tag): try: wheel_name = os.listdir(temp_dir.path)[0] wheel_path = os.path.join(output_dir, wheel_name) shutil.move( os.path.join(temp_dir.path, wheel_name), wheel_path ) logger.info('Stored in directory: %s', output_dir) return wheel_path except: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #7
Source File: wheel.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if req.use_pep517: builder = self._build_one_pep517 else: builder = self._build_one_legacy wheel_path = builder(req, temp_dir.path, python_tag=python_tag) if wheel_path is not None: wheel_name = os.path.basename(wheel_path) dest_path = os.path.join(output_dir, wheel_name) try: shutil.move(wheel_path, dest_path) logger.info('Stored in directory: %s', output_dir) return dest_path except Exception: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #8
Source File: req_uninstall.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _get_directory_stash(self, path): # type: (str) -> str """Stashes a directory. Directories are stashed adjacent to their original location if possible, or else moved/copied into the user's temp dir.""" try: save_dir = AdjacentTempDirectory(path) # type: TempDirectory save_dir.create() except OSError: save_dir = TempDirectory(kind="uninstall") save_dir.create() self._save_dirs[os.path.normcase(path)] = save_dir return save_dir.path
Example #9
Source File: wheel.py From deepWordBug with Apache License 2.0 | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if req.use_pep517: builder = self._build_one_pep517 else: builder = self._build_one_legacy wheel_path = builder(req, temp_dir.path, python_tag=python_tag) if wheel_path is not None: wheel_name = os.path.basename(wheel_path) dest_path = os.path.join(output_dir, wheel_name) try: shutil.move(wheel_path, dest_path) logger.info('Stored in directory: %s', output_dir) return dest_path except Exception: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #10
Source File: wheel.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _build_one_inside_env(self, req, output_dir, python_tag=None): with TempDirectory(kind="wheel") as temp_dir: if req.use_pep517: builder = self._build_one_pep517 else: builder = self._build_one_legacy wheel_path = builder(req, temp_dir.path, python_tag=python_tag) if wheel_path is not None: wheel_name = os.path.basename(wheel_path) dest_path = os.path.join(output_dir, wheel_name) try: shutil.move(wheel_path, dest_path) logger.info('Stored in directory: %s', output_dir) return dest_path except Exception: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
Example #11
Source File: req_uninstall.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _get_directory_stash(self, path): # type: (str) -> str """Stashes a directory. Directories are stashed adjacent to their original location if possible, or else moved/copied into the user's temp dir.""" try: save_dir = AdjacentTempDirectory(path) # type: TempDirectory save_dir.create() except OSError: save_dir = TempDirectory(kind="uninstall") save_dir.create() self._save_dirs[os.path.normcase(path)] = save_dir return save_dir.path
Example #12
Source File: req_install.py From pex with Apache License 2.0 | 6 votes |
def ensure_build_location(self, build_dir): # type: (str) -> str assert build_dir is not None if self._temp_build_dir is not None: assert self._temp_build_dir.path return self._temp_build_dir.path if self.req is None: # Some systems have /tmp as a symlink which confuses custom # builds (such as numpy). Thus, we ensure that the real path # is returned. self._temp_build_dir = TempDirectory(kind="req-build") return self._temp_build_dir.path if self.editable: name = self.name.lower() else: name = self.name # FIXME: Is there a better place to create the build_dir? (hg and bzr # need this) if not os.path.exists(build_dir): logger.debug('Creating directory %s', build_dir) _make_build_dir(build_dir) return os.path.join(build_dir, name)
Example #13
Source File: metadata.py From pex with Apache License 2.0 | 6 votes |
def generate_metadata(build_env, backend): # type: (BuildEnvironment, Pep517HookCaller) -> str """Generate metadata using mechanisms described in PEP 517. Returns the generated metadata directory. """ metadata_tmpdir = TempDirectory( kind="modern-metadata", globally_managed=True ) metadata_dir = metadata_tmpdir.path with build_env: # Note that Pep517HookCaller implements a fallback for # prepare_metadata_for_build_wheel, so we don't have to # consider the possibility that this hook doesn't exist. runner = runner_with_spinner_message("Preparing wheel metadata") with backend.subprocess_runner(runner): distinfo_dir = backend.prepare_metadata_for_build_wheel( metadata_dir ) return os.path.join(metadata_dir, distinfo_dir)
Example #14
Source File: wheel.py From pex with Apache License 2.0 | 6 votes |
def install_wheel( name, # type: str wheel_path, # type: str scheme, # type: Scheme req_description, # type: str pycompile=True, # type: bool warn_script_location=True, # type: bool _temp_dir_for_testing=None, # type: Optional[str] ): # type: (...) -> None with TempDirectory( path=_temp_dir_for_testing, kind="unpacked-wheel" ) as unpacked_dir: unpack_file(wheel_path, unpacked_dir.path) install_unpacked_wheel( name=name, wheeldir=unpacked_dir.path, scheme=scheme, req_description=req_description, pycompile=pycompile, warn_script_location=warn_script_location, )
Example #15
Source File: git.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def export(self, location): """Export the Git repository at the url to the destination location""" if not location.endswith('/'): location = location + '/' with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path) self.run_command( ['checkout-index', '-a', '-f', '--prefix', location], show_stdout=False, cwd=temp_dir.path )
Example #16
Source File: download.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def unpack_http_url(link, location, download_dir=None, session=None, hashes=None, progress_bar="on"): if session is None: raise TypeError( "unpack_http_url() missing 1 required keyword argument: 'session'" ) with TempDirectory(kind="unpack") as temp_dir: # If a download dir is specified, is the file already downloaded there? already_downloaded_path = None if download_dir: already_downloaded_path = _check_download_dir(link, download_dir, hashes) if already_downloaded_path: from_path = already_downloaded_path content_type = mimetypes.guess_type(from_path)[0] else: # let's download to a tmp dir from_path, content_type = _download_http_url(link, session, temp_dir.path, hashes, progress_bar) # unpack the archive to the build dir location. even when only # downloading archives, they have to be unpacked to parse dependencies unpack_file(from_path, location, content_type, link) # a download dir is specified; let's copy the archive there if download_dir and not already_downloaded_path: _copy_file(from_path, download_dir, link) if not already_downloaded_path: os.unlink(from_path)
Example #17
Source File: bazaar.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def export(self, location): """ Export the Bazaar repository at the url to the destination location """ # Remove the location to make sure Bazaar can export it correctly if os.path.exists(location): rmtree(location) with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path) self.run_command( ['export', location], cwd=temp_dir.path, show_stdout=False, )
Example #18
Source File: req_uninstall.py From deepWordBug with Apache License 2.0 | 5 votes |
def __init__(self): # Mapping from source file root to [Adjacent]TempDirectory # for files under that directory. self._save_dirs = {} # (old path, new path) tuples for each move that may need # to be undone. self._moves = []
Example #19
Source File: req_tracker.py From deepWordBug with Apache License 2.0 | 5 votes |
def __init__(self): # type: () -> None self._root = os.environ.get('PIP_REQ_TRACKER') if self._root is None: self._temp_dir = TempDirectory(delete=False, kind='req-tracker') self._temp_dir.create() self._root = os.environ['PIP_REQ_TRACKER'] = self._temp_dir.path logger.debug('Created requirements tracker %r', self._root) else: self._temp_dir = None logger.debug('Re-using requirements tracker %r', self._root) self._entries = set() # type: Set[InstallRequirement]
Example #20
Source File: mercurial.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def export(self, location): """Export the Hg repository at the url to the destination location""" with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path) self.run_command( ['archive', location], show_stdout=False, cwd=temp_dir.path )
Example #21
Source File: git.py From pex with Apache License 2.0 | 5 votes |
def export(self, location, url): # type: (str, HiddenText) -> None """Export the Git repository at the url to the destination location""" if not location.endswith('/'): location = location + '/' with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path, url=url) self.run_command( ['checkout-index', '-a', '-f', '--prefix', location], show_stdout=False, cwd=temp_dir.path )
Example #22
Source File: bazaar.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def export(self, location): """ Export the Bazaar repository at the url to the destination location """ # Remove the location to make sure Bazaar can export it correctly if os.path.exists(location): rmtree(location) with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path) self.run_command( ['export', location], cwd=temp_dir.path, show_stdout=False, )
Example #23
Source File: mercurial.py From pex with Apache License 2.0 | 5 votes |
def export(self, location, url): # type: (str, HiddenText) -> None """Export the Hg repository at the url to the destination location""" with TempDirectory(kind="export") as temp_dir: self.unpack(temp_dir.path, url=url) self.run_command( ['archive', location], show_stdout=False, cwd=temp_dir.path )
Example #24
Source File: req_uninstall.py From pex with Apache License 2.0 | 5 votes |
def _get_file_stash(self, path): # type: (str) -> str """Stashes a file. If no root has been provided, one will be created for the directory in the user's temp directory.""" path = os.path.normcase(path) head, old_head = os.path.dirname(path), None save_dir = None while head != old_head: try: save_dir = self._save_dirs[head] break except KeyError: pass head, old_head = os.path.dirname(head), head else: # Did not find any suitable root head = os.path.dirname(path) save_dir = TempDirectory(kind='uninstall') self._save_dirs[head] = save_dir relpath = os.path.relpath(path, head) if relpath and relpath != os.path.curdir: return os.path.join(save_dir.path, relpath) return save_dir.path
Example #25
Source File: build_env.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def __init__(self, no_clean): self._temp_dir = TempDirectory(kind="build-env") self._no_clean = no_clean
Example #26
Source File: req_uninstall.py From pex with Apache License 2.0 | 5 votes |
def __init__(self): # type: () -> None # Mapping from source file root to [Adjacent]TempDirectory # for files under that directory. self._save_dirs = {} # type: Dict[str, TempDirectory] # (old path, new path) tuples for each move that may need # to be undone. self._moves = [] # type: List[Tuple[str, str]]
Example #27
Source File: cache.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def __init__(self, format_control): self._temp_dir = TempDirectory(kind="ephem-wheel-cache") self._temp_dir.create() super(EphemWheelCache, self).__init__( self._temp_dir.path, format_control )
Example #28
Source File: download.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def unpack_http_url(link, location, download_dir=None, session=None, hashes=None, progress_bar="on"): if session is None: raise TypeError( "unpack_http_url() missing 1 required keyword argument: 'session'" ) with TempDirectory(kind="unpack") as temp_dir: # If a download dir is specified, is the file already downloaded there? already_downloaded_path = None if download_dir: already_downloaded_path = _check_download_dir(link, download_dir, hashes) if already_downloaded_path: from_path = already_downloaded_path content_type = mimetypes.guess_type(from_path)[0] else: # let's download to a tmp dir from_path, content_type = _download_http_url(link, session, temp_dir.path, hashes, progress_bar) # unpack the archive to the build dir location. even when only # downloading archives, they have to be unpacked to parse dependencies unpack_file(from_path, location, content_type, link) # a download dir is specified; let's copy the archive there if download_dir and not already_downloaded_path: _copy_file(from_path, download_dir, link) if not already_downloaded_path: os.unlink(from_path)
Example #29
Source File: req_uninstall.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def __init__(self, dist): self.paths = set() self._refuse = set() self.pth = {} self.dist = dist self.save_dir = TempDirectory(kind="uninstall") self._moved_paths = []
Example #30
Source File: req_uninstall.py From deepWordBug with Apache License 2.0 | 5 votes |
def _get_directory_stash(self, path): """Stashes a directory. Directories are stashed adjacent to their original location if possible, or else moved/copied into the user's temp dir.""" try: save_dir = AdjacentTempDirectory(path) save_dir.create() except OSError: save_dir = TempDirectory(kind="uninstall") save_dir.create() self._save_dirs[os.path.normcase(path)] = save_dir return save_dir.path