我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.conf.settings.configured()。
def run(*args): """ Check and/or create dj-stripe Django migrations. If --check is present in the arguments then migrations are checked only. """ if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) if "--check" in args: check_migrations() else: django.core.management.call_command("makemigrations", APP_NAME, *args)
def runtests(*test_args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.news.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures)
def runtests(*test_args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.cohorts.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures)
def main(): """ django-develop CLI entry point. """ # XXX: Bail out early if being invoked for autocompletion. utility = ManagementUtility() utility.autocomplete() if not utils.is_inside_virtual_env(): _fail('Run django-develop inside a virtualenv') dd = _get_DjangoDevelop() if not dd.instance_path.exists(): _fail('django-develop not configured, try "django-develop-config"') else: # Set up and hand over to Django dd.activate_dev_settings() utility.execute()
def runtests(*test_args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.api.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures)
def run(command): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) # Compatibility with Django 1.7's stricter initialization if hasattr(django, 'setup'): django.setup() parent = os.path.dirname(os.path.abspath(__file__)) appdir = os.path.join(parent, 'lbattachment') os.chdir(appdir) from django.core.management import call_command params = {} if command == 'make': params['locale'] = ['zh-Hans'] call_command('%smessages' % command, **params)
def runtests(): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) # Compatibility with Django 1.7's stricter initialization if hasattr(django, 'setup'): django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ['lbattachment.tests'] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ['tests'] failures = runner_class( verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures)
def get_commands(): """ Returns a dictionary mapping command names to their callback applications. This works by looking for a management.commands package in django.core, and in each installed application -- if a commands package exists, all commands in that package are registered. Core commands are always included. If a settings module has been specified, user-defined commands will also be included. The dictionary is in the format {command_name: app_name}. Key-value pairs from this dictionary can then be used in calls to load_command_class(app_name, command_name) If a specific version of a command must be loaded (e.g., with the startapp command), the instantiated module can be placed in the dictionary in place of the application name. 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]))} if not settings.configured: return commands for app_config in reversed(list(apps.get_app_configs())): path = os.path.join(app_config.path, 'management') commands.update({name: app_config.name for name in find_commands(path)}) return commands
def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ if commands_only: usage = sorted(get_commands().keys()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands_dict = defaultdict(lambda: []) for name, app in six.iteritems(get_commands()): if app == 'django.core': app = 'django' else: app = app.rpartition('.')[-1] commands_dict[app].append(name) style = color_style() for app in sorted(commands_dict.keys()): usage.append("") usage.append(style.NOTICE("[%s]" % app)) for name in sorted(commands_dict[app]): usage.append(" %s" % name) # Output an extra note if settings are not properly configured if self.settings_exception is not None: usage.append(style.NOTICE( "Note that only Django core commands are listed " "as settings are not properly configured (error: %s)." % self.settings_exception)) return '\n'.join(usage)
def pytest_configure(): if not settings.configured: from pootle import syspath_override # Needed for monkey-patching syspath_override os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings' os.environ['ZING_SETTINGS'] = os.path.join(WORKING_DIR, 'settings.py') # The call to `setup()` was needed before a fix for # pytest-dev/pytest-django#146 was available. This happened in version # 2.9; unfortunately upgrading to 2.9+ is not possible yet because a fix # for pytest-dev/pytest-django#289 is needed too, and this is not part # of any releases for the time being. setup()
def pytest_configure(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") import django from django.conf import settings if settings.configured and hasattr(django, 'setup'): django.setup()
def run(*args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) django.core.management.call_command( "makemigrations", "pinax_news", *args )
def __init__(self, node, **options): if settings.configured: options.update(getattr(settings,'PYPUGJS',{})) super(Compiler, self).__init__(node, **options)
def run(*args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) django.core.management.call_command( "makemigrations", "pinax_cohorts", *args )
def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ if commands_only: usage = sorted(get_commands().keys()) else: usage = [ "", "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, "", "Available subcommands:", ] commands_dict = collections.defaultdict(lambda: []) for name, app in six.iteritems(get_commands()): if app == 'django.core': app = 'django' else: app = app.rpartition('.')[-1] commands_dict[app].append(name) style = color_style() for app in sorted(commands_dict.keys()): usage.append("") usage.append(style.NOTICE("[%s]" % app)) for name in sorted(commands_dict[app]): usage.append(" %s" % name) # Output an extra note if settings are not properly configured if self.settings_exception is not None: usage.append(style.NOTICE( "Note that only Django core commands are listed " "as settings are not properly configured (error: %s)." % self.settings_exception)) return '\n'.join(usage)
def main(): if not settings.configured: module_root = path.dirname(path.realpath(__file__)) settings.configure( DEBUG = False, INSTALLED_APPS = ( 'private_storage', ), ) if django.VERSION >= (1,7): django.setup() makemessages()
def main_config(): """ django-develop-config CLI entry point. """ if not utils.is_inside_virtual_env(): _fail('Run django-develop-config inside a virtualenv') dd = _get_DjangoDevelop() # type: DjangoDevelop try: [base_settings_module] = sys.argv[1:2] except ValueError: print('Usage: django-develop-config <base_settings_module>') print() # Show current configuration if dd.instance_path.exists(): print('Instance directory: {}'.format(dd.instance_path)) print() config = dd.read_config() base_settings_module = config.get('django-develop', 'base_settings_module', fallback=None) print('Current base settings module: {}'.format( utils.SUCCESS(base_settings_module) if base_settings_module else 'not configured')) print() # TODO: Add CLI flag for include_problems? utils.print_candidate_settings() raise SystemExit(2) else: dd.init_instance(base_settings_module)
def pytest_configure(config): if not settings.configured: os.environ['DJANGO_SETTINGS_MODULE'] = 'hw3.settings' settings.DATABASES['default'] = settings.TEST_DATABASES[os.environ.get('DJANGO_TEST_DATABASE', 'default')] settings.DEBUG = False # settings.AUTHENTICATION_BACKENDS = ['tests.base.utils.AuthBackend'] # settings.MIDDLEWARE += ['tests.base.utils.AuthMiddleware'] # settings.EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'