Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: Lib/packaging/install.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/packaging/database.py ('k') | Lib/packaging/tests/__main__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Building blocks for installers. 1 """Building blocks for installers.
2 2
3 When used as a script, this module installs a release thanks to info 3 When used as a script, this module installs a release thanks to info
4 obtained from an index (e.g. PyPI), with dependencies. 4 obtained from an index (e.g. PyPI), with dependencies.
5 5
6 This is a higher-level module built on packaging.database and 6 This is a higher-level module built on packaging.database and
7 packaging.pypi. 7 packaging.pypi.
8 """ 8 """
9 import os 9 import os
10 import sys 10 import sys
(...skipping 24 matching lines...) Expand all
35 35
36 36
37 def _move_files(files, destination): 37 def _move_files(files, destination):
38 """Move the list of files in the destination folder, keeping the same 38 """Move the list of files in the destination folder, keeping the same
39 structure. 39 structure.
40 40
41 Return a list of tuple (old, new) emplacement of files 41 Return a list of tuple (old, new) emplacement of files
42 42
43 :param files: a list of files to move. 43 :param files: a list of files to move.
44 :param destination: the destination directory to put on the files. 44 :param destination: the destination directory to put on the files.
45 if not defined, create a new one, using mkdtemp
45 """ 46 """
47 if not destination:
48 destination = tempfile.mkdtemp()
46 49
47 for old in files: 50 for old in files:
48 filename = os.path.split(old)[-1] 51 filename = os.path.split(old)[-1]
49 new = os.path.join(destination, filename) 52 new = os.path.join(destination, filename)
50 # try to make the paths. 53 # try to make the paths.
51 try: 54 try:
52 os.makedirs(os.path.dirname(new)) 55 os.makedirs(os.path.dirname(new))
53 except OSError as e: 56 except OSError as e:
54 if e.errno != errno.EEXIST: 57 if e.errno != errno.EEXIST:
55 raise 58 raise
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 119
117 Returns True on success, False on Failure. 120 Returns True on success, False on Failure.
118 """ 121 """
119 path = os.path.abspath(path) 122 path = os.path.abspath(path)
120 if os.path.isdir(path): 123 if os.path.isdir(path):
121 logger.info('Installing from source directory: %s', path) 124 logger.info('Installing from source directory: %s', path)
122 return _run_install_from_dir(path) 125 return _run_install_from_dir(path)
123 elif _is_archive_file(path): 126 elif _is_archive_file(path):
124 logger.info('Installing from archive: %s', path) 127 logger.info('Installing from archive: %s', path)
125 _unpacked_dir = tempfile.mkdtemp() 128 _unpacked_dir = tempfile.mkdtemp()
126 try: 129 shutil.unpack_archive(path, _unpacked_dir)
127 shutil.unpack_archive(path, _unpacked_dir) 130 return _run_install_from_archive(_unpacked_dir)
128 return _run_install_from_archive(_unpacked_dir)
129 finally:
130 shutil.rmtree(_unpacked_dir)
131 else: 131 else:
132 logger.warning('No projects to install.') 132 logger.warning('No projects to install.')
133 return False 133 return False
134 134
135 135
136 def _run_install_from_archive(source_dir): 136 def _run_install_from_archive(source_dir):
137 # XXX need a better way 137 # XXX need a better way
138 for item in os.listdir(source_dir): 138 for item in os.listdir(source_dir):
139 fullpath = os.path.join(source_dir, item) 139 fullpath = os.path.join(source_dir, item)
140 if os.path.isdir(fullpath): 140 if os.path.isdir(fullpath):
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 If an error occurs while installing one of the distributions, uninstall all 173 If an error occurs while installing one of the distributions, uninstall all
174 the installed distribution (in the context if this function). 174 the installed distribution (in the context if this function).
175 175
176 Return a list of installed dists. 176 Return a list of installed dists.
177 177
178 :param dists: distributions to install 178 :param dists: distributions to install
179 :param path: base path to install distribution in 179 :param path: base path to install distribution in
180 :param paths: list of paths (defaults to sys.path) to look for info 180 :param paths: list of paths (defaults to sys.path) to look for info
181 """ 181 """
182 if not path:
183 path = tempfile.mkdtemp()
182 184
183 installed_dists = [] 185 installed_dists = []
184 for dist in dists: 186 for dist in dists:
185 logger.info('Installing %r %s...', dist.name, dist.version) 187 logger.info('Installing %r %s...', dist.name, dist.version)
186 try: 188 try:
187 _install_dist(dist, path) 189 _install_dist(dist, path)
188 installed_dists.append(dist) 190 installed_dists.append(dist)
189 except Exception as e: 191 except Exception as e:
190 logger.info('Failed: %s', e) 192 logger.info('Failed: %s', e)
191 193
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return True 531 return True
530 532
531 533
532 def _main(**attrs): 534 def _main(**attrs):
533 if 'script_args' not in attrs: 535 if 'script_args' not in attrs:
534 attrs['requirements'] = sys.argv[1] 536 attrs['requirements'] = sys.argv[1]
535 get_infos(**attrs) 537 get_infos(**attrs)
536 538
537 if __name__ == '__main__': 539 if __name__ == '__main__':
538 _main() 540 _main()
OLDNEW
« no previous file with comments | « Lib/packaging/database.py ('k') | Lib/packaging/tests/__main__.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+