Permalink
Browse files

Refs #23919 -- Removed django.utils._os.upath()/npath()/abspathu() us…

…age.

These functions do nothing on Python 3.
  • Loading branch information...
timgraham committed Jan 20, 2017
1 parent ec4c1d6 commit 4e729feaa647547f25debb1cb63dec989dc41a20
Showing with 108 additions and 178 deletions.
  1. +1 −2 django/apps/config.py
  2. +1 −2 django/contrib/auth/password_validation.py
  3. +2 −2 django/core/files/storage.py
  4. +2 −3 django/core/management/__init__.py
  5. +3 −4 django/core/management/commands/compilemessages.py
  6. +1 −2 django/core/management/commands/loaddata.py
  7. +1 −2 django/core/management/commands/makemessages.py
  8. +2 −3 django/db/migrations/writer.py
  9. +2 −3 django/db/utils.py
  10. +1 −2 django/forms/renderers.py
  11. +1 −2 django/template/utils.py
  12. +5 −6 django/utils/_os.py
  13. +1 −2 django/utils/autoreload.py
  14. +2 −3 django/utils/translation/trans_real.py
  15. +5 −6 tests/admin_scripts/tests.py
  16. +1 −2 tests/admin_scripts/urls.py
  17. +2 −3 tests/admin_views/tests.py
  18. +1 −2 tests/app_loading/tests.py
  19. +1 −2 tests/apps/namespace_package_base/nsapp/apps.py
  20. +3 −4 tests/apps/tests.py
  21. +1 −3 tests/auth_tests/settings.py
  22. +1 −2 tests/auth_tests/test_validators.py
  23. +1 −2 tests/file_storage/tests.py
  24. +5 −6 tests/files/tests.py
  25. +2 −3 tests/fixtures_regress/tests.py
  26. +5 −10 tests/forms_tests/field_tests/test_filepathfield.py
  27. +1 −2 tests/forms_tests/field_tests/test_imagefield.py
  28. +2 −3 tests/forms_tests/tests/test_renderers.py
  29. +3 −5 tests/gis_tests/gdal_tests/test_raster.py
  30. +1 −2 tests/gis_tests/geo3d/tests.py
  31. +1 −2 tests/gis_tests/geogapp/tests.py
  32. +1 −2 tests/gis_tests/layermap/tests.py
  33. +1 −2 tests/gis_tests/test_data.py
  34. +2 −3 tests/httpwrappers/tests.py
  35. +1 −2 tests/i18n/contenttypes/tests.py
  36. +2 −3 tests/i18n/patterns/tests.py
  37. +1 −2 tests/i18n/test_percents.py
  38. +1 −2 tests/i18n/tests.py
  39. +1 −3 tests/i18n/utils.py
  40. +1 −2 tests/mail/tests.py
  41. +1 −2 tests/migrations/test_writer.py
  42. +2 −3 tests/model_fields/test_imagefield.py
  43. +1 −2 tests/model_forms/models.py
  44. +3 −4 tests/model_forms/tests.py
  45. +1 −2 tests/project_template/test_settings.py
  46. +1 −2 tests/proxy_model_inheritance/tests.py
  47. +2 −3 tests/runtests.py
  48. +1 −2 tests/servers/tests.py
  49. +2 −3 tests/sitemaps_tests/test_http.py
  50. +1 −3 tests/staticfiles_tests/settings.py
  51. +1 −2 tests/staticfiles_tests/test_liveserver.py
  52. +1 −2 tests/template_tests/syntax_tests/i18n/base.py
  53. +1 −2 tests/template_tests/utils.py
  54. +1 −2 tests/test_client_regress/tests.py
  55. +2 −2 tests/test_utils/tests.py
  56. +1 −2 tests/urlpatterns_reverse/test_localeregexprovider.py
  57. +1 −2 tests/user_commands/tests.py
  58. +1 −2 tests/utils_tests/test_archive.py
  59. +7 −8 tests/utils_tests/test_autoreload.py
  60. +1 −2 tests/utils_tests/test_html.py
  61. +1 −2 tests/utils_tests/test_module_loading.py
  62. +1 −2 tests/validators/tests.py
  63. +1 −2 tests/view_tests/tests/test_i18n.py
  64. +1 −2 tests/view_tests/urls.py
View
@@ -2,7 +2,6 @@
from importlib import import_module
from django.core.exceptions import ImproperlyConfigured
-from django.utils._os import upath
from django.utils.module_loading import module_has_submodule
MODELS_MODULE_NAME = 'models'
@@ -80,7 +79,7 @@ def _path_from_module(self, module):
"The app module %r has no filesystem location, "
"you must configure this app with an AppConfig subclass "
"with a 'path' class attribute." % (module,))
- return upath(paths[0])
+ return paths[0]
@classmethod
def create(cls, entry):
@@ -8,7 +8,6 @@
from django.core.exceptions import (
FieldDoesNotExist, ImproperlyConfigured, ValidationError,
)
-from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import lazy
from django.utils.html import format_html
@@ -168,7 +167,7 @@ class CommonPasswordValidator:
https://xato.net/passwords/more-top-worst-passwords/
"""
DEFAULT_PASSWORD_LIST_PATH = os.path.join(
- os.path.dirname(os.path.realpath(upath(__file__))), 'common-passwords.txt.gz'
+ os.path.dirname(os.path.realpath(__file__)), 'common-passwords.txt.gz'
)
def __init__(self, password_list_path=DEFAULT_PASSWORD_LIST_PATH):
@@ -9,7 +9,7 @@
from django.core.files.move import file_move_safe
from django.core.signals import setting_changed
from django.utils import timezone
-from django.utils._os import abspathu, safe_join
+from django.utils._os import safe_join
from django.utils.crypto import get_random_string
from django.utils.deconstruct import deconstructible
from django.utils.encoding import filepath_to_uri, force_text
@@ -201,7 +201,7 @@ def base_location(self):
@cached_property
def location(self):
- return abspathu(self.base_location)
+ return os.path.abspath(self.base_location)
@cached_property
def base_url(self):
@@ -14,7 +14,6 @@
)
from django.core.management.color import color_style
from django.utils import autoreload
-from django.utils._os import npath, upath
from django.utils.encoding import force_text
@@ -26,7 +25,7 @@ def find_commands(management_dir):
Returns an empty list if no commands are defined.
"""
command_dir = os.path.join(management_dir, 'commands')
- return [name for _, name, is_pkg in pkgutil.iter_modules([npath(command_dir)])
+ return [name for _, name, is_pkg in pkgutil.iter_modules([command_dir])
if not is_pkg and not name.startswith('_')]
@@ -63,7 +62,7 @@ def get_commands():
The dictionary is cached on the first call and reused on subsequent
calls.
"""
- commands = {name: 'django.core' for name in find_commands(upath(__path__[0]))}
+ commands = {name: 'django.core' for name in find_commands(__path__[0])}
if not settings.configured:
return commands
@@ -4,7 +4,6 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import find_command, popen_wrapper
-from django.utils._os import npath, upath
def has_bom(fn):
@@ -62,7 +61,7 @@ def handle(self, **options):
basedirs = [os.path.join('conf', 'locale'), 'locale']
if os.environ.get('DJANGO_SETTINGS_MODULE'):
from django.conf import settings
- basedirs.extend(upath(path) for path in settings.LOCALE_PATHS)
+ basedirs.extend(settings.LOCALE_PATHS)
# Walk entire tree, looking for locale directories
for dirpath, dirnames, filenames in os.walk('.', topdown=True):
@@ -115,13 +114,13 @@ def compile_messages(self, locations):
base_path = os.path.splitext(po_path)[0]
# Check writability on first location
- if i == 0 and not is_writable(npath(base_path + '.mo')):
+ if i == 0 and not is_writable(base_path + '.mo'):
self.stderr.write("The po files under %s are in a seemingly not writable location. "
"mo files will not be updated/created." % dirpath)
return
args = [self.program] + self.program_options + [
- '-o', npath(base_path + '.mo'), npath(base_path + '.po')
+ '-o', base_path + '.mo', base_path + '.po'
]
output, errors, status = popen_wrapper(args)
if status:
@@ -17,7 +17,6 @@
DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, connections, router,
transaction,
)
-from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import cached_property
@@ -287,7 +286,7 @@ def fixture_dirs(self):
dirs.append(app_dir)
dirs.extend(list(fixture_dirs))
dirs.append('')
- dirs = [upath(os.path.abspath(os.path.realpath(d))) for d in dirs]
+ dirs = [os.path.abspath(os.path.realpath(d)) for d in dirs]
return dirs
def parse_name(self, fixture_name):
@@ -14,7 +14,6 @@
from django.core.management.utils import (
find_command, handle_extensions, popen_wrapper,
)
-from django.utils._os import upath
from django.utils.encoding import DEFAULT_LOCALE_ENCODING
from django.utils.functional import cached_property
from django.utils.jslex import prepare_js_for_gettext
@@ -638,7 +637,7 @@ def copy_plural_forms(self, msgs, locale):
the msgs string, inserting it at the right place. msgs should be the
contents of a newly created .po file.
"""
- django_dir = os.path.normpath(os.path.join(os.path.dirname(upath(django.__file__))))
+ django_dir = os.path.normpath(os.path.join(os.path.dirname(django.__file__)))
if self.domain == 'djangojs':
domains = ('djangojs', 'django')
else:
@@ -7,7 +7,6 @@
from django.db import migrations
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.serializer import serializer_factory
-from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.inspect import get_func_args
from django.utils.module_loading import module_dir
@@ -229,7 +228,7 @@ def basedir(self):
pass
else:
try:
- return upath(module_dir(migrations_module))
+ return module_dir(migrations_module)
except ValueError:
pass
@@ -250,7 +249,7 @@ def basedir(self):
continue
else:
try:
- base_dir = upath(module_dir(base_module))
+ base_dir = module_dir(base_module)
except ValueError:
continue
else:
View
@@ -6,7 +6,6 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import six
-from django.utils._os import npath, upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
@@ -116,10 +115,10 @@ def load_backend(backend_name):
except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message
# listing all possible (built-in) database backends.
- backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends')
+ backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
try:
builtin_backends = [
- name for _, name, ispkg in pkgutil.iter_modules([npath(backend_dir)])
+ name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'}
]
except EnvironmentError:
@@ -4,7 +4,6 @@
from django.conf import settings
from django.template.backends.django import DjangoTemplates
from django.template.loader import get_template
-from django.utils._os import upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
@@ -14,7 +13,7 @@
def Jinja2(params):
raise ImportError("jinja2 isn't installed")
-ROOT = upath(os.path.dirname(__file__))
+ROOT = os.path.dirname(__file__)
@functools.lru_cache()
View
@@ -5,7 +5,6 @@
from django.apps import apps
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
-from django.utils._os import upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
@@ -103,6 +102,6 @@ def get_app_template_dirs(dirname):
continue
template_dir = os.path.join(app_config.path, dirname)
if os.path.isdir(template_dir):
- template_dirs.append(upath(template_dir))
+ template_dirs.append(template_dir)
# Immutable return value because it will be cached and shared by callers.
return tuple(template_dirs)
View
@@ -5,20 +5,19 @@
from django.core.exceptions import SuspiciousFileOperation
from django.utils.encoding import force_text
+# For backwards-compatibility in Django 2.0
abspathu = abspath
def upath(path):
- """
- Always return a unicode path.
- """
+ """Always return a unicode path (did something for Python 2)."""
return path
def npath(path):
"""
Always return a native path, that is unicode on Python 3 and bytestring on
- Python 2.
+ Python 2. Noop for Python 3.
"""
return path
@@ -33,8 +32,8 @@ def safe_join(base, *paths):
"""
base = force_text(base)
paths = [force_text(p) for p in paths]
- final_path = abspathu(join(base, *paths))
- base_path = abspathu(base)
+ final_path = abspath(join(base, *paths))
+ base_path = abspath(base)
# Ensure final_path starts with base_path (using normcase to ensure we
# don't false-negative on case insensitive operating systems like Windows),
# further, one of the following conditions must be true:
@@ -41,7 +41,6 @@
from django.conf import settings
from django.core.signals import request_finished
from django.utils import six
-from django.utils._os import npath
# This import does nothing, but it's necessary to avoid some race conditions
# in the threading module. See http://code.djangoproject.com/ticket/2330 .
@@ -111,7 +110,7 @@ def gen_filenames(only_new=False):
'conf', 'locale'),
'locale']
for app_config in reversed(list(apps.get_app_configs())):
- basedirs.append(os.path.join(npath(app_config.path), 'locale'))
+ basedirs.append(os.path.join(app_config.path, 'locale'))
basedirs.extend(settings.LOCALE_PATHS)
basedirs = [os.path.abspath(basedir) for basedir in basedirs
if os.path.isdir(basedir)]
@@ -14,7 +14,6 @@
from django.core.exceptions import AppRegistryNotReady
from django.core.signals import setting_changed
from django.dispatch import receiver
-from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.safestring import SafeData, mark_safe
from django.utils.translation import LANGUAGE_SESSION_KEY
@@ -155,7 +154,7 @@ def _new_gnu_trans(self, localedir, use_null_fallback=True):
def _init_translation_catalog(self):
"""Creates a base catalog using global django translations."""
- settingsfile = upath(sys.modules[settings.__module__].__file__)
+ settingsfile = sys.modules[settings.__module__].__file__
localedir = os.path.join(os.path.dirname(settingsfile), 'locale')
translation = self._new_gnu_trans(localedir)
self.merge(translation)
@@ -399,7 +398,7 @@ def all_locale_paths():
Returns a list of paths to user-provides languages files.
"""
globalpath = os.path.join(
- os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale')
+ os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
return [globalpath] + list(settings.LOCALE_PATHS)
@@ -26,10 +26,9 @@
from django.test import (
LiveServerTestCase, SimpleTestCase, TestCase, mock, override_settings,
)
-from django.utils._os import npath, upath
from django.utils.encoding import force_text
-custom_templates_dir = os.path.join(os.path.dirname(upath(__file__)), 'custom_templates')
+custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
PY36 = sys.version_info >= (3, 6)
SYSTEM_CHECK_MSG = 'System check identified no issues'
@@ -128,7 +127,7 @@ def _ext_backend_paths(self):
def run_test(self, script, args, settings_file=None, apps=None):
base_dir = os.path.dirname(self.test_dir)
# The base dir for Django's tests is one level up.
- tests_dir = os.path.dirname(os.path.dirname(upath(__file__)))
+ tests_dir = os.path.dirname(os.path.dirname(__file__))
# The base dir for Django is one level above the test dir. We don't use
# `import django` to figure that out, so we don't pick up a Django
# from site-packages or similar.
@@ -152,7 +151,7 @@ def run_test(self, script, args, settings_file=None, apps=None):
python_path = [base_dir, django_dir, tests_dir]
python_path.extend(ext_backend_base_dirs)
# Use native strings for better compatibility
- test_environ[str(python_path_var_name)] = npath(os.pathsep.join(python_path))
+ test_environ[str(python_path_var_name)] = os.pathsep.join(python_path)
test_environ[str('PYTHONWARNINGS')] = str('')
# Move to the test directory and run
@@ -168,7 +167,7 @@ def run_test(self, script, args, settings_file=None, apps=None):
return out, err
def run_django_admin(self, args, settings_file=None):
- script_dir = os.path.abspath(os.path.join(os.path.dirname(upath(django.__file__)), 'bin'))
+ script_dir = os.path.abspath(os.path.join(os.path.dirname(django.__file__), 'bin'))
return self.run_test(os.path.join(script_dir, 'django-admin.py'), args, settings_file)
def run_manage(self, args, settings_file=None):
@@ -178,7 +177,7 @@ def safe_remove(path):
except OSError:
pass
- conf_dir = os.path.dirname(upath(conf.__file__))
+ conf_dir = os.path.dirname(conf.__file__)
template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py-tpl')
test_manage_py = os.path.join(self.test_dir, 'manage.py')
@@ -1,10 +1,9 @@
import os
from django.conf.urls import url
-from django.utils._os import upath
from django.views.static import serve
-here = os.path.dirname(upath(__file__))
+here = os.path.dirname(__file__)
urlpatterns = [
url(r'^custom_templates/(?P<path>.*)$', serve, {
@@ -31,7 +31,6 @@
from django.test.utils import override_script_prefix, patch_logger
from django.urls import NoReverseMatch, resolve, reverse
from django.utils import formats, translation
-from django.utils._os import upath
from django.utils.cache import get_max_age
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.encoding import force_bytes, force_text, iri_to_uri
@@ -919,8 +918,8 @@ def test_adminsite_display_site_url(self):
# Put this app's and the shared tests templates dirs in DIRS to take precedence
# over the admin's templates dir.
'DIRS': [
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),
- os.path.join(os.path.dirname(os.path.dirname(upath(__file__))), 'templates'),
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
@@ -3,13 +3,12 @@
from django.apps import apps
from django.test import SimpleTestCase
from django.test.utils import extend_sys_path
-from django.utils._os import upath
class EggLoadingTest(SimpleTestCase):
def setUp(self):
- self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
+ self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
def tearDown(self):
apps.clear_cache()
Oops, something went wrong.

0 comments on commit 4e729fe

Please sign in to comment.