From 3685f03461947890cb10991a982ff22d2892334a Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 15 Dec 2024 23:00:41 +0000 Subject: [PATCH] uv not pip - online edit of handbook/troggle/trogdjangup.html [PosixPath('/home/philip/expo/expoweb/handbook/troggle/trogdjangup.html')] --- handbook/troggle/trogdjangup.html | 73 +++++++++++++------------------ 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/handbook/troggle/trogdjangup.html b/handbook/troggle/trogdjangup.html index d7dc1ba4d..93889913e 100644 --- a/handbook/troggle/trogdjangup.html +++ b/handbook/troggle/trogdjangup.html @@ -10,9 +10,10 @@

CUCC Expedition Handbook

Upgrading Django for Troggle

Why this used to be difficult

-

Before Django 3.0, when Django was upgraded to a new version things broke across the entire django package, including things which we don't conciously use but are internal dependencies within Django. These were 'the way to do it' when troggle was first written for Django 0.7 in 2006. So upgrading troggle to a new Django version required not just a broad beadth of knowledge across troggle, but also across the entire breadth of django itself. And the error messages are sometimes very unhelpful. This is no longer the case and the Django organisation has a very clear "non-breaking" policy between LTS releases. +

Before Django 3.0, whenever Django was upgraded to a new version things broke across the entire django package, including things which we don't conciously use but are internal dependencies within Django. These were 'the way to do it' when troggle was first written for Django 0.7 in 2006. So upgrading troggle to a new Django version required not just a broad beadth of knowledge across troggle, but also across the entire breadth of django itself. And the error messages are sometimes very unhelpful. This is no longer the case and the Django organisation has a very clear "non-breaking" policy between LTS releases.

Now read Django and Troggle if you haven't already. +

Note that Django 3.2 is out of support since April 2024.

Django versions and update schedule

@@ -132,16 +133,16 @@ troggle test suite. See how to set up a troggle softwa sqlite database browser software very helpful and that you will need to know git.

Important Tricks

-[I. November 2024 we are planning on moving from pip to uv for managing python vitrual environments.]

There are six critical tricks that make everything much, much easier:

    -
  1. Use pip venv or virtualenv to set up a virtual python environment within which you can easily and quickly change the specific releases of python, django, django's dependencies and django plugins. - With a previously created venv py39d32 start it up like this:
    - cd py39d32
    - source bin/activate
    +
  2. Use a virtual python environment within which you can easily and quickly change the specific releases of python, django, django's dependencies and django plugins. + With a previously created envornment .venv start it up like this:
    + + cd ~/expo/troggle
    + source .venv/bin/activate
    python --version
    - cd troggle
    + django-admin
    python manage.py
    python manage.py check -v 3
    @@ -190,10 +191,25 @@ release note. From

    Running troggle before and after a Django migration

      -
    1. ensure that you have the exact version of python installed on your machine as is live for troggle on the server, e.g. do $ sudo apt install python3.7.5. -
    2. create a venv using the version of python to be used.
      We have a script to help you do this in :troggle:venv-trog.sh (but it is fragile and often broken) -
    3. do a clean install of django and troggle. -
    4. check the versions of plugins using pip list -o +
    5. ensure that you have the exact same version of python installed on your machine as is live for troggle on the server, so check the line
      + requires-python = ">=3.11,<3.12"
      + in the file server.toml. +
    6. Copy server.toml on top of pyprojectr.toml and synchronise the environment: uv sync. + +
    7. check the versions of plugins using uv tree +
      (troggle) philip@Mohawk:~/expo/troggle$ uv tree --all-groups
      +Resolved 11 packages in 0.54ms
      +troggle-server v2024.12.1
      +├── beautifulsoup4 v4.11.2 (group: server)
      +│   └── soupsieve v2.6
      +├── coverage v7.6.9 (group: server)
      +├── django v3.2.19 (group: server)
      +│   ├── asgiref v3.8.1
      +│   ├── pytz v2024.2
      +│   └── sqlparse v0.5.3
      +├── piexif v1.1.3 (group: server)
      +├── pillow v9.4.0 (group: server)
      +└── unidecode v1.3.6 (group: server)
    8. open two terminal windows:
    -

    Django dependencies

    -

    You can upgrade the version of python installed within pip venv but not downgrade. So get that first venv installed right. -

    Here is example of installed (Version) and most-recent-available (Latest) verisons of pip installations. -

    Package    Version Latest Type
    ----------- ------- ------ -----
    -Django     2.2.19  3.2    wheel
    -docutils   0.14    0.17   wheel
    - -

    This only gives any output for packages which are not the most recent. To see what is actually installed use -

    $ pip freeze
    -confusable-homoglyphs==3.2.0
    -Django==2.2.19
    -docutils==0.17
    -Pillow==8.2.0
    -pytz==2021.1
    -sqlparse==0.4.1
    -Unidecode==1.2.0
    - -Although the above all work fine, on debian buster we were actually using the standard installs on that version of debian which are older: -
    $ pip freeze
    -confusable-homoglyphs==3.2.0
    -Django==2.2.19
    -docutils==0.14
    -Pillow==5.4.1
    -pytz==2019.1
    -sqlparse==0.2.4
    -Unidecode==1.0.23
    - -

    To upgrade pip istelf, do $ pip install --upgrade pip

    Django database dependencies

    On the expo server we run MariaDB as the database which has its own dependencies. In particular under debian buster we -had to use MariaDB v1.3.10 which was the latest version supported by buster: +had to use MariaDB v1.3.10 which was the latest version supported by Debian buster:

    mysqlclient==1.3.10
     
    which is technically incompatible with Django 2.2 which requires 1.3.13. @@ -255,7 +242,7 @@ This incompatibility is a policy choice by the Django team. Wookey ran the Djang Django just didn't support it because they couldn't spare the effort to test it.

    To run Django's system test suite:

    -

    This is only necessary if we hit a policy-imposed incomatibility, as we did with mysqlclient==1.3.10 . We have only ever had to do this once. +

    This is only necessary if we hit a policy-imposed incompatibility, as we did with mysqlclient==1.3.10 . We have only ever had to do this once.

    Follow the instructions in the "Unit tests" section installed locally at docs/internals/contributing/writing-code/unit-tests.txt, published online at docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/ This involves running git clone on the django source repo to download the tests. We hope we never have to do this again but in case we get incomprehensible bugs in future, we should be prepared to do so.