Skip to content

Commit ee40819

Browse files
voidusblueyed
authored andcommitted
Remove py dependency
py is in maintenance mode and there are modern alternatives.
1 parent be42484 commit ee40819

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

pytest_django/plugin.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import types
1313

14-
import py
14+
import pathlib
1515
import pytest
1616

1717
from .django_compat import is_django_unittest # noqa
@@ -87,13 +87,6 @@ def pytest_addoption(parser):
8787
type='bool', default=False)
8888

8989

90-
def _exists(path, ignore=EnvironmentError):
91-
try:
92-
return path.check()
93-
except ignore:
94-
return False
95-
96-
9790
PROJECT_FOUND = ('pytest-django found a Django project in %s '
9891
'(it contains manage.py) and added it to the Python path.\n'
9992
'If this is wrong, add "django_find_project = false" to '
@@ -120,21 +113,28 @@ def _handle_import_error(extra_message):
120113

121114

122115
def _add_django_project_to_path(args):
123-
args = [x for x in args if not str(x).startswith("-")]
124-
125-
if not args:
126-
args = [py.path.local()]
127-
128-
for arg in args:
129-
arg = py.path.local(arg)
130-
131-
for base in arg.parts(reverse=True):
132-
manage_py_try = base.join('manage.py')
133-
134-
if _exists(manage_py_try):
135-
sys.path.insert(0, str(base))
136-
return PROJECT_FOUND % base
116+
def is_django_project(path):
117+
return path.is_dir() and (path / 'manage.py').exists()
118+
119+
def find_django_path(args):
120+
args = [pathlib.Path(x) for x in args if not str(x).startswith("-")]
121+
args = [p for p in args if p.is_dir()]
122+
123+
if not args:
124+
args = [pathlib.Path.cwd()]
125+
126+
for arg in args:
127+
if is_django_project(arg):
128+
return arg
129+
for parent in arg.parents:
130+
if is_django_project(parent):
131+
return parent
132+
return None
137133

134+
project_dir = find_django_path(args)
135+
if project_dir:
136+
sys.path.insert(0, str(project_dir))
137+
return PROJECT_FOUND % project_dir
138138
return PROJECT_NOT_FOUND
139139

140140

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def read(fname):
3030
long_description=read('README.rst'),
3131
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
3232
setup_requires=['setuptools_scm>=1.11.1'],
33-
install_requires=['pytest>=3.6'],
33+
install_requires=[
34+
'pytest>=3.6',
35+
'pathlib;python_version<"3.4"',
36+
'six',
37+
],
3438
extras_require={
3539
'docs': [
3640
'sphinx',

tests/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import shutil
33
from textwrap import dedent
44

5-
import py
5+
import pathlib
66
import pytest
7+
import six
78
from django.conf import settings
89

910
from pytest_django_test.db_helpers import DB_NAME, TEST_DB_NAME
1011

1112
pytest_plugins = 'pytester'
1213

13-
REPOSITORY_ROOT = py.path.local(__file__).join('..')
14+
REPOSITORY_ROOT = pathlib.Path(__file__).parent
1415

1516

1617
def pytest_configure(config):
@@ -99,12 +100,12 @@ def django_testdir(request, testdir, monkeypatch):
99100

100101
tpkg_path.ensure('__init__.py')
101102

102-
app_source = REPOSITORY_ROOT.dirpath('pytest_django_test/app')
103+
app_source = REPOSITORY_ROOT / '../pytest_django_test/app'
103104
test_app_path = tpkg_path.join('app')
104105

105106
# Copy the test app to make it available in the new test run
106-
shutil.copytree(py.builtin._totext(app_source),
107-
py.builtin._totext(test_app_path))
107+
shutil.copytree(six.text_type(app_source),
108+
six.text_type(test_app_path))
108109
tpkg_path.join("the_settings.py").write(test_settings)
109110

110111
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.the_settings')

0 commit comments

Comments
 (0)