Commits

Jannis Leidel committed 8aae9b0 Merge

merge pull

Comments (0)

Files changed (2)

 
 * Fix some filename issues on Windows.
 
+* Allow the ``-i`` and ``--extra-index-url`` options in requirements
+  files.
+
+* Fix the way bundle components are unpacked and moved around, to make
+  bundles work.
+
 0.3.1
 -----
 
 if os.environ.get('PIP_DEFAULT_VCS'):
     default_vcs = os.environ['PIP_DEFAULT_VCS']
 
-
 try:
     pip_dist = pkg_resources.get_distribution('pip')
     version = '%s from %s (python %s)' % (
         find_links = options.find_links or []
         ## FIXME: Obviously this should be settable:
         find_tags = False
+        skip_match = None
+        if os.environ.get('PIP_SKIP_REQUIREMENTS_REGEX'):
+            skip_match = re.compile(os.environ['PIP_SKIP_REQUIREMENTS_REGEX'])
 
         if filename == '-':
             logger.move_stdout_to_stderr()
                 if not line.strip() or line.strip().startswith('#'):
                     f.write(line)
                     continue
+                if skip_match and skip_match.search(line):
+                    f.write(line)
+                    continue
                 elif line.startswith('-e') or line.startswith('--editable'):
                     if line.startswith('-e'):
                         line = line[2:].strip()
         return s
 
     def from_path(self):
+        if self.req is None:
+            return None
         s = str(self.req)
         if self.comes_from:
             if isinstance(self.comes_from, basestring):
                 comes_from = self.comes_from
             else:
                 comes_from = self.comes_from.from_path()
-            s += '->' + comes_from
+            if comes_from:
+                s += '->' + comes_from
         return s
 
     def build_location(self, build_dir):
         return self._is_bundle
 
     def bundle_requirements(self):
-        base = self._temp_build_dir
-        assert base
-        src_dir = os.path.join(base, 'src')
-        build_dir = os.path.join(base, 'build')
-        if os.path.exists(src_dir):
-            for package in os.listdir(src_dir):
-                ## FIXME: svnism:
-                for vcs_backend in vcs.backends:
-                    url = rev = None
-                    vcs_bundle_file = os.path.join(
-                        src_dir, package, vcs_backend.bundle_file)
-                    if os.path.exists(vcs_bundle_file):
-                        vc_type = vcs_backend.name
-                        fp = open(vcs_bundle_file)
-                        content = fp.read()
-                        fp.close()
-                        url, rev = vcs_backend().parse_vcs_bundle_file(content)
-                        break
-                if url:
-                    url = '%s+%s@%s' % (vc_type, url, rev)
-                else:
-                    url = None
-                yield InstallRequirement(
-                    package, self, editable=True, url=url,
-                    update=False, source_dir=os.path.join(src_dir, package))
-        if os.path.exists(build_dir):
-            for package in os.listdir(build_dir):
-                yield InstallRequirement(
-                    package, self,
-                    source_dir=os.path.join(build_dir, package))
+        for dest_dir in self._bundle_editable_dirs:
+            package = os.path.basename(dest_dir)
+            ## FIXME: svnism:
+            for vcs_backend in vcs.backends:
+                url = rev = None
+                vcs_bundle_file = os.path.join(
+                    dest_dir, vcs_backend.bundle_file)
+                if os.path.exists(vcs_bundle_file):
+                    vc_type = vcs_backend.name
+                    fp = open(vcs_bundle_file)
+                    content = fp.read()
+                    fp.close()
+                    url, rev = vcs_backend().parse_vcs_bundle_file(content)
+                    break
+            if url:
+                url = '%s+%s@%s' % (vc_type, url, rev)
+            else:
+                url = None
+            yield InstallRequirement(
+                package, self, editable=True, url=url,
+                update=False, source_dir=dest_dir)
+        for dest_dir in self._bundle_build_dirs:
+            package = os.path.basename(dest_dir)
+            yield InstallRequirement(
+                package, self, 
+                source_dir=dest_dir)
 
     def move_bundle_files(self, dest_build_dir, dest_src_dir):
         base = self._temp_build_dir
         assert base
         src_dir = os.path.join(base, 'src')
         build_dir = os.path.join(base, 'build')
-        for source_dir, dest_dir in [(src_dir, dest_src_dir),
-                                     (build_dir, dest_build_dir)]:
+        bundle_build_dirs = []
+        bundle_editable_dirs = []
+        for source_dir, dest_dir, dir_collection in [
+            (src_dir, dest_src_dir, bundle_editable_dirs),
+            (build_dir, dest_build_dir, bundle_build_dirs)]:
             if os.path.exists(source_dir):
                 for dirname in os.listdir(source_dir):
                     dest = os.path.join(dest_dir, dirname)
+                    dir_collection.append(dest)
                     if os.path.exists(dest):
                         logger.warn('The directory %s (containing package %s) already exists; cannot move source from bundle %s'
                                     % (dest, dirname, self))
                         logger.info('Creating directory %s' % dest_dir)
                         os.makedirs(dest_dir)
                     shutil.move(os.path.join(source_dir, dirname), dest)
+                if not os.listdir(source_dir):
+                    os.rmdir(source_dir)
+        self._temp_build_dir = None
+        self._bundle_build_dirs = bundle_build_dirs
+        self._bundle_editable_dirs = bundle_editable_dirs
 
     @property
     def delete_marker_filename(self):
                     if unpack:
                         is_bundle = req_to_install.is_bundle
                         if is_bundle:
+                            req_to_install.move_bundle_files(self.build_dir, self.src_dir)
                             for subreq in req_to_install.bundle_requirements():
                                 reqs.append(subreq)
                                 self.add_requirement(subreq)
-                            req_to_install.move_bundle_files(self.build_dir, self.src_dir)
                         else:
                             req_to_install.source_dir = location
                             req_to_install.run_egg_info()
             fp = open(target_file+'.content-type', 'w')
             fp.write(content_type)
             fp.close()
-        os.unlink(temp_location)
+            os.unlink(temp_location)
+        if target_file is None:
+            os.unlink(temp_location)
 
     def unpack_file(self, filename, location, content_type, link):
         if (content_type == 'application/zip'
                             % (display_path(dest), url))
                 logger.notify('Updating clone %s%s'
                               % (display_path(dest), rev_display))
-                call_subprocess(['hg', 'fetch', '-q'], cwd=dest)
+                call_subprocess(['hg', 'pull', '-q'], cwd=dest)
                 call_subprocess(
                     ['hg', 'update', '-q'] + rev_options, cwd=dest)
             else:
             ## FIXME: it would be nice to keep track of the source of
             ## the find_links:
             finder.find_links.append(line)
+        elif line.startswith('-i') or line.startswith('--index-url'):
+            if line.startswith('-i'):
+                line = line[2:].strip()
+            else:
+                line = line[len('--index-url'):].strip().lstrip('=')
+            finder.index_urls = [line]
+        elif line.startswith('--extra-index-url'):
+            line = line[len('--extra-index-url'):].strip().lstrip('=')
+            finder.index_urls.append(line)
         else:
             comes_from = '-r %s (line %s)' % (filename, line_number)
             if line.startswith('-e') or line.startswith('--editable'):