Skip to content

Commit

Permalink
merge #11001
Browse files Browse the repository at this point in the history
  • Loading branch information
chrabyrd committed Jul 15, 2024
2 parents 7b1f0f6 + 458d751 commit 28c0571
Show file tree
Hide file tree
Showing 19 changed files with 280 additions and 188 deletions.
38 changes: 15 additions & 23 deletions arches/app/media/js/utils/load-component-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,35 @@
define([], function() {
return function loadComponentDependencies(componentPaths){
for (const componentPath of componentPaths) {
try { // first try to load project path
require(`${APP_ROOT_DIRECTORY}/media/js/${componentPath}`);
}
catch(e) { // if project path fails, look in applications
try {
if (ARCHES_APPLICATIONS.length === 0) { // ensures fallthrough to Arches-core
throw new Error();
try {
for (const archesApp of ARCHES_APPLICATIONS) {
try {
require(`${SITE_PACKAGES_DIRECTORY}/${archesApp}/media/js/${componentPath}`);
break;
}
for (const archesApp of ARCHES_APPLICATIONS) {
catch(e) { // handles egg/wheel links, cannot access them programatically hence manual access
try {
require(`${SITE_PACKAGES_DIRECTORY}/${archesApp}/media/js/${componentPath}`);
require(`${LINKED_APPLICATION_PATH_0}/media/js/${componentPath}`);
break;
}
catch(e) { // handles egg/wheel links, cannot access them programatically hence manual access
catch { // handles egg/wheel links, cannot access them programatically hence manual access
try {
require(`${LINKED_APPLICATION_PATH_0}/media/js/${componentPath}`);
require(`${LINKED_APPLICATION_PATH_1}/media/js/${componentPath}`);
break;
}
catch { // handles egg/wheel links, cannot access them programatically hence manual access
catch { // handles egg/wheel links, cannot access them programatically hence manual access
try {
require(`${LINKED_APPLICATION_PATH_1}/media/js/${componentPath}`);
require(`${LINKED_APPLICATION_PATH_2}/media/js/${componentPath}`);
break;
}
catch { // handles egg/wheel links, cannot access them programatically hence manual access
try {
require(`${LINKED_APPLICATION_PATH_2}/media/js/${componentPath}`);
break;
}
catch { throw new Error(); } // if all attempts fail within the loop, throw error for outer try/catch
}
catch { throw new Error(); } // if all attempts fail within the loop, throw error for outer try/catch
}
}
}
}
catch(e) { // finally, look in Arches core for component
require(`${ARCHES_CORE_DIRECTORY}/app/media/js/${componentPath}`);
}
}
catch(e) { // finally, look in Arches core for component
require(`${ARCHES_CORE_DIRECTORY}/app/media/js/${componentPath}`);
}
}
};
Expand Down
26 changes: 14 additions & 12 deletions arches/app/utils/module_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from arches.app.const import ExtensionType
from arches.app.models.system_settings import settings
from arches.settings_utils import list_arches_app_names


def get_module(path, modulename=""):
Expand All @@ -10,26 +11,27 @@ def get_module(path, modulename=""):


def get_directories(extension_type: ExtensionType):
core_root_dir = f"arches.app.{extension_type.value}"
if extension_type is ExtensionType.SEARCH_COMPONENTS:
core_root_dir = core_root_dir.replace("search_components", "search.components")

core_and_arches_app_dirs = [core_root_dir]
for arches_app in settings.ARCHES_APPLICATIONS:
core_and_arches_app_dirs.append(f"{arches_app}.{extension_type.value}")
core_and_arches_app_dirs.append(
f"{arches_app}.pkg.extensions.{extension_type.value}"
)
arches_app_dirs = []
for arches_app in list_arches_app_names():
arches_app_dirs.append(f"{arches_app}.{extension_type.value}")
arches_app_dirs.append(f"{arches_app}.pkg.extensions.{extension_type.value}")

filtered_settings_dirs = [
setting_dir
for setting_dir in getattr(
settings, extension_type.value.upper()[:-1] + "_LOCATIONS"
)
if setting_dir not in core_and_arches_app_dirs
if setting_dir not in arches_app_dirs
]

return core_and_arches_app_dirs + filtered_settings_dirs
core_root_dir = f"arches.app.{extension_type.value}"
if extension_type is ExtensionType.SEARCH_COMPONENTS:
core_root_dir = core_root_dir.replace("search_components", "search.components")

if core_root_dir in filtered_settings_dirs:
filtered_settings_dirs.remove(core_root_dir)

return arches_app_dirs + filtered_settings_dirs + [core_root_dir]


def get_class_from_modulename(modulename, classname, extension_type: ExtensionType):
Expand Down
2 changes: 1 addition & 1 deletion arches/app/utils/thumbnail_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging
import importlib

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

logger = logging.getLogger(__name__)

Expand Down
12 changes: 5 additions & 7 deletions arches/app/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from arches.app.search.components.base import SearchFilterFactory
from arches.app.datatypes.datatypes import DataTypeFactory, EDTFDataType
from arches.app.search.search_engine_factory import SearchEngineFactory
from arches.settings_utils import list_arches_app_paths

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -119,19 +120,16 @@ def get(self, request):
language_file_path = []

language_file_path.append(
os.path.join(settings.APP_ROOT, "locale", user_language + ".json")
os.path.join(settings.ROOT_DIR, "locale", user_language + ".json")
)

for arches_application_name in settings.ARCHES_APPLICATIONS:
application_path = os.path.split(
sys.modules[arches_application_name].__spec__.origin
)[0]
for arches_app_path in list_arches_app_paths():
language_file_path.append(
os.path.join(application_path, "locale", user_language + ".json")
os.path.join(arches_app_path, "locale", user_language + ".json")
)

language_file_path.append(
os.path.join(settings.ROOT_DIR, "locale", user_language + ".json")
os.path.join(settings.APP_ROOT, "locale", user_language + ".json")
)

localized_strings = {}
Expand Down
10 changes: 8 additions & 2 deletions arches/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import warnings

from django.apps import AppConfig
from django.conf import settings
from django.core.checks import register, Tags, Error, Warning


class ArchesAppConfig(AppConfig):
name = "arches"
verbose_name = "Arches"
is_arches_application = False


### GLOBAL DEPRECATIONS ###
FILE_TYPE_CHECKING_MSG = (
"Providing boolean values to FILE_TYPE_CHECKING is deprecated. "
Expand All @@ -14,8 +22,6 @@


### SYSTEM CHECKS ###


@register(Tags.security)
def check_cache_backend_for_production(app_configs, **kwargs):
errors = []
Expand Down
7 changes: 7 additions & 0 deletions arches/install/arches-templates/project_name/apps.py-tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class {{ project_name_title_case }}Config(AppConfig):
name = "{{ project_name }}"
verbose_name = "{{ project_name_title_case }}"
is_arches_application = True
24 changes: 6 additions & 18 deletions arches/install/arches-templates/project_name/settings.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ INSTALLED_APPS = (
"oauth2_provider",
"django_celery_results",
# "silk",
"{{ project_name }}",
"{{ project_name }}", # Ensure the project is listed before any other arches applications
)

ARCHES_APPLICATIONS = ()
# Placing this last ensures any templates provided by Arches Applications
# take precedence over core arches templates in arches/app/templates.
INSTALLED_APPS += ("arches.app",)

INSTALLED_APPS += ARCHES_APPLICATIONS

Expand Down Expand Up @@ -182,17 +184,11 @@ MIDDLEWARE.append( # this must resolve last MIDDLEWARE entry
"django_hosts.middleware.HostsResponseMiddleware"
)

STATICFILES_DIRS = build_staticfiles_dirs(
root_dir=ROOT_DIR,
app_root=APP_ROOT,
arches_applications=ARCHES_APPLICATIONS,
)
STATICFILES_DIRS = build_staticfiles_dirs(app_root=APP_ROOT)

TEMPLATES = build_templates_config(
root_dir=ROOT_DIR,
debug=DEBUG,
app_root=APP_ROOT,
arches_applications=ARCHES_APPLICATIONS,
)

ALLOWED_HOSTS = []
Expand Down Expand Up @@ -438,12 +434,4 @@ except ImportError as e:

# returns an output that can be read by NODEJS
if __name__ == "__main__":
transmit_webpack_django_config(
root_dir=ROOT_DIR,
app_root=APP_ROOT,
arches_applications=ARCHES_APPLICATIONS,
public_server_address=PUBLIC_SERVER_ADDRESS,
static_url=STATIC_URL,
webpack_development_server_port=WEBPACK_DEVELOPMENT_SERVER_PORT,
)

transmit_webpack_django_config(**locals())
2 changes: 1 addition & 1 deletion arches/install/arches-templates/project_name/urls.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# Only handle i18n routing in active project. This will still handle the routes provided by Arches core and Arches applications,
# but handling i18n routes in multiple places causes application errors.
if settings.APP_NAME != "Arches" and settings.APP_NAME not in settings.ARCHES_APPLICATIONS:
if settings.ROOT_URLCONF == __name__:
if settings.SHOW_LANGUAGE_SWITCH is True:
urlpatterns = i18n_patterns(*urlpatterns)

Expand Down
2 changes: 0 additions & 2 deletions arches/install/arches-templates/tests/test_settings.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ TEST_ROOT = os.path.normpath(os.path.join(ROOT_DIR, "..", "tests"))

ROOT_URLCONF = '{{ project_name }}.urls'

ARCHES_APPLICATIONS = ()

MIN_ARCHES_VERSION = arches.__version__
MAX_ARCHES_VERSION = arches.__version__

Expand Down
5 changes: 4 additions & 1 deletion arches/install/arches_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def handle(self, options):
options["arches_next_minor_version"] = ".".join(
[str(arches.VERSION[0]), str(arches.VERSION[1] + 1), "0"]
)
options["project_name_title_case"] = project_name.title()

super(ArchesProjectCommand, self).handle(
"project", project_name, target, **options
Expand All @@ -132,6 +133,7 @@ def handle(self, options):
)

for relative_file_path in [
os.path.join(project_name, "apps.py"),
".coveragerc",
"pyproject.toml",
".pre-commit-config.yaml",
Expand All @@ -142,7 +144,8 @@ def handle(self, options):
file.close()

updated_file_data = (
file_data.replace("{{ project_name }}", project_name)
file_data.replace("{{ project_name_title_case }}", project_name.title())
.replace("{{ project_name }}", project_name)
.replace(
"{{ arches_semantic_version }}", options["arches_semantic_version"]
)
Expand Down
5 changes: 4 additions & 1 deletion arches/install/arches_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def handle(self, options):
options["arches_next_minor_version"] = ".".join(
[str(arches.VERSION[0]), str(arches.VERSION[1] + 1), "0"]
)
options["project_name_title_case"] = project_name.title()

super(ArchesCommand, self).handle("project", project_name, target, **options)

Expand All @@ -60,6 +61,7 @@ def handle(self, options):
)

for relative_file_path in [
os.path.join(project_name, "apps.py"),
".coveragerc",
"pyproject.toml",
".pre-commit-config.yaml",
Expand All @@ -70,7 +72,8 @@ def handle(self, options):
file.close()

updated_file_data = (
file_data.replace("{{ project_name }}", project_name)
file_data.replace("{{ project_name_title_case }}", project_name.title())
.replace("{{ project_name }}", project_name)
.replace(
"{{ arches_semantic_version }}", options["arches_semantic_version"]
)
Expand Down
30 changes: 28 additions & 2 deletions arches/management/commands/updateproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import arches
import os
import shutil
import warnings

from django.core.management.base import BaseCommand
from django.core import management
from django.db import connection
from arches.app.models.system_settings import settings


class Command(BaseCommand):
class Command(BaseCommand): # pragma: no cover
"""
Command for migrating projects between versions
Expand Down Expand Up @@ -252,6 +253,28 @@ def update_to_v7_6(self):
),
)

if os.path.isfile(os.path.join(settings.APP_ROOT, "apps.py")):
warnings.warn(
"Existing apps.py detected. Manually add is_arches_application=True.",
UserWarning,
)
else:
self.stdout.write("Copying apps.py to project root")
shutil.copy2(
os.path.join(
settings.ROOT_DIR,
"install",
"arches-templates",
"project_name",
"apps.py-tpl",
),
settings.APP_ROOT,
)
os.rename(
os.path.join(settings.APP_ROOT, "apps.py-tpl"),
os.path.join(settings.APP_ROOT, "apps.py"),
)

if not os.path.isfile(
os.path.join(settings.APP_ROOT, "src", "declarations.d.ts")
):
Expand Down Expand Up @@ -325,7 +348,10 @@ def update_to_v7_6(self):
file.close()

updated_file_data = (
file_data.replace("{{ project_name }}", settings.APP_NAME)
file_data.replace(
"{{ project_name_title_case }}", settings.APP_NAME.title()
)
.replace("{{ project_name }}", settings.APP_NAME)
.replace("{{ arches_semantic_version }}", arches_semantic_version)
.replace(
"{{ arches_next_minor_version }}", arches_next_minor_version
Expand Down
Loading

0 comments on commit 28c0571

Please sign in to comment.