Skip to content

Commit

Permalink
Merge pull request #9 from Brown-University-Library/update-install-in…
Browse files Browse the repository at this point in the history
…structions

updates install instructions to use `uv`
  • Loading branch information
birkin authored Nov 23, 2024
2 parents 56b0bc3 + e9261c9 commit ccefc28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ 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])
- 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`.
- 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
Expand All @@ -27,23 +28,21 @@ $ 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]: <https://docs.astral.sh/uv/getting-started/installation/>
[old]: <https://github.com/Brown-University-Library/django_template_42_project/tree/56b0bc3bc2211e50c418dbed7b588c2092dcc9e5>

---

# stuff to try
Expand All @@ -61,7 +60,7 @@ That's it!

- Try <http://127.0.0.1:8000/version/>. 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.
Expand Down
8 changes: 8 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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()

0 comments on commit ccefc28

Please sign in to comment.