Skip to content

Commit d1c72d9

Browse files
committed
Removed django.core.management.setup_environ and execute_manager.
1 parent 5935124 commit d1c72d9

File tree

2 files changed

+0
-134
lines changed

2 files changed

+0
-134
lines changed

django/core/management/__init__.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -391,79 +391,9 @@ def execute(self):
391391
else:
392392
self.fetch_command(subcommand).run_from_argv(self.argv)
393393

394-
def setup_environ(settings_mod, original_settings_path=None):
395-
"""
396-
Configures the runtime environment. This can also be used by external
397-
scripts wanting to set up a similar environment to manage.py.
398-
Returns the project directory (assuming the passed settings module is
399-
directly in the project directory).
400-
401-
The "original_settings_path" parameter is optional, but recommended, since
402-
trying to work out the original path from the module can be problematic.
403-
"""
404-
warnings.warn(
405-
"The 'setup_environ' function is deprecated, "
406-
"you likely need to update your 'manage.py'; "
407-
"please see the Django 1.4 release notes "
408-
"(https://docs.djangoproject.com/en/dev/releases/1.4/).",
409-
DeprecationWarning)
410-
411-
# Add this project to sys.path so that it's importable in the conventional
412-
# way. For example, if this file (manage.py) lives in a directory
413-
# "myproject", this code would add "/path/to/myproject" to sys.path.
414-
if '__init__.py' in upath(settings_mod.__file__):
415-
p = os.path.dirname(upath(settings_mod.__file__))
416-
else:
417-
p = upath(settings_mod.__file__)
418-
project_directory, settings_filename = os.path.split(p)
419-
if project_directory == os.curdir or not project_directory:
420-
project_directory = os.getcwd()
421-
project_name = os.path.basename(project_directory)
422-
423-
# Strip filename suffix to get the module name.
424-
settings_name = os.path.splitext(settings_filename)[0]
425-
426-
# Strip $py for Jython compiled files (like settings$py.class)
427-
if settings_name.endswith("$py"):
428-
settings_name = settings_name[:-3]
429-
430-
# Set DJANGO_SETTINGS_MODULE appropriately.
431-
if original_settings_path:
432-
os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
433-
else:
434-
# If DJANGO_SETTINGS_MODULE is already set, use it.
435-
os.environ['DJANGO_SETTINGS_MODULE'] = os.environ.get(
436-
'DJANGO_SETTINGS_MODULE',
437-
'%s.%s' % (project_name, settings_name)
438-
)
439-
440-
# Import the project module. We add the parent directory to PYTHONPATH to
441-
# avoid some of the path errors new users can have.
442-
sys.path.append(os.path.join(project_directory, os.pardir))
443-
import_module(project_name)
444-
sys.path.pop()
445-
446-
return project_directory
447-
448394
def execute_from_command_line(argv=None):
449395
"""
450396
A simple method that runs a ManagementUtility.
451397
"""
452398
utility = ManagementUtility(argv)
453399
utility.execute()
454-
455-
def execute_manager(settings_mod, argv=None):
456-
"""
457-
Like execute_from_command_line(), but for use by manage.py, a
458-
project-specific django-admin.py utility.
459-
"""
460-
warnings.warn(
461-
"The 'execute_manager' function is deprecated, "
462-
"you likely need to update your 'manage.py'; "
463-
"please see the Django 1.4 release notes "
464-
"(https://docs.djangoproject.com/en/dev/releases/1.4/).",
465-
DeprecationWarning)
466-
467-
setup_environ(settings_mod)
468-
utility = ManagementUtility(argv)
469-
utility.execute()

tests/regressiontests/settings_tests/tests.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -287,67 +287,3 @@ def test_set_with_xheader_right(self):
287287
req = HttpRequest()
288288
req.META['HTTP_X_FORWARDED_PROTOCOL'] = 'https'
289289
self.assertEqual(req.is_secure(), True)
290-
291-
class EnvironmentVariableTest(TestCase):
292-
"""
293-
Ensures proper settings file is used in setup_environ if
294-
DJANGO_SETTINGS_MODULE is set in the environment.
295-
"""
296-
# Decide what to do with these tests when setup_environ() gets removed in Django 1.6
297-
def setUp(self):
298-
self.original_value = os.environ.get('DJANGO_SETTINGS_MODULE')
299-
self.save_warnings_state()
300-
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.core.management')
301-
302-
def tearDown(self):
303-
self.restore_warnings_state()
304-
if self.original_value:
305-
os.environ['DJANGO_SETTINGS_MODULE'] = self.original_value
306-
elif 'DJANGO_SETTINGS_MODULE' in os.environ:
307-
del(os.environ['DJANGO_SETTINGS_MODULE'])
308-
309-
def test_env_var_used(self):
310-
"""
311-
If the environment variable is set, do not ignore it. However, the
312-
kwarg original_settings_path takes precedence.
313-
314-
This tests both plus the default (neither set).
315-
"""
316-
from django.core.management import setup_environ
317-
318-
# whatever was already there
319-
original_module = os.environ.get(
320-
'DJANGO_SETTINGS_MODULE',
321-
'the default'
322-
)
323-
324-
# environment variable set by user
325-
user_override = 'custom.settings'
326-
327-
# optional argument to setup_environ
328-
orig_path = 'original.path'
329-
330-
# expect default
331-
setup_environ(global_settings)
332-
self.assertEqual(
333-
os.environ.get('DJANGO_SETTINGS_MODULE'),
334-
original_module
335-
)
336-
337-
# override with environment variable
338-
os.environ['DJANGO_SETTINGS_MODULE'] = user_override
339-
setup_environ(global_settings)
340-
341-
self.assertEqual(
342-
os.environ.get('DJANGO_SETTINGS_MODULE'),
343-
user_override
344-
)
345-
346-
# pass in original_settings_path (should take precedence)
347-
os.environ['DJANGO_SETTINGS_MODULE'] = user_override
348-
setup_environ(global_settings, original_settings_path = orig_path)
349-
350-
self.assertEqual(
351-
os.environ.get('DJANGO_SETTINGS_MODULE'),
352-
orig_path
353-
)

0 commit comments

Comments
 (0)