Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of markers in VCS requirements #3253

Merged
merged 6 commits into from
Nov 19, 2018
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
1 change: 1 addition & 0 deletions .azure-pipelines/jobs/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ steps:
export GIT_SSL_CAINFO="$(python -m certifi)"
export LANG="C.UTF-8"
export PIP_PROCESS_DEPENDENCY_LINKS="1"
git submodule sync && git submodule update --init --recursive
pipenv run pytest --junitxml=test-results.xml
displayName: Run integration tests

Expand Down
2 changes: 2 additions & 0 deletions .azure-pipelines/steps/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ steps:
$env:TEMP='T:\'
Write-Host "##vso[task.setvariable variable=TMP]T:\"
$env:TMP='T:\'
git submodule sync
git submodule update --init --recursive
D:\.venv\Scripts\pipenv run pytest -ra --ignore=pipenv\patched --ignore=pipenv\vendor --junitxml=test-results.xml tests
displayName: Run integration tests

Expand Down
15 changes: 15 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[submodule "tests/test_artifacts/git/six-1.9.0"]
path = tests/test_artifacts/git/six-1.9.0
url = https://github.com/benjaminp/six.git
[submodule "tests/test_artifacts/git/pinax"]
path = tests/test_artifacts/git/pinax
url = https://github.com/pinax/pinax.git
[submodule "tests/test_artifacts/git/requests"]
path = tests/test_artifacts/git/requests
url = https://github.com/requests/requests.git
[submodule "tests/test_artifacts/git/six"]
path = tests/test_artifacts/git/six
url = https://github.com/benjaminp/six.git
[submodule "tests/test_artifacts/git/dateutil"]
path = tests/test_artifacts/git/dateutil
url = https://github.com/dateutil/dateutil
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include pipenv/vendor/pipreqs/stdlib pipenv/vendor/pipreqs/mapping
include pipenv/vendor/*.txt pipenv/vendor/pexpect/bashrc.sh
include pipenv/vendor/Makefile
include pipenv/pipenv.1
exclude .gitmodules
exclude .editorconfig .travis.yml .env appveyor.yml tox.ini pytest.ini
exclude Pipfile* CHANGELOG.draft.rst
exclude docker-compose.yml Dockerfile
Expand Down
1 change: 1 addition & 0 deletions news/3249.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding normal pep 508 compatible markers is now fully functional when using VCS dependencies.
1 change: 0 additions & 1 deletion pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ def uninstall(
if retcode:
sys.exit(retcode)


@cli.command(short_help="Generates Pipfile.lock.")
@lock_options
@pass_state
Expand Down
6 changes: 5 additions & 1 deletion pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,11 @@ def pip_install(
ignore_hashes = True
else:
ignore_hashes = True if not requirement.hashes else False
install_reqs = [escape_cmd(r) for r in requirement.as_line(as_list=True)]
install_reqs = requirement.as_line(as_list=True)
if not requirement.markers:
install_reqs = [escape_cmd(r) for r in install_reqs]
elif len(install_reqs) > 1:
install_reqs = install_reqs[0] + [escape_cmd(r) for r in install_reqs[1:]]
pip_command = [which_pip(allow_global=allow_global), "install"]
if pre:
pip_command.append("--pre")
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
addopts = -ra -n auto
testpaths = tests
; Add vendor and patched in addition to the default list of ignored dirs
norecursedirs = .* build dist CVS _darcs {arch} *.egg vendor patched news tasks docs
norecursedirs = .* build dist CVS _darcs {arch} *.egg vendor patched news tasks docs tests/test_artifacts
filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
14 changes: 7 additions & 7 deletions run-tests.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rem imdisk -a -s 964515b -m R: -p "/FS:NTFS /Y"
virtualenv R:\.venv
R:\.venv\Scripts\pip install -e . --upgrade --upgrade-strategy=only-if-needed
R:\.venv\Scripts\pipenv install --dev
SET RAM_DISK=R: && R:\.venv\Scripts\pipenv run pytest -n auto -v tests --tap-stream > report.tap
rem imdisk -a -s 964515b -m R: -p "/FS:NTFS /Y"

virtualenv R:\.venv
R:\.venv\Scripts\pip install -e . --upgrade --upgrade-strategy=only-if-needed
R:\.venv\Scripts\pipenv install --dev
git submodule sync && git submodule update --init --recursive
SET RAM_DISK=R: && R:\.venv\Scripts\pipenv run pytest -n auto -v tests --tap-stream > report.tap
3 changes: 3 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ PIPENV_PYTHON=2.7 python3 -m pipenv --venv && pipenv --rm && pipenv install --de
PIPENV_PYTHON=3.7 python3 -m pipenv --venv && pipenv --rm && pipenv install --dev
PIPENV_PYTHON=2.7 python3 -m pipenv run pip install --upgrade -e .
PIPENV_PYTHON=3.7 python3 -m pipenv run pip install --upgrade -e .
echo "$ git submodule sync && git submodule update --init --recursive"

git submodule sync && git submodule update --init --recursive

echo "$ pipenv run time pytest -v -n auto tests -m \"$TEST_SUITE\""
# PIPENV_PYTHON=2.7 pipenv run time pytest -v -n auto tests -m "$TEST_SUITE" | prefix 2.7 &
Expand Down
Empty file added tests/conftest.py
Empty file.
44 changes: 42 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pipenv.vendor import delegator
from pipenv.vendor import requests
from pipenv.vendor import toml
from pipenv.vendor import tomlkit
from pytest_pypi.app import prepare_packages as prepare_pypi_packages
from vistir.compat import ResourceWarning, fs_str
from vistir.path import mkdir_p
Expand Down Expand Up @@ -124,6 +125,44 @@ def isolate(pathlib_tmpdir):
WE_HAVE_GITHUB_SSH_KEYS = check_github_ssh()


class _Pipfile(object):
def __init__(self, path):
self.path = path
self.document = tomlkit.document()
self.document["sources"] = tomlkit.aot()
self.document["requires"] = tomlkit.table()
self.document["packages"] = tomlkit.table()
self.document["dev_packages"] = tomlkit.table()

def install(self, package, value, dev=False):
section = "packages" if not dev else "dev_packages"
if isinstance(value, dict):
table = tomlkit.inline_table()
table.update(value)
self.document[section][package] = table
else:
self.document[section][package] = value
self.write()

def loads(self):
self.document = tomlkit.loads(self.path.read_text())

def dumps(self):
source_table = tomlkit.table()
source_table["url"] = os.environ.get("PIPENV_TEST_INDEX")
source_table["verify_ssl"] = False
source_table["name"] = "pipenv_test_index"
self.document["sources"].append(source_table)
return tomlkit.dumps(self.document)

def write(self):
self.path.write_text(self.dumps())

@classmethod
def get_fixture_path(cls, path):
return Path(__file__).absolute().parent.parent / "test_artifacts" / path


class _PipenvInstance(object):
"""An instance of a Pipenv Project..."""
def __init__(self, pypi=None, pipfile=True, chdir=False, path=None, home_dir=None):
Expand All @@ -134,7 +173,7 @@ def __init__(self, pypi=None, pipfile=True, chdir=False, path=None, home_dir=Non
os.environ["CI"] = fs_str("1")
warnings.simplefilter("ignore", category=ResourceWarning)
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
path = os.environ.get("PIPENV_PROJECT_DIR", None)
path = path if path else os.environ.get("PIPENV_PROJECT_DIR", None)
if not path:
self._path = TemporaryDirectory(suffix='-project', prefix='pipenv-')
path = Path(self._path.name)
Expand All @@ -143,7 +182,7 @@ def __init__(self, pypi=None, pipfile=True, chdir=False, path=None, home_dir=Non
except OSError:
self.path = str(path.absolute())
else:
self._path = None
self._path = path
self.path = path
# set file creation perms
self.pipfile_path = None
Expand All @@ -159,6 +198,7 @@ def __init__(self, pypi=None, pipfile=True, chdir=False, path=None, home_dir=Non

self.chdir = False or chdir
self.pipfile_path = p_path
self._pipfile = _Pipfile(Path(p_path))

def __enter__(self):
os.environ['PIPENV_DONT_USE_PYENV'] = fs_str('1')
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/test_install_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,17 @@ def test_vcs_entry_supersedes_non_vcs(PipenvInstance, pip_src_dir):
p.lockfile["default"]["pyinstaller"]["git"]
== "https://github.com/pyinstaller/pyinstaller.git"
)


@pytest.mark.vcs
@pytest.mark.install
@pytest.mark.needs_internet
def test_vcs_can_use_markers(PipenvInstance, pip_src_dir, pypi):
with PipenvInstance(chdir=True, pypi=pypi) as p:
path = p._pipfile.get_fixture_path("git/six/.git")
p._pipfile.install("six", {"git": "{0}".format(path.as_uri()), "markers": "sys_platform == 'linux'"})
assert "six" in p.pipfile["packages"]
c = p.pipenv("install")
assert c.return_code == 0
assert "six" in p.lockfile["default"]
assert "git" in p.lockfile["default"]["six"]
1 change: 1 addition & 0 deletions tests/test_artifacts/git/dateutil
Submodule dateutil added at 6618de
1 change: 1 addition & 0 deletions tests/test_artifacts/git/pinax
Submodule pinax added at 147d85
1 change: 1 addition & 0 deletions tests/test_artifacts/git/requests
Submodule requests added at 57d728
1 change: 1 addition & 0 deletions tests/test_artifacts/git/six
Submodule six added at e114ef
1 change: 1 addition & 0 deletions tests/test_artifacts/git/six-1.9.0
Submodule six-1.9.0 added at 5efb52