Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pipenv/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json as simplejson
import logging
import os
import re
import shutil
import sys
import tempfile
Expand All @@ -23,6 +24,7 @@
install_req_from_parsed_requirement,
)
from pipenv.patched.pip._internal.req.req_file import parse_requirements
from pipenv.patched.pip._internal.utils.misc import split_auth_from_netloc
from pipenv.project import Project
from pipenv.utils.constants import MYPY_RUNNING
from pipenv.utils.dependencies import (
Expand Down Expand Up @@ -198,9 +200,19 @@ def import_requirements(project, r=None, dev=False):
for package in reqs:
if package.name not in BAD_PACKAGES:
if package.link is not None:
package_string = (
f"-e {package.link}" if package.editable else str(package.link)
)
if package.editable:
package_string = f"-e {package.link}"
else:
netloc, (user, pw) = split_auth_from_netloc(package.link.netloc)
safe = True
if user and not re.match(r"\${[\W\w]+}", user):
safe = False
if pw and not re.match(r"\${[\W\w]+}", pw):
safe = False
if safe:
package_string = str(package.link._url)
else:
package_string = str(package.link)
project.add_package_to_pipfile(package_string, dev=dev)
else:
project.add_package_to_pipfile(str(package.req), dev=dev)
Expand Down
67 changes: 67 additions & 0 deletions tests/integration/test_import_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
from pathlib import Path
import tempfile

import pytest

from pipenv.core import import_requirements
from pipenv.project import Project


@pytest.mark.cli
@pytest.mark.deploy
@pytest.mark.system
def test_auth_with_pw_redacted(PipenvInstance):
with PipenvInstance(chdir=True) as p:
p.pipenv("run shell")
project = Project()
requirements_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
requirements_file.write("""git+https://${AUTH_USER}:mypw1@github.com/user/myproject.git#egg=myproject""")
requirements_file.close()
import_requirements(project, r=requirements_file.name)
os.unlink(requirements_file.name)
assert p.pipfile["packages"]["myproject"] == {'git': 'https://${AUTH_USER}:****@github.com/user/myproject.git'}


@pytest.mark.cli
@pytest.mark.deploy
@pytest.mark.system
def test_auth_with_username_redacted(PipenvInstance):
with PipenvInstance(chdir=True) as p:
p.pipenv("run shell")
project = Project()
requirements_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
requirements_file.write("""git+https://username@github.com/user/myproject.git#egg=myproject""")
requirements_file.close()
import_requirements(project, r=requirements_file.name)
os.unlink(requirements_file.name)
assert p.pipfile["packages"]["myproject"] == {'git': 'https://****@github.com/user/myproject.git'}


@pytest.mark.cli
@pytest.mark.deploy
@pytest.mark.system
def test_auth_with_pw_are_variables_passed_to_pipfile(PipenvInstance):
with PipenvInstance(chdir=True) as p:
p.pipenv("run shell")
project = Project()
requirements_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
requirements_file.write("""git+https://${AUTH_USER}:${AUTH_PW}@github.com/user/myproject.git#egg=myproject""")
requirements_file.close()
import_requirements(project, r=requirements_file.name)
os.unlink(requirements_file.name)
assert p.pipfile["packages"]["myproject"] == {'git': 'https://${AUTH_USER}:${AUTH_PW}@github.com/user/myproject.git'}

@pytest.mark.cli
@pytest.mark.deploy
@pytest.mark.system
def test_auth_with_only_username_variable_passed_to_pipfile(PipenvInstance):
with PipenvInstance(chdir=True) as p:
p.pipenv("run shell")
project = Project()
requirements_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
requirements_file.write("""git+https://${AUTH_USER}@github.com/user/myproject.git#egg=myproject""")
requirements_file.close()
import_requirements(project, r=requirements_file.name)
os.unlink(requirements_file.name)
assert p.pipfile["packages"]["myproject"] == {'git': 'https://${AUTH_USER}@github.com/user/myproject.git'}
8 changes: 6 additions & 2 deletions tests/integration/test_install_twists.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def test_normalize_name_install(PipenvInstance):
@pytest.mark.files
@pytest.mark.local
@pytest.mark.resolver
@pytest.mark.skip # extracting this package where it does mamy be causing the pip_to_deps failures
def test_local_package(PipenvInstance, pip_src_dir, testsroot):
"""This test ensures that local packages (directories with a setup.py)
installed in editable mode have their dependencies resolved as well"""
Expand Down Expand Up @@ -234,13 +235,15 @@ def test_local_package(PipenvInstance, pip_src_dir, testsroot):
def test_local_zipfiles(PipenvInstance, testsroot):
file_name = "requests-2.19.1.tar.gz"
# Not sure where travis/appveyor run tests from
source_path = os.path.abspath(os.path.join(testsroot, "test_artifacts", file_name))
source_path = os.path.join(testsroot, "test_artifacts", file_name)

with PipenvInstance(chdir=True) as p:
# This tests for a bug when installing a zipfile in the current dir
shutil.copy(source_path, os.path.join(p.path, file_name))
destination = os.path.join(p.path, file_name)
shutil.copy(source_path, destination)

c = p.pipenv(f"install {file_name}")
os.unlink(destination)
assert c.returncode == 0
key = [k for k in p.pipfile["packages"].keys()][0]
dep = p.pipfile["packages"][key]
Expand Down Expand Up @@ -268,6 +271,7 @@ def test_relative_paths(PipenvInstance, testsroot):
shutil.copy(source_path, os.path.join(artifact_path, file_name))
# Test installing a relative path in a subdirectory
c = p.pipenv(f"install {artifact_dir}/{file_name}")
os.unlink(f"{artifact_dir}/{file_name}")
assert c.returncode == 0
key = next(k for k in p.pipfile["packages"].keys())
dep = p.pipfile["packages"][key]
Expand Down