Ronny Pfannschmidt avatar Ronny Pfannschmidt committed 69e00c6

add support for global distutils options

Comments (0)

Files changed (3)

pip/commands/install.py

             "Use multiple --install-option options to pass multiple options to setup.py install.  "
             "If you are using an option with a directory path, be sure to use absolute path.")
 
+        self.parser.add_option(
+            '--global-option',
+            dest='global_options',
+            action='append',
+            help="Extra global options to be supplied to the setup.py"
+            "call before the install command"
+        )
+
     def run(self, options, args):
         if not options.build_dir:
             options.build_dir = build_prefix
         options.build_dir = os.path.abspath(options.build_dir)
         options.src_dir = os.path.abspath(options.src_dir)
         install_options = options.install_options or []
+        global_options = options.global_options or []
         index_urls = [options.index_url] + options.extra_index_urls
         if options.no_index:
             logger.notify('Ignoring indexes: %s' % ','.join(index_urls))
         else:
             requirement_set.locate_files()
         if not options.no_install and not self.bundle:
-            requirement_set.install(install_options)
+            requirement_set.install(install_options, global_options)
             installed = ' '.join([req.name for req in
                                   requirement_set.successfully_installed])
             if installed:
         name = name.replace(os.path.sep, '/')
         return name
 
-    def install(self, install_options):
+    def install(self, install_options, global_options=()):
         if self.editable:
             self.install_editable()
             return
         record_filename = os.path.join(temp_location, 'install-record.txt')
         try:
 
-            install_args = [sys.executable, '-c',
-                            "import setuptools; __file__=%r; execfile(%r)" % (self.setup_py, self.setup_py),
-                            'install', '--single-version-externally-managed', '--record', record_filename]
+            install_args = [
+                sys.executable, '-c',
+                "import setuptools;__file__=%r;execfile(__file__)" % self.setup_py
+            ] + list(global_options) + [
+                'install',
+                '--single-version-externally-managed',
+                '--record', record_filename,
+            ]
 
             if in_venv():
                 ## FIXME: I'm not sure if this is a reasonable location; probably not
                     cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
             finally:
                 logger.indent -= 2
+            if not os.path.exists(record_filename):
+                logger.notify('Record file %s not found' % record_filename)
+                return
             self.install_succeeded = True
             f = open(record_filename)
             for line in f:
         finally:
             tar.close()
 
-    def install(self, install_options):
+    def install(self, install_options, global_options=()):
         """Install everything in this set (after having downloaded and unpacked the packages)"""
         to_install = sorted([r for r in self.requirements.values()
                              if self.upgrade or not r.satisfied_by],
                     finally:
                         logger.indent -= 2
                 try:
-                    requirement.install(install_options)
+                    requirement.install(install_options, global_options)
                 except:
                     # if install did not succeed, rollback previous uninstall
                     if requirement.conflicts_with and not requirement.install_succeeded:

tests/test_basic.py

     result = run_pip('install', pardir, cwd=run_from, expect_error=False)
     assert (lib_py + 'site-packages/fspkg') in result.files_created, str(result.stdout)
     assert (lib_py + 'site-packages/FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
+
+def test_install_global_option():
+    """
+    test using global distutils options.
+
+    in particular those that disable the actual install action\
+
+    """
+    reset_env()
+    result = run_pip('install', '--global-option=--version', "INITools==0.1")
+    assert '0.1\n' in result.stdout
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.