diff --git a/HISTORY.txt b/HISTORY.txt index 062fa3c5..85fc2b22 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -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: diff --git a/pipenv/cli.py b/pipenv/cli.py index 264a8077..c0ff67da 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -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() diff --git a/pipenv/project.py b/pipenv/project.py index 8e204a7a..b20c5809 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -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))