-
Notifications
You must be signed in to change notification settings - Fork 0
Add a CLI Wrapper for Django Project Initialization #75
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
base: main
Are you sure you want to change the base?
Conversation
065b001 to
6b6436b
Compare
|
I noted I need to update the project CI properly. I'll fix it some time next week. |
3da0029 to
37ca747
Compare
|
Question: Do you need to replace Could you just wrap it in your script then perform additional steps after |
This change adds a simple wrapper for startproject command of django. It generate the project based on the config file.
After this change, the path to the project can be configured in the config file. If the path doesn't exists it creates the path. If the path exists, it prompts the user to confirm a fresh start or abort.
a3f441b to
decc714
Compare
|
@a-musing-moose Thanks for the review! My initial idea was to use Jinja2 for rendering settings dynamically, but I agree that sticking with |
decc714 to
e083e3c
Compare
| from pathlib import Path | ||
|
|
||
| import typer | ||
| import yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick (non-blocking): Can we use toml instead?
I have a pet peeve about yaml - I find it hard to format correctly for some reason. Toml is a simpler standard, we already use it (pyproject.toml) and as an added bonus - reading toml is built into recent versions of Python: https://docs.python.org/3/library/tomllib.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I'll update it.
| license = {text = "BSD-3-Clause"} | ||
| dependencies = [ | ||
| "typer[all]>=0.9.0", | ||
| "jinja2>=3.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I don't think jinja2 is needed any more
If we don't need it - please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops!
| @app.command() | ||
| def fire( | ||
| config_path: Path = typer.Option( | ||
| DEFAULT_CONFIG, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Make this a mandatory argument
The script cannot proceed without a config file. A default for the name of a project for example is never going to be reasonable. So might as well make it a mandatory argument.
|
|
||
| def django_start_project(config): | ||
| """Create a Django project using the specified configuration.""" | ||
| project_name = config["project_name"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Check this is a valid Python package name
Since project_name is used as the package name, it needs to be a valid. We should do some basic checks here to ensure it is:
- a-z, 0-9
- Lowercase
- underscores
-
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
| OUTPUT_DIR = BASE_DIR / "output" | ||
| DEFAULT_CONFIG = BASE_DIR / "sample_config.yml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Remove these defaults.
As already mentioned - I don't think a default config file makes sense. So I also think that the output dir should either be the current working directory or come from the now mandatory config file.
This is being designed as a stand alone script, installed from a wheel using pipx. As such the BASE_DIR as described here might not actually exist as it is being run from inside a pipx virtualenv all by itself.
| "--extension", | ||
| "py,env,sh,toml,yml", | ||
| "--exclude", | ||
| "nothing", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Perhaps a comment here as to why we are using --exclude nothing
jadedarko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if alternatives were considered to a custom wrapper tool?
The first thing that comes to mind is django-cookiecutter, which is a widely used tool that wraps project initiation in a similar way
The ADR should address alternatives like this to avoid people asking the above question at the very least ;)
Agreed - the ADR should cover this. In terms of using cookie-cutter... we could but the intent is that a follow up to what is in here is the addition of "variants". Cookie cutter requires that all possible configures and content are baked into the templates - including/excluding portions of those templates. For me this tips over into unreadable pretty quickly. What I am hoping we can do with our own wrapper script is to avoid that. Details on how are still up for debate - but I can foresee "variants" having their own little config files that can do things like adding lines to the This may all be a tall ask - but I thought it worth exploring. Very much open to suggestions though. |
Description
This PR introduces a CLI wrapper named booster to simplify the process of initializing Django projects:
Key updates
Add CLI Wrapper: Implements a command-line interface (booster) for generating Django projects based on a YAML configuration file.
Dynamic Template Rendering:
django-admin startprojectwith direct rendering of templates using Jinja2.Configuration: Default configuration file is
sample_config.yml.Package Creation:
pyproject.tomlforpipxinstallation..gitignoreentries for build artifacts and output folders.