Skip to content

Commit

Permalink
Remove py dependency
Browse files Browse the repository at this point in the history
py is in maintenance mode and there are modern alternatives.
  • Loading branch information
voidus authored and blueyed committed Jul 26, 2018
1 parent be42484 commit ee40819
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
44 changes: 22 additions & 22 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import types

import py
import pathlib
import pytest

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


def _exists(path, ignore=EnvironmentError):
try:
return path.check()
except ignore:
return False


PROJECT_FOUND = ('pytest-django found a Django project in %s '
'(it contains manage.py) and added it to the Python path.\n'
'If this is wrong, add "django_find_project = false" to '
Expand All @@ -120,21 +113,28 @@ def _handle_import_error(extra_message):


def _add_django_project_to_path(args):
args = [x for x in args if not str(x).startswith("-")]

if not args:
args = [py.path.local()]

for arg in args:
arg = py.path.local(arg)

for base in arg.parts(reverse=True):
manage_py_try = base.join('manage.py')

if _exists(manage_py_try):
sys.path.insert(0, str(base))
return PROJECT_FOUND % base
def is_django_project(path):
return path.is_dir() and (path / 'manage.py').exists()

def find_django_path(args):
args = [pathlib.Path(x) for x in args if not str(x).startswith("-")]
args = [p for p in args if p.is_dir()]

if not args:
args = [pathlib.Path.cwd()]

for arg in args:
if is_django_project(arg):
return arg
for parent in arg.parents:
if is_django_project(parent):
return parent
return None

project_dir = find_django_path(args)
if project_dir:
sys.path.insert(0, str(project_dir))
return PROJECT_FOUND % project_dir
return PROJECT_NOT_FOUND


Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def read(fname):
long_description=read('README.rst'),
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
setup_requires=['setuptools_scm>=1.11.1'],
install_requires=['pytest>=3.6'],
install_requires=[
'pytest>=3.6',
'pathlib;python_version<"3.4"',
'six',
],
extras_require={
'docs': [
'sphinx',
Expand Down
11 changes: 6 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import shutil
from textwrap import dedent

import py
import pathlib
import pytest
import six
from django.conf import settings

from pytest_django_test.db_helpers import DB_NAME, TEST_DB_NAME

pytest_plugins = 'pytester'

REPOSITORY_ROOT = py.path.local(__file__).join('..')
REPOSITORY_ROOT = pathlib.Path(__file__).parent


def pytest_configure(config):
Expand Down Expand Up @@ -99,12 +100,12 @@ def django_testdir(request, testdir, monkeypatch):

tpkg_path.ensure('__init__.py')

app_source = REPOSITORY_ROOT.dirpath('pytest_django_test/app')
app_source = REPOSITORY_ROOT / '../pytest_django_test/app'
test_app_path = tpkg_path.join('app')

# Copy the test app to make it available in the new test run
shutil.copytree(py.builtin._totext(app_source),
py.builtin._totext(test_app_path))
shutil.copytree(six.text_type(app_source),
six.text_type(test_app_path))
tpkg_path.join("the_settings.py").write(test_settings)

monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.the_settings')
Expand Down

0 comments on commit ee40819

Please sign in to comment.