Skip to content

Commit

Permalink
naming, cruft, logic nits re: #11009
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 10, 2024
1 parent 736fcd5 commit 54edfc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
1 change: 0 additions & 1 deletion arches/app/utils/thumbnail_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import logging
import importlib

from django.apps import apps
from arches.app.models.system_settings import settings

logger = logging.getLogger(__name__)
Expand Down
30 changes: 14 additions & 16 deletions arches/settings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@contextmanager
def move_to_end_of_sys_path(*paths):
def _move_to_end_of_sys_path(*paths):
_orig_sys_path = sys.path[:]
for path in paths:
if path in sys.path:
Expand All @@ -26,26 +26,22 @@ def arches_applications():
from arches import settings as core_settings

return [
mod.name for mod in arches_applications_modules(core_settings.INSTALLED_APPS)
module.name
for module in arches_applications_modules(core_settings.INSTALLED_APPS)
]


def arches_applications_modules(installed_apps):
from arches import settings as core_settings

arches_applications_modules = []

for app in installed_apps or []:
if app in core_settings.INSTALLED_APPS:
continue
try:
config = AppConfig.create(app)
except ImportError:
# Something not pip-installed (the project) might not be importable yet.
continue
if getattr(config, "is_arches_application", False):
arches_applications_modules.append(config.module)
break

return arches_applications_modules

Expand Down Expand Up @@ -151,22 +147,24 @@ def build_templates_config(


def transmit_webpack_django_config(**kwargs):
is_core = kwargs["APP_NAME"] == "Arches"
our_settings = {k: v for k, v in kwargs.items() if k.isupper()}
is_arches_core = kwargs["APP_NAME"] == "Arches"
transmitted_project_settings = {k: v for k, v in kwargs.items() if k.isupper()}

# We're currently executing APP_NAME's settings.py,
# we don't need to try to install it, too.
if not is_core:
our_settings["INSTALLED_APPS"] = list(our_settings["INSTALLED_APPS"])
our_settings["INSTALLED_APPS"].remove(kwargs["APP_NAME"])
settings.configure(default_settings=global_settings, **our_settings)
if not is_arches_core:
transmitted_project_settings["INSTALLED_APPS"] = list(
transmitted_project_settings["INSTALLED_APPS"]
)
transmitted_project_settings["INSTALLED_APPS"].remove(kwargs["APP_NAME"])
settings.configure(default_settings=global_settings, **transmitted_project_settings)

# Without this `import celery` might resolve to arches.celery or project.celery
if is_core:
with move_to_end_of_sys_path(os.path.realpath(kwargs["ROOT_DIR"])):
if is_arches_core:
with _move_to_end_of_sys_path(os.path.realpath(kwargs["ROOT_DIR"])):
django.setup()
else:
with move_to_end_of_sys_path(os.path.realpath(kwargs["APP_ROOT"])):
with _move_to_end_of_sys_path(os.path.realpath(kwargs["APP_ROOT"])):
django.setup()

arches_applications_paths = {
Expand Down

0 comments on commit 54edfc8

Please sign in to comment.