From 57ae551f820f1064bf0160033d1e8a18686cf60c Mon Sep 17 00:00:00 2001 From: Birkin James Diana Date: Fri, 1 Nov 2024 08:00:04 -0400 Subject: [PATCH 1/6] updates instructions to use `uv`. --- README.md | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 61ba124..e4ec540 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ This is a template for new django projects -- to standardize on some nice featur Notes about the install instructions... -- The install-instructions below assume a unix-like environment (ie Mac, Linux, or Windows Subsystem for Linux (WSL)). +- The install-instructions below assume: + - a unix-like environment (ie Mac, Linux, or Windows Subsystem for Linux (WSL)). + - you've installed `uv` ([link][uv_link]) - The install-instructions below reference `x_project_stuff`, `x_project`, and `x_app`. In all cases replace with the name of your project, like: `isbn_api_project_stuff`, `isbn_api_project`, and `isbn_api_app`. -- You'll also need to update, in the install-instructions, the path to the version of python you're using. Sensible suggestion: use the version of python used by the oldest server on which you'll be running the code. (Django 4.2x requires at least Python 3.8.) - The `update_project_and_app_references.py` script ([link](https://github.com/Brown-University-Library/django_template_42_project/blob/main/update_project_and_app_references.py)) deletes the cloned `.git` directory (in addition to its main purpose to rename the project). Why? So you don't accidentally start building away and commit to the template repo. After this installation, creating a new git repo is one of the first things you should do. -- When you run the `pip istall ...` command, you may get a message about upgrading pip, with instructions. That's always a good idea, but not necessary for this install. -- When you start the webapp via `runserver`, you'll get a message that there are migrations that need to be run, with instructions. You can go ahead and do that, or do it later (this is a one-time thing). +- When you start the webapp via `runserver`, you'll get a message that there are migrations that need to be run, with instructions. You can go ahead and do that, or do it later. ```bash ## setup directories @@ -27,23 +27,20 @@ $ mkdir ./DBs $ git clone https://github.com/Brown-University-Library/django_template_42_project.git ## update project-name (line below is a single long line; clarifying in case it wraps) -$ /path/to/python3 ./django_template_42_project/update_project_and_app_references.py --target_dir "./django_template_42_project/" --new_project_name "x_project" --new_app_name "x_app" +$ uv run --python 3.8 ./django_template_42_project/update_project_and_app_references.py --target_dir "./django_template_42_project/" --new_project_name "x_project" --new_app_name "x_app" ## setup the envar-settings $ cd ./x_project/ $ cp ./config/dotenv_example_file.txt ../.env -## setup the virtual-environment -$ /path/to/python3 -m venv ../venv -$ source ../venv/bin/activate -(venv) $ pip install pip-tools -(venv) $ pip-compile ./config/requirements/requirements_base.in -(venv) $ pip install -r ./config/requirements/requirements_base.txt -(venv) $ python ./manage.py runserver +## run the app +$ uv run ./manage.py runserver ``` That's it! +[uv_link]: + --- # stuff to try @@ -61,7 +58,7 @@ That's it! - Try . Once you `git init`, `git add --all`, and `git commit -am "initial commit"`, it'll show the branch and commit -- super-handy for dev and prod confirmations. -- Try `(venv) $ python ./manage.py test`. There are two simple tests that should pass. (Requires venv to be sourced.) +- Try `$ uv run ./manage.py test`. There are two simple tests that should pass. - Check out the logs (`project_stuff/logs/`). The envar log-level is `DEBUG`, easily changed. On the servers that should be `INFO` or higher, and remember to rotate them, not via python's log-rotate -- but by the server's log-rotate. From b4b15109bcb504110b71c0be1c859d3dd0381f34 Mon Sep 17 00:00:00 2001 From: Birkin James Diana Date: Sat, 23 Nov 2024 08:41:17 -0500 Subject: [PATCH 2/6] updates script-requirements. --- manage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manage.py b/manage.py index eb34647..9cd6e38 100755 --- a/manage.py +++ b/manage.py @@ -1,7 +1,7 @@ ## recently adopted python standard. ## Allows, for development, to run the app via `uv run ./manage.py runserver`, with no venv. # /// script -# requires-python = "~=3.8.0" +# requires-python = "~=3.8.0,<4" # dependencies = [ # "django~=4.2.0", # "python-dotenv~=1.0.0", From 2c8374c0612d4b4f472419d94b583c6c6e1c8ec2 Mon Sep 17 00:00:00 2001 From: Birkin James Diana Date: Sat, 23 Nov 2024 08:44:18 -0500 Subject: [PATCH 3/6] updates uv-link. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e4ec540..605799b 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ $ uv run ./manage.py runserver That's it! -[uv_link]: +[uv_link]: --- From ba2f6c614bf1bbc475d47f036273c65effd9ed33 Mon Sep 17 00:00:00 2001 From: Birkin James Diana Date: Sat, 23 Nov 2024 08:54:19 -0500 Subject: [PATCH 4/6] adds pip-based link to readme. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 605799b..3e2972c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Notes about the install instructions... - The install-instructions below assume: - a unix-like environment (ie Mac, Linux, or Windows Subsystem for Linux (WSL)). - you've installed `uv` ([link][uv_link]) + - For now, here's a link to an [older version][old] of the repo that uses `pip`-based setup instructions. When improvements are made to this repo, this link will be removed. - The install-instructions below reference `x_project_stuff`, `x_project`, and `x_app`. In all cases replace with the name of your project, like: `isbn_api_project_stuff`, `isbn_api_project`, and `isbn_api_app`. - The `update_project_and_app_references.py` script ([link](https://github.com/Brown-University-Library/django_template_42_project/blob/main/update_project_and_app_references.py)) deletes the cloned `.git` directory (in addition to its main purpose to rename the project). Why? So you don't accidentally start building away and commit to the template repo. After this installation, creating a new git repo is one of the first things you should do. - When you start the webapp via `runserver`, you'll get a message that there are migrations that need to be run, with instructions. You can go ahead and do that, or do it later. @@ -40,6 +41,7 @@ $ uv run ./manage.py runserver That's it! [uv_link]: +[old]: --- From 8950ee4002c514f95083452c50522d2ba2425c0b Mon Sep 17 00:00:00 2001 From: Birkin James Diana Date: Sat, 23 Nov 2024 09:12:50 -0500 Subject: [PATCH 5/6] updates manage.py python constraint. --- manage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manage.py b/manage.py index 9cd6e38..44f68ea 100755 --- a/manage.py +++ b/manage.py @@ -1,7 +1,7 @@ ## recently adopted python standard. ## Allows, for development, to run the app via `uv run ./manage.py runserver`, with no venv. # /// script -# requires-python = "~=3.8.0,<4" +# requires-python = "~=3.8.0,<3.9" # dependencies = [ # "django~=4.2.0", # "python-dotenv~=1.0.0", From e9261c92121a90efc1c7336e9c1a926bc1892a42 Mon Sep 17 00:00:00 2001 From: Birkin James Diana Date: Sat, 23 Nov 2024 09:51:48 -0500 Subject: [PATCH 6/6] prints out python and django versions on startup. --- manage.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/manage.py b/manage.py index 44f68ea..e52507b 100755 --- a/manage.py +++ b/manage.py @@ -1,7 +1,7 @@ ## recently adopted python standard. ## Allows, for development, to run the app via `uv run ./manage.py runserver`, with no venv. # /// script -# requires-python = "~=3.8.0,<3.9" +# requires-python = "~=3.8.0" # dependencies = [ # "django~=4.2.0", # "python-dotenv~=1.0.0", @@ -17,6 +17,8 @@ import os import sys +import django # for the "in case you're curious about versions" code + def main(): """Run administrative tasks.""" @@ -33,4 +35,10 @@ def main(): if __name__ == '__main__': + ## in case you're curious about versions -- feel free to comment out + if os.environ.get('RUN_MAIN') != 'true': + major, minor, micro = sys.version_info[:3] + print(f'using python version, ``{major}.{minor}.{micro}``') + print(f'using django version, ``{django.get_version()}``') + main()