Skip to content

Commit

Permalink
Merge pull request #2454 from pypa/bugfix/2438
Browse files Browse the repository at this point in the history
Switch to using pathlib2 for python<3.5
  • Loading branch information
techalchemy authored Jun 28, 2018
2 parents ac7f1ae + 7294c58 commit f0c8b46
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 47 deletions.
1 change: 1 addition & 0 deletions news/2454.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pipenv will now always use ``pathlib2`` for ``Path`` based filesystem interactions by default on ``python<3.5``.
11 changes: 7 additions & 4 deletions pipenv/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ def _infer_return_type(*args):
_types.add(type(arg))
return _types.pop()

try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
if sys.version_info[:2] >= (3, 5):
try:
from pathlib import Path
except ImportError:
from .vendor.pathlib2 import Path
else:
from .vendor.pathlib2 import Path


try:
Expand Down
5 changes: 1 addition & 4 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import toml
import json as simplejson

try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
from ._compat import Path

from .cmdparse import Script
from .vendor.requirementslib import Requirement
Expand Down
13 changes: 4 additions & 9 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from click import echo as click_echo
from first import first

try:
from weakref import finalize
except ImportError:
Expand All @@ -36,13 +35,7 @@ def detach(self):
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
try:
from pathlib import Path
except ImportError:
try:
from .vendor.pathlib2 import Path
except ImportError:
pass

from distutils.spawn import find_executable
from contextlib import contextmanager
from .pep508checker import lookup
Expand Down Expand Up @@ -609,6 +602,7 @@ def is_installable_file(path):
from .patched.notpip._internal.utils.misc import is_installable_dir
from .patched.notpip._internal.utils.packaging import specifiers
from .patched.notpip._internal.download import is_archive_file
from ._compat import Path

if hasattr(path, 'keys') and any(
key for key in path.keys() if key in ['file', 'path']
Expand Down Expand Up @@ -853,6 +847,7 @@ def find_windows_executable(bin_path, exe_name):


def path_to_url(path):
from ._compat import Path
return Path(normalize_drive(os.path.abspath(path))).as_uri()


Expand Down Expand Up @@ -1158,7 +1153,7 @@ def get_vcs_deps(
pypi_mirror=None,
):
from .patched.notpip._internal.vcs import VcsSupport
from ._compat import TemporaryDirectory
from ._compat import TemporaryDirectory, Path

section = "vcs_dev_packages" if dev else "vcs_packages"
reqs = []
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

import pytest

from pipenv._compat import TemporaryDirectory
from pipenv._compat import TemporaryDirectory, Path
from pipenv.vendor import delegator
from pipenv.vendor import requests
from pipenv.vendor import six
from pipenv.vendor import toml

try:
from pathlib import Path
except ImportError:
from pipenv.vendor.pathlib2 import Path


if six.PY2:
class ResourceWarning(Warning):
pass
Expand Down
6 changes: 1 addition & 5 deletions tests/integration/test_install_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
import os

from pipenv.utils import temp_environ
from pipenv._compat import TemporaryDirectory
from pipenv._compat import TemporaryDirectory, Path
from pipenv.vendor import delegator
from pipenv.project import Project
try:
from pathlib import Path
except ImportError:
from pipenv.vendor.pathlib2 import Path

import pytest

Expand Down
7 changes: 2 additions & 5 deletions tests/integration/test_install_twists.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import os
import shutil
from pipenv.project import Project
try:
import pathlib
except ImportError:
import pathlib2 as pathlib
from pipenv._compat import Path

from pipenv.utils import mkdir_p, temp_environ

Expand Down Expand Up @@ -223,7 +220,7 @@ def test_relative_paths(PipenvInstance, pypi, testsroot):
dep = p.pipfile['packages'][key]

assert 'path' in dep
assert pathlib.Path('.', artifact_dir, file_name) == pathlib.Path(dep['path'])
assert Path('.', artifact_dir, file_name) == Path(dep['path'])
assert c.return_code == 0


Expand Down
5 changes: 1 addition & 4 deletions tests/integration/test_install_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import os
from flaky import flaky
import delegator
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
from pipenv._compat import Path


@pytest.mark.vcs
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/test_pipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
from pipenv.core import activate_virtualenv
from pipenv.project import Project
from pipenv.vendor import delegator

try:
from pathlib import Path
except ImportError:
from pipenv.vendor.pathlib2 import Path
from pipenv._compat import Path


@pytest.mark.code
Expand Down Expand Up @@ -123,4 +119,4 @@ def mocked_mkdtemp(suffix, prefix, dir):
assert os.path.isdir(venv_path)
# Manually clean up environment, since PipenvInstance assumes that
# the virutalenv is in the project directory.
p.pipenv('--rm')
p.pipenv('--rm')
6 changes: 3 additions & 3 deletions tests/integration/test_windows.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from pipenv.project import Project
from pipenv.vendor import pathlib2 as pathlib
from pipenv._compat import Path

import pytest

Expand Down Expand Up @@ -33,7 +33,7 @@ def test_case_changes_windows(PipenvInstance, pypi):
@pytest.mark.files
def test_local_path_windows(PipenvInstance, pypi):
whl = (
pathlib.Path(__file__).parent.parent
Path(__file__).parent.parent
.joinpath('pypi', 'six', 'six-1.11.0-py2.py3-none-any.whl')
)
try:
Expand All @@ -48,7 +48,7 @@ def test_local_path_windows(PipenvInstance, pypi):
@pytest.mark.files
def test_local_path_windows_forward_slash(PipenvInstance, pypi):
whl = (
pathlib.Path(__file__).parent.parent
Path(__file__).parent.parent
.joinpath('pypi', 'six', 'six-1.11.0-py2.py3-none-any.whl')
)
try:
Expand Down

0 comments on commit f0c8b46

Please sign in to comment.