Skip to content

Commit

Permalink
Update {create,update}project for apps.py re #11009
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 19, 2024
1 parent 641a0db commit 4143d7c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
10 changes: 8 additions & 2 deletions arches/install/arches-admin
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,19 @@ class ArchesProjectCommand(TemplateCommand):
# need to manually replace instances of {{ project_name }} in some files
path_to_project = os.path.join(target) if target else os.path.join(os.getcwd(), project_name)

for relative_file_path in ['.coveragerc', "pyproject.toml", ".pre-commit-config.yaml"]: # relative to app root directory
for relative_file_path in [
os.path.join(project_name, "apps.py"),
".coveragerc",
"pyproject.toml",
".pre-commit-config.yaml"
]: # relative to app root directory
file = open(os.path.join(path_to_project, relative_file_path),'r')
file_data = file.read()
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"])
.replace("{{ arches_next_minor_version }}", options["arches_next_minor_version"])
)
Expand Down
10 changes: 8 additions & 2 deletions arches/install/arches-project
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ class ArchesCommand(TemplateCommand):
# need to manually replace instances of {{ project_name }} in some files
path_to_project = os.path.join(target) if target else os.path.join(os.getcwd(), project_name)

for relative_file_path in ['.coveragerc', "pyproject.toml", ".pre-commit-config.yaml"]: # relative to app root directory
for relative_file_path in [
os.path.join(project_name, "apps.py"),
".coveragerc",
"pyproject.toml",
".pre-commit-config.yaml",
]: # relative to app root directory
file = open(os.path.join(path_to_project, relative_file_path),'r')
file_data = file.read()
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"])
.replace("{{ arches_next_minor_version }}", options["arches_next_minor_version"])
)
Expand Down
9 changes: 3 additions & 6 deletions arches/install/arches-templates/project_name/apps.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ from django.apps import AppConfig
from arches.settings_utils import inject_arches_applications_directories


class {{ project_name }}Config(AppConfig):
class {{ project_name_title_case }}Config(AppConfig):
name = "{{ project_name }}"
# consider adding verbose_name = ...
verbose_name = {{ project_name_title_case }}
is_arches_application = True

def ready(self):
from django.conf import settings

if self.name == settings.INSTALLED_APPS[-1]:
inject_arches_applications_directories()
inject_arches_applications_directories()
29 changes: 28 additions & 1 deletion arches/management/commands/updateproject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import arches
import os
import shutil
import warnings

from django.core.management.base import BaseCommand
from django.core import management
Expand Down Expand Up @@ -173,6 +174,28 @@ def update_to_v7_6(self):
os.path.join(dirpath, filename[:-7] + ".py"),
)

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, "install", "requirements_dev.txt")
):
Expand Down Expand Up @@ -247,6 +270,7 @@ def update_to_v7_6(self):

path_to_project = os.path.join(settings.APP_ROOT, "..")
for relative_file_path in [
os.path.join(settings.APP_NAME, "apps.py"),
"gettext.config.js",
".coveragerc",
".gitignore",
Expand All @@ -262,7 +286,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

0 comments on commit 4143d7c

Please sign in to comment.