import sources from requirements files

Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
2017-09-21 12:45:44 -04:00
parent 4638701c59
commit 0b66968c02
3 changed files with 31 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@
- make `graph --json` consistient with `graph`.
- Much better support for suggesting package names.
- Updated to pipfile spec 4, support for path= for relative package names.
- Import sources from requirements files.
7.4.3:
- Download/install things concurrently.
7.4.2:
+12
View File
@@ -224,6 +224,15 @@ def import_requirements(r=None):
if r is None:
r = project.requirements_location
with open(r, 'r') as f:
contents = f.read()
indexes = []
# Find and add extra indexes.
for line in contents.split('\n'):
if line.startswith('-i '):
indexes.append(line.split()[1])
reqs = [f for f in parse_requirements(r, session=pip._vendor.requests)]
for package in reqs:
@@ -238,6 +247,9 @@ def import_requirements(r=None):
else:
project.add_package_to_pipfile(str(package.req))
for index in indexes:
project.add_index_to_pipfile(index)
project.recase_pipfile()
+18
View File
@@ -416,5 +416,23 @@ class Project(object):
# Write Pipfile.
self.write_toml(p)
def add_index_to_pipfile(self, index):
"""Adds a given index to the Pipfile."""
# Read and append Pipfile.
p = self._pipfile
source = {'url': index, 'verify_ssl': True}
# Add the package to the group.
if 'source' not in p:
p['source'] = [source]
else:
p['source'].append(source)
# Write Pipfile.
self.write_toml(p)
def recase_pipfile(self):
self.write_toml(recase_file(self._pipfile))