Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Use cookiecutter organization name throughout project #656

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ updates:
open-pull-requests-limit: 1

- package-ecosystem: "pip"
directory: "/{{cookiecutter.repo_name}}"
directory: "/{{^cookiecutter.repo_name^}}"
schedule:
interval: "weekly"
target-branch: "develop"
open-pull-requests-limit: 1

- package-ecosystem: "npm"
directory: "/{{cookiecutter.repo_name}}"
directory: "/{{^cookiecutter.repo_name^}}"
schedule:
interval: "weekly"
target-branch: "develop"
19 changes: 10 additions & 9 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"project_name": "sampleapp",
"project_name_verbose": "Sample App",
"repo_name": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}",
"author_name": "Ben Beecher",
"email": "{{ cookiecutter.author_name.lower()|replace(' ', '-') }}@lightmatter.com",
"org_name": "Lightmatter",
"description": "A short description of the project.",
"author_name": "John Smith",
"org_name": "Django Hydra",
"domain_name": "example.com",
"email": "{{ cookiecutter.author_name.lower()|replace(' ', '-') }}@{{ cookiecutter.domain_name|lower }}",
"description": "A short description of the project.",
"version": "0.1.0",
"_copy_without_render": [
"{{cookiecutter.repo_name}}/**/*.jinja",
"{{cookiecutter.repo_name}}/**/*.html",
"{{cookiecutter.repo_name}}/templates/**/*.txt"
]
"_jinja2_env_vars": {
"variable_start_string": "{{^",
"variable_end_string": "^}}",
"block_start_string": "{%^",
"block_end_string": "%^}"
}
}
4 changes: 2 additions & 2 deletions docs/source/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Project Structure

Hydra is wholly contained within the Django project folder. All of the backend functionality is defined in apps within the project folders, html/jinja templates and Alpine.js components for additional frontend functionality are defined side by side within a templates folder, and the static assets (such as CSS and TypeScript) that are served by Vite are defined in the static_source. The philosophy is to have things that are related to each other actually next to each other and not have a separate frontend vs backend folder structure.

The folder structure within ``/{{ cookiecutter.project_name }}`` is as follows:
The folder structure within ``/{{^ cookiecutter.project_name ^}}`` is as follows:

* ``/config`` - Project settings, asgi settings, and base urls
* ``/home`` - Handles home page for django, error endpoint, settings context processor
Expand Down Expand Up @@ -159,7 +159,7 @@ For instructions on customizing or extending the color palette, see the instruct
Components
----------

All generic Jinja components are under the `{{cookiecutter.repo_name}}/templates/components/` directory. The structure follows the
All generic Jinja components are under the `{{^ cookiecutter.repo_name ^}}/templates/components/` directory. The structure follows the
material.ui format of having a folder per component with the js/css/jinja files within, allowing for files to be overwritten and customized
as needed.

Expand Down
3 changes: 1 addition & 2 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import re
import sys


MODULE_REGEX = r"^[a-z][_a-z]+$"

module_name = "{{cookiecutter.repo_name}}"
module_name = "{{ cookiecutter.repo_name }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weirdly enough, this file ignores the _jinja2_env_vars for strings?


if not re.match(MODULE_REGEX, module_name):
print(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/.env
/.venv/
/node_modules
/{{cookiecutter.repo_name}}/static
/{{^ cookiecutter.repo_name ^}}/static
.DS_Store
.editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PYTHONBREAKPOINT="pudb.set_trace"
ENV_NAME="{{cookiecutter.repo_name}}"
ENV_NAME="{{^cookiecutter.repo_name^}}"

DATABASE_URL="psql://{{ cookiecutter.repo_name }}:{{cookiecutter.repo_name}}@localhost/{{cookiecutter.repo_name}}"
DATABASE_URL="psql://{{^ cookiecutter.repo_name ^}}:{{^cookiecutter.repo_name^}}@localhost/{{^cookiecutter.repo_name^}}"
REDIS_URL="redis://localhost:6379"
DJANGO_SETTINGS_MODULE="{{ cookiecutter.repo_name }}.config.settings.local"
DJANGO_SETTINGS_MODULE="{{^ cookiecutter.repo_name ^}}.config.settings.local"
DJANGO_SECRET_KEY="!!!! Change me !!!!"
DJANGO_DEBUG=True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
"import/resolver": {
"alias": {
"map": [
["@", "./{{cookiecutter.repo_name}}/static_source"],
["@", "./{{^cookiecutter.repo_name^}}/static_source"],
],
},
"node": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
runs-on: ubuntu-latest{% endraw %}
env:
DATABASE_URL: "psql://postgres:postgres@localhost/postgres"
DJANGO_SETTINGS_MODULE: "{{cookiecutter.repo_name}}.config.settings.test"
DJANGO_SETTINGS_MODULE: "{{^cookiecutter.repo_name^}}.config.settings.test"
DJANGO_SECRET_KEY: "!!!! Change me !!!!"

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ repos:
hooks:
- id: stylelint
name: stylelint
files: ^{{cookiecutter.repo_name}}/static_source/
files: ^{{^cookiecutter.repo_name^}}/static_source/
types_or: [css, scss]
args: [--report-needless-disables, --report-invalid-scope-disables, --fix, --allow-empty-input]
additional_dependencies:
Expand All @@ -63,7 +63,7 @@ repos:
hooks:
- id: eslint
name: eslint
files: ^{{cookiecutter.repo_name}}/static_source/
files: ^{{^cookiecutter.repo_name^}}/static_source/
types_or: [javascript, ts]
args: [--fix]
additional_dependencies:
Expand All @@ -80,7 +80,7 @@ repos:
- id: tsc
name: tsc
entry: npx tsc --noEmit
files: ^{{cookiecutter.repo_name}}/static_source/
files: ^{{^cookiecutter.repo_name^}}/static_source/
language: system
types_or: [javascript, ts]
pass_filenames: false
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"compounds": [
{
"name": "Debug {{ cookiecutter.project_name_verbose }}",
"name": "Debug {{^ cookiecutter.project_name_verbose ^}}",
"configurations": ["Django", "Vite", "Browser Debug"],
"stopAll": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# {{ cookiecutter.project_name_verbose }}
# {{^ cookiecutter.project_name_verbose ^}}

## Overview
{{ cookiecutter.description }}
{{^ cookiecutter.description ^}}

# Project Structure
This project is divided into 2 major parts: Alpine.js to provide additional front end functionality and a Django backend.
It's the Django server is deployed with precompiled static assets

- `/{{ cookiecutter.project_name }}` - the Django project folder
- `/{{^ cookiecutter.project_name ^}}` - the Django project folder
- `/config` - Project settings, asgi settings, and base urls
- `/home` - Handles home page for django, error endpoint, settings context processor
- `/user` - User related logic, views, models, etc.
Expand Down Expand Up @@ -214,9 +214,9 @@ NOTE: you must be at the project root to run any `./manage.py ...` or `./scripts
### AWS
- Retrieve Media assets from AWS S3:
- Set up and configure the AWS CLI: see <https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html> for instructions
- be sure to set up your AWS config with your {{ cookiecutter.project_name }} credentials: instructions here <https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html>
- make sure a directory exists with the path [project root]/{{ cookiecutter.project_name }}/media
- from the project root run: `aws s3 cp s3://{{ cookiecutter.project_name }}-dev ./{{ cookiecutter.project_name }}/media --recursive` replacing `{{ cookiecutter.project_name }}-dev` with `{{ cookiecutter.project_name }}-prod` or a different s3 bucket name as needed
- be sure to set up your AWS config with your {{^ cookiecutter.project_name ^}} credentials: instructions here <https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html>
- make sure a directory exists with the path [project root]/{{^ cookiecutter.project_name ^}}/media
- from the project root run: `aws s3 cp s3://{{^ cookiecutter.project_name ^}}-dev ./{{^ cookiecutter.project_name ^}}/media --recursive` replacing `{{^ cookiecutter.project_name ^}}-dev` with `{{^ cookiecutter.project_name ^}}-prod` or a different s3 bucket name as needed

## Styleguide

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
ENV PYTHONUNBUFFERED=1
ENV PYTHONHASHSEED=random
ENV DJANGO_SETTINGS_MODULE={{ cookiecutter.repo_name }}.config.settings.prod
ENV DJANGO_SETTINGS_MODULE={{^ cookiecutter.repo_name ^}}.config.settings.prod


FROM node:lts-alpine AS js-deps
Expand Down Expand Up @@ -37,9 +37,9 @@ WORKDIR app

# Install application into container
COPY . .
COPY --from=js-deps /{{ cookiecutter.repo_name }}/static_source ./{{ cookiecutter.repo_name }}/static_source
COPY --from=js-deps /{{^ cookiecutter.repo_name ^}}/static_source ./{{^ cookiecutter.repo_name ^}}/static_source

ENV DJANGO_SETTINGS_MODULE="{{ cookiecutter.repo_name }}.config.settings.prod"
ENV DJANGO_SETTINGS_MODULE="{{^ cookiecutter.repo_name ^}}.config.settings.prod"
RUN DJANGO_AWS_ACCESS_KEY_ID="" \
DJANGO_AWS_SECRET_ACCESS_KEY="" \
DJANGO_AWS_STORAGE_BUCKET_NAME="" \
Expand All @@ -59,4 +59,4 @@ RUN DJANGO_AWS_ACCESS_KEY_ID="" \

# TODO: Set a sensible initial value for workers and threads based on available CPU cores.
# N.b. Gunicorn timeout must be shorter than any upstream timeouts, e.g. the gateway timeout.
CMD gunicorn
CMD gunicorn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fly.toml file generated on 2021-12-28T20:18:42-05:00

app = "{{cookiecutter.repo_name}}"
app = "{{^cookiecutter.repo_name^}}"

kill_signal = "SIGINT"
kill_timeout = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
worker_tmp_dir = "/dev/shm" # noqa
# See https://docs.gunicorn.org/en/stable/design.html#how-many-workers
workers = multiprocessing.cpu_count() * 2 + 1
wsgi_app = "{{cookiecutter.repo_name}}.config.wsgi:application"
wsgi_app = "{{^cookiecutter.repo_name^}}.config.wsgi:application"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.repo_name}}.config.settings.local")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{^cookiecutter.repo_name^}}.config.settings.local")

try:
from django.core.management import execute_from_command_line
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "{{cookiecutter.repo_name}}",
"name": "{{^cookiecutter.repo_name^}}",
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "{{cookiecutter.repo_name}}"
name = "{{^cookiecutter.repo_name^}}"
version = "0.1.0"
description = ""
authors = ["{{cookiecutter.author_name}} <{{cookiecutter.email}}>"]
authors = ["{{^cookiecutter.author_name^}} <{{^cookiecutter.email^}}>"]

[tool.poetry.dependencies]
python = "^3.11"
Expand Down Expand Up @@ -133,8 +133,8 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py311"

[tool.ruff.per-file-ignores]
"{{cookiecutter.repo_name}}/config/settings/*.py" = ["F405"]
"{{cookiecutter.repo_name}}/home/views.py" = ["N802"]
"{{^cookiecutter.repo_name^}}/config/settings/*.py" = ["F405"]
"{{^cookiecutter.repo_name^}}/home/views.py" = ["N802"]
"*tests.py" = ["S105"]
"*tests/*.py" = ["S105"]

Expand Down Expand Up @@ -171,7 +171,7 @@ ignore_errors = true
omit = [
"*/migrations/*",
"manage.py",
"{{cookiecutter.repo_name}}/config/*",
"{{^cookiecutter.repo_name^}}/config/*",
"**/tests.py",
]

Expand All @@ -190,7 +190,7 @@ use_gitignore=true
env_files = [".env", ".env.example"]
python_files = ["tests.py", "test_*.py", "*_tests.py"]
# https://pytest-django.readthedocs.io/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db
addopts = ["--reuse-db", "--ds={{cookiecutter.repo_name}}.config.settings.test"]
addopts = ["--reuse-db", "--ds={{^cookiecutter.repo_name^}}.config.settings.test"]
markers = ["integration"]

[tool.cruft]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ previewsEnabled: true
previewsExpireAfterDays: 5
services:
- type: web
name: {{cookiecutter.repo_name}}
name: {{^cookiecutter.repo_name^}}
env: python
previewPlan: starter
healthCheckPath: /
Expand All @@ -15,30 +15,30 @@ services:
- key: DJANGO_SECRET_KEY
generateValue: true
- key: DJANGO_SETTINGS_MODULE
value: "{{cookiecutter.repo_name}}.config.settings.prod"
value: "{{^cookiecutter.repo_name^}}.config.settings.prod"
- key: DJANGO_ALLOWED_HOSTS
fromService:
type: web
envVarKey: RENDER_EXTERNAL_HOSTNAME
name: {{cookiecutter.repo_name}}
name: {{^cookiecutter.repo_name^}}
- key: DJANGO_DEBUG
value: false
- key: DATABASE_URL
fromDatabase:
name: {{cookiecutter.repo_name}}-db
name: {{^cookiecutter.repo_name^}}-db
property: connectionString
- key: SENTRY_ENVIRONMENT
fromService:
type: web
envVarKey: RENDER_SERVICE_NAME
name: {{cookiecutter.repo_name}}
name: {{^cookiecutter.repo_name^}}
- key: SENTRY_RELEASE
fromService:
type: web
envVarKey: RENDER_GIT_COMMIT
name: {{cookiecutter.repo_name}}
name: {{^cookiecutter.repo_name^}}
- key: DJANGO_AWS_STORAGE_BUCKET_NAME
value: {{cookiecutter.repo_name}}
value: {{^cookiecutter.repo_name^}}
- key: DJANGO_AWS_ACCESS_KEY_ID
fromService:
type: web
Expand Down Expand Up @@ -95,9 +95,9 @@ services:


databases:
- name: {{cookiecutter.repo_name}}-db
- name: {{^cookiecutter.repo_name^}}-db
previewPlan: starter
databaseName: {{cookiecutter.repo_name}} # optional (Render may add a suffix)
databaseName: {{^cookiecutter.repo_name^}} # optional (Render may add a suffix)
ipAllowList: [] # optional (defaults to allow all)

envVarGroups:
Expand All @@ -106,4 +106,4 @@ envVarGroups:
- key: SENTRY_DSN
sync: false
- key: SENTRY_PROJECT
value: {{cookiecutter.repo_name}}
value: {{^cookiecutter.repo_name^}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ echo "Setting up for a GRRRRREAT DJANGO PROJECT"
thisdir="${0%/*}"


echo "Making Virtual Environment for {{cookiecutter.repo_name}}"
export ENV_NAME="{{cookiecutter.repo_name}}"
echo "Making Virtual Environment for {{^cookiecutter.repo_name^}}"
export ENV_NAME="{{^cookiecutter.repo_name^}}"

cp $thisdir/../.env.example $thisdir/../.env;
export DJANGO_SETTINGS_MODULE=$ENV_NAME.config.settings.local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ PATCH_NAME="$PROJECT_NAME"_"$PATCH_COMMIT"".diff"
PATCH_TMP_PATH="/tmp/""$PATCH_NAME"
git diff "$BASE_COMMIT" "$PATCH_COMMIT" > "$PATCH_TMP_PATH"

sed -i 's/'"$PROJECT_NAME"'/{{cookiecutter.repo_name}}/g' "$PATCH_TMP_PATH"
sed -i 's/'"$PROJECT_NAME"'/{{^cookiecutter.repo_name^}}/g' "$PATCH_TMP_PATH"

mv "$PATCH_TMP_PATH" ../django-hydra/
echo "Patch created successfully!"
pushd ../django-hydra/
git apply --ignore-space-change --ignore-whitespace --directory=\{\{cookiecutter.repo_name\}\} "$PATCH_NAME" --reject --index
git apply --ignore-space-change --ignore-whitespace --directory=\{\{\^cookiecutter.repo_name\^\}\} "$PATCH_NAME" --reject --index
if [ $? -eq 0 ]
then
rm "$PATCH_NAME"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash


export ENV_NAME="{{cookiecutter.repo_name}}"
export ENV_NAME="{{^cookiecutter.repo_name^}}"

dropdb $ENV_NAME
heroku pg:pull DATABASE_URL $ENV_NAME --app $ENV_NAME-development
Expand Down
Loading