From 0d7cd642184f9c5df5cf7dd9df8ba01d9a3895d4 Mon Sep 17 00:00:00 2001 From: heinzel Date: Fri, 25 Sep 2020 12:43:40 +0200 Subject: [PATCH] Drop Python2 and Django1 support --- .pylintrc | 8 +++---- README.rst | 2 +- setup.py | 11 +++------- src/django_deploy/api.py | 10 ++++----- src/django_deploy/exceptions.py | 2 +- src/django_deploy/hooks.py | 4 ++-- src/django_deploy/tests/generic.py | 28 ++++++------------------- src/django_deploy/tests/test_api.py | 6 +----- src/django_deploy/tests/test_hooks.py | 6 +++--- src/django_deploy/tests/test_program.py | 6 +----- src/django_deploy/version.py | 2 +- tox.ini | 4 +--- 12 files changed, 29 insertions(+), 60 deletions(-) diff --git a/.pylintrc b/.pylintrc index b70bbbb..d3fcc22 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,10 +7,10 @@ load-plugins=pylint_django [MESSAGES CONTROL] disable=missing-docstring, - missing-module-docstring, - missing-class-docstring, - missing-function-docstring, - useless-object-inheritance, + missing-module-docstring, + missing-class-docstring, + missing-function-docstring, + useless-object-inheritance, [BASIC] diff --git a/README.rst b/README.rst index c1a5d2d..0dd70da 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ into a django project. REQUIREMENTS ============ -- python >= 2.7 +- python >= 3 - Django (will be pulled in by pip, if you haven't installed it already. Probably this is why you are interested in this project) diff --git a/setup.py b/setup.py index 14ddd0f..fe2d4d1 100644 --- a/setup.py +++ b/setup.py @@ -30,12 +30,7 @@ class CreatePythonEnvironment(MyCommand): def run(): python_bin = sys.executable if sys.executable else 'python' python_ver = sys.version_info.major - if python_ver == 2: - path = os.path.join('env', 'python2') - symlink_path = os.path.join('env', 'python') - venv_module = 'virtualenv' - prompt = '(py2) ' - elif python_ver == 3: + if python_ver == 3: path = os.path.join('env', 'python3') symlink_path = os.path.join('env', 'python') venv_module = 'venv' @@ -67,7 +62,7 @@ class CreatePythonEnvironment(MyCommand): setup( name='django-deploy', - version='0.2.dev0', + version='0.3.dev0', description='A helper to deploy reusable django apps into a django project.', long_description=long_description(), long_description_content_type='text/x-rst', @@ -95,7 +90,7 @@ setup( 'django-deploy.py = django_deploy:main', ], }, - python_requires='>=2.7', + python_requires='>=3', install_requires=[ 'django', ], diff --git a/src/django_deploy/api.py b/src/django_deploy/api.py index 19563ab..f8cb916 100644 --- a/src/django_deploy/api.py +++ b/src/django_deploy/api.py @@ -42,7 +42,7 @@ class DjangoProjectHooksConfig(OrderedDict): 'Keyword arguments project_dir and settings_dir' \ ' are mutually exclusive.' - super(DjangoProjectHooksConfig, self).__init__() + super().__init__() if project_dir is not None: settings_dir = os.path.join(project_dir, DJANGO_SETTINGS_DIR) @@ -68,7 +68,7 @@ class DjangoProject(object): try: app_obj = importlib.import_module(module_path) except ImportError as e: - raise DjangoDeployError(e, code=errno.ENOPKG) + raise DjangoDeployError(e, code=errno.ENOPKG) from e try: hooks_config = getattr(app_obj, hooks_config_name) @@ -76,7 +76,7 @@ class DjangoProject(object): try: hooks_config = importlib.import_module('{}.{}'.format(module_path, hooks_config_name)) except ImportError as e: - raise DjangoDeployError('In {}: {}'.format(module_path, e), code=errno.ENOENT) + raise DjangoDeployError('In {}: {}'.format(module_path, e), code=errno.ENOENT) from e return hooks_config @@ -215,13 +215,13 @@ class DjangoProject(object): try: subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - raise DjangoDeployError(e.output.decode('utf8'), exitval=e.returncode) + raise DjangoDeployError(e.output.decode('utf8'), exitval=e.returncode) from e else: cmd = [management_script, 'migrate'] try: subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: # pragma: no cover - raise DjangoDeployError(e.output.decode('utf8'), exitval=e.returncode) + raise DjangoDeployError(e.output.decode('utf8'), exitval=e.returncode) from e def __init__(self, project_dir): self._project_dir = project_dir diff --git a/src/django_deploy/exceptions.py b/src/django_deploy/exceptions.py index 20ed203..65b5fe8 100644 --- a/src/django_deploy/exceptions.py +++ b/src/django_deploy/exceptions.py @@ -3,7 +3,7 @@ class DjangoDeployError(Exception): self._message = message self._code = code self._exitval = exitval - super(DjangoDeployError, self).__init__(message) + super().__init__(message) @property def message(self): diff --git a/src/django_deploy/hooks.py b/src/django_deploy/hooks.py index 0896ad2..b39d96c 100644 --- a/src/django_deploy/hooks.py +++ b/src/django_deploy/hooks.py @@ -1,5 +1,5 @@ import os -from django.conf.urls import url, include +from django.urls import re_path, include from .api import DjangoProjectHooksConfig @@ -27,6 +27,6 @@ def get_urlpatterns(file_path, urlpatterns): pattern = '^' else: pattern = '^{}'.format(route) - url_obj = url(pattern, include(urlconf_module)) + url_obj = re_path(pattern, include(urlconf_module)) urls_list.append(url_obj) return urls_list diff --git a/src/django_deploy/tests/generic.py b/src/django_deploy/tests/generic.py index ab412ee..2072c77 100644 --- a/src/django_deploy/tests/generic.py +++ b/src/django_deploy/tests/generic.py @@ -18,10 +18,7 @@ class DjangoDeployTestCase(unittest.TestCase): def _import_from_dir(module_name, directory): sys.path.insert(0, directory) module = importlib.import_module(module_name) - if sys.version_info.major == 2: # pragma: no cover - reload(module) # pylint: disable=undefined-variable - else: # pragma: no cover - importlib.reload(module) # pylint: disable=no-member + importlib.reload(module) sys.path.pop(0) return module @@ -136,15 +133,9 @@ class DjangoDeployTestCase(unittest.TestCase): def assert_urlpatterns(self, project_dir, patterns): root_urlconf = self.get_django_root_urlconf(project_dir) - # Django 2 vs Django 1 - if hasattr(root_urlconf, 'path'): # pragma: no cover - expected_urlpatterns = [ - ('URLPattern', 'admin/', 'django.contrib.admin.site.urls'), - ] - else: # pragma: no cover - expected_urlpatterns = [ - ('URLPattern', '^admin/', 'django.contrib.admin.site.urls'), - ] + expected_urlpatterns = [ + ('URLPattern', 'admin/', 'django.contrib.admin.site.urls'), + ] expected_urlpatterns += patterns real_urlpatterns = root_urlconf.urlpatterns @@ -154,19 +145,12 @@ class DjangoDeployTestCase(unittest.TestCase): real = real_urlpatterns[i] real_class_name = real.__class__.__name__ self.assertTrue(real_class_name.endswith(expected[0])) - # Django 2 vs. Django 1 - if real_class_name == 'URLPattern': # pragma: no cover + if real_class_name == 'URLPattern': self.assertEqual(expected[1], str(real.pattern)) self.assertTrue(real.callback.startswith("