mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
easier extensibility).
This commit is contained in:
		
							parent
							
								
									7b87c0e1bb
								
							
						
					
					
						commit
						f84fb660cb
					
				
					 1 changed files with 28 additions and 8 deletions
				
			
		|  | @ -46,31 +46,46 @@ def finalize_options (self): | ||||||
|     def run (self): |     def run (self): | ||||||
| 
 | 
 | ||||||
|         # Make sure we have built everything we need first |         # Make sure we have built everything we need first | ||||||
|  |         self.build() | ||||||
|  |          | ||||||
|  |         # Install everything: simply dump the entire contents of the build | ||||||
|  |         # directory to the installation directory (that's the beauty of | ||||||
|  |         # having a build directory!) | ||||||
|  |         outfiles = self.install() | ||||||
|  | 
 | ||||||
|  |         # (Optionally) compile .py to .pyc | ||||||
|  |         self.bytecompile(outfiles) | ||||||
|  | 
 | ||||||
|  |     # run () | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     # -- Top-level worker functions ------------------------------------ | ||||||
|  |     # (called from 'run()') | ||||||
|  | 
 | ||||||
|  |     def build (self): | ||||||
|         if not self.skip_build: |         if not self.skip_build: | ||||||
|             if self.distribution.has_pure_modules(): |             if self.distribution.has_pure_modules(): | ||||||
|                 self.run_command('build_py') |                 self.run_command('build_py') | ||||||
|             if self.distribution.has_ext_modules(): |             if self.distribution.has_ext_modules(): | ||||||
|                 self.run_command('build_ext') |                 self.run_command('build_ext') | ||||||
| 
 |          | ||||||
|         # Install everything: simply dump the entire contents of the build |     def install (self): | ||||||
|         # directory to the installation directory (that's the beauty of |  | ||||||
|         # having a build directory!) |  | ||||||
|         if os.path.isdir(self.build_dir): |         if os.path.isdir(self.build_dir): | ||||||
|             outfiles = self.copy_tree(self.build_dir, self.install_dir) |             outfiles = self.copy_tree(self.build_dir, self.install_dir) | ||||||
|         else: |         else: | ||||||
|             self.warn("'%s' does not exist -- no Python modules to install" % |             self.warn("'%s' does not exist -- no Python modules to install" % | ||||||
|                       self.build_dir) |                       self.build_dir) | ||||||
|             return |             return | ||||||
|  |         return outfiles | ||||||
| 
 | 
 | ||||||
|         # (Optionally) compile .py to .pyc |     def bytecompile (self, files): | ||||||
|         # XXX hey! we can't control whether we optimize or not; that's up |         # XXX hey! we can't control whether we optimize or not; that's up | ||||||
|         # to the invocation of the current Python interpreter (at least |         # to the invocation of the current Python interpreter (at least | ||||||
|         # according to the py_compile docs).  That sucks. |         # according to the py_compile docs).  That sucks. | ||||||
| 
 |  | ||||||
|         if self.compile: |         if self.compile: | ||||||
|             from py_compile import compile |             from py_compile import compile | ||||||
| 
 | 
 | ||||||
|             for f in outfiles: |             for f in files: | ||||||
|                 # only compile the file if it is actually a .py file |                 # only compile the file if it is actually a .py file | ||||||
|                 if f[-3:] == '.py': |                 if f[-3:] == '.py': | ||||||
|                     out_fn = f + (__debug__ and "c" or "o") |                     out_fn = f + (__debug__ and "c" or "o") | ||||||
|  | @ -79,9 +94,10 @@ def run (self): | ||||||
|                     skip_msg = "skipping byte-compilation of %s" % f |                     skip_msg = "skipping byte-compilation of %s" % f | ||||||
|                     self.make_file(f, out_fn, compile, (f,), |                     self.make_file(f, out_fn, compile, (f,), | ||||||
|                                    compile_msg, skip_msg) |                                    compile_msg, skip_msg) | ||||||
|     # run () |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |     # -- Utility methods ----------------------------------------------- | ||||||
|  | 
 | ||||||
|     def _mutate_outputs (self, has_any, build_cmd, cmd_option, output_dir): |     def _mutate_outputs (self, has_any, build_cmd, cmd_option, output_dir): | ||||||
| 
 | 
 | ||||||
|         if not has_any: |         if not has_any: | ||||||
|  | @ -108,6 +124,10 @@ def _bytecode_filenames (self, py_filenames): | ||||||
| 
 | 
 | ||||||
|         return bytecode_files |         return bytecode_files | ||||||
|          |          | ||||||
|  | 
 | ||||||
|  |     # -- External interface -------------------------------------------- | ||||||
|  |     # (called by outsiders) | ||||||
|  | 
 | ||||||
|     def get_outputs (self): |     def get_outputs (self): | ||||||
|         """Return the list of files that would be installed if this command |         """Return the list of files that would be installed if this command | ||||||
|         were actually run.  Not affected by the "dry-run" flag or whether |         were actually run.  Not affected by the "dry-run" flag or whether | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Greg Ward
						Greg Ward