mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
import sources from requirements files
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user