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

Upgrade python to 3.11 #1030

Merged
merged 11 commits into from
Oct 24, 2024
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- uses: Gr1N/setup-poetry@v8
with:
poetry-version: 1.8.2
poetry-version: 1.8.3
- name: Install Poetry
run: |
poetry config virtualenvs.create false &&
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- uses: Gr1N/setup-poetry@v8
with:
poetry-version: 1.5.0
poetry-version: 1.8.3
- name: Install Poetry
run: |
poetry config virtualenvs.create false &&
Expand Down
16 changes: 14 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default_language_version:
node: 18.4.0
python: python3.8
python: python3.11
repos:
- repo: https://github.com/python/black
rev: 24.4.0
Expand Down Expand Up @@ -45,7 +45,19 @@ repos:
- [email protected]
- [email protected]
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.16.0
rev: 1.20.0
hooks:
- id: django-upgrade
args: [--target-version, '4.2'] # Replace with Django version
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
- repo: https://github.com/python-poetry/poetry
rev: '1.8.3' # keep version in sync with version installed in the Dockerfile
hooks:
- id: poetry-check
- id: poetry-lock
# Never update dependencies and only run on changes to pyproject.toml
args: [--no-update]
files: ^pyproject.toml$
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.6
3.11
Copy link
Member

Choose a reason for hiding this comment

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

👌 it's nice that we are not locking down to a specific patch version. This will capture whatever 3.11.x version is availble.

8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ RUN npm run build:prod
# ones becase they use a different C compiler. Debian images also come with
# all useful packages required for image manipulation out of the box. They
# however weight a lot, approx. up to 1.5GiB per built image.
FROM python:3.8 as production
FROM python:3.11-bookworm as production

ARG POETRY_INSTALL_ARGS="--no-dev"

# IMPORTANT: Remember to review .circleci/config.yml when upgrading
ARG POETRY_VERSION=1.8.2
ARG POETRY_VERSION=1.8.3

# Install dependencies in a virtualenv
ENV VIRTUAL_ENV=/venv
Expand All @@ -37,8 +37,8 @@ WORKDIR /app
# * PATH - Make sure that Poetry is on the PATH, along with our venv
# * PYTHONUNBUFFERED - This is useful so Python does not hold any messages
# from being output.
# https://docs.python.org/3.8/using/cmdline.html#envvar-PYTHONUNBUFFERED
# https://docs.python.org/3.8/using/cmdline.html#cmdoption-u
# https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONUNBUFFERED
# https://docs.python.org/3.11/using/cmdline.html#cmdoption-u
# * DJANGO_SETTINGS_MODULE - default settings used in the container.
# * PORT - default port used. Please match with EXPOSE so it works on Dokku.
# Heroku will ignore EXPOSE and only set PORT variable. PORT variable is
Expand Down
110 changes: 66 additions & 44 deletions docs/upgrading.md
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done some clean up on this file. We don't need to keep the notes about previous Wagtail versions.

Original file line number Diff line number Diff line change
Expand Up @@ -106,50 +106,6 @@ As well as testing the critical paths, these areas of functionality should be ch

---

#### Wagtail v3 Upgrade notes

When the site was upgraded to Wagtail v3 the original issue at v2.15 & v2.16 noted above was fixed.

Wagtail 3 introduced a lot of Javascript generated editor template "furniture" such as the admin side bar. To accommodate hiding the search input for Student accounts the following has been implemented.

- New wagtail_hooks [global_admin_css](https://github.com/torchbox/rca-wagtail-2019/blob/7e5bb3c9201d8a7b7fa6e0288d4bee0ba1c79f52/rca/people/wagtail_hooks.py#L21) and [global_admin_js](https://github.com/torchbox/rca-wagtail-2019/blob/7e5bb3c9201d8a7b7fa6e0288d4bee0ba1c79f52/rca/people/wagtail_hooks.py#L13)
- Wagtail [Base.html](https://github.com/torchbox/rca-wagtail-2019/blob/support/wagtail-3.0-upgrade/rca/account_management/templates/wagtailadmin/base.html) override. Specifically [here](https://github.com/torchbox/rca-wagtail-2019/blob/7e5bb3c9201d8a7b7fa6e0288d4bee0ba1c79f52/rca/account_management/templates/wagtailadmin/base.html#L12) Which adds a new data-attribute for the hooks above to operate on.

Wagtail 3 introduced a new [FieldPanel `permission` parameter](https://docs.wagtail.org/en/stable/reference/pages/panels.html#wagtail.admin.panels.FieldPanel.permission) which has been use on many fields of the [StudentPage](https://github.com/torchbox/rca-wagtail-2019/blob/support/wagtail-3.0-upgrade/rca/people/models.py#L777) content_panels.

Additionally there are some Custom Panels which help to add the `permission` parameter to child FieldPanels and control panel visibility in general.

- [StudentPageInlinePanel](https://github.com/torchbox/rca-wagtail-2019/blob/7e5bb3c9201d8a7b7fa6e0288d4bee0ba1c79f52/rca/people/utils.py#L72), including the custom templates at the following locations:
- `rca/people/templates/admin/panels/student_page_inline_panel.html`
- `rca/people/templates/admin/panels/student_page_inline_panel_child.html`
- [StudentPagePromoteTab](https://github.com/torchbox/rca-wagtail-2019/blob/7e5bb3c9201d8a7b7fa6e0288d4bee0ba1c79f52/rca/people/utils.py#L86)
- [StudentPageSettingsTab](https://github.com/torchbox/rca-wagtail-2019/blob/7e5bb3c9201d8a7b7fa6e0288d4bee0ba1c79f52/rca/people/utils.py#L107)

`use_json_field` argument added to `StreamField` (creates new migration files)

---

#### Wagtail v4 Upgrade notes

- Removed `wagtail_redirect_importer` as it's now part of Wagtail since version `2.10`

---

#### Wagtail v5 Upgrade notes

- Added `index.AutocompleteField` entries for the relevant fields on the model’s `search_fields` definition, as the old `SearchField("some_field", partial_match=True)` format is no longer supported.
- Changes to header CSS classes in `ModelAdmin` templates
- `wagtailsearch.Query` has been moved to `wagtail.contrib.search_promotions`
- `status` classes are now `w-status`

---

#### Wagtail v6 Upgrade notes

- `StreamField` no longer requires `use_json_field=True`

---

## Overridden core Wagtail templates

The following templates are overridden and should be checked for changes when upgrading Wagtail:
Expand Down Expand Up @@ -183,3 +139,69 @@ This is the path to the Django template which is used to display the “password
```python
WAGTAIL_PASSWORD_REQUIRED_TEMPLATE = "patterns/pages/wagtail/password_required.html"
```

## Python version upgrade

We don't generally upgrade python versions until a new LTS/Major version is released and has been stable for a while. We prefer to be running a more stable version of python.

If you are upgrading python, you should check the following python version references are updated:

- The `python` key in the `tool.poetry.dependencies` section of the `pyproject.toml` file.
- The `python` key in the pre-commit configuration file `.pre-commit-config.yaml`.
- The `python` image tag in the `Dockerfile`/s.
- Any references to the python version in documentation.
- Any references to the python version in the CI configuration file `gitlab-ci.yaml`.

### Pyupgrade tool

If you are upgrading python. There is a development tool available to help with modernising the codebase. This is installed as part of the poetry development dependencies.

To run the tool, use the following command:

```bash
git ls-files -z -- '*.py' | xargs -0 pyupgrade [python-version-arg]
```

Where `[python-version-arg]` is the version of python you are upgrading to.

To view the available version arguments, use the following command:

```bash
pyupgrade --help
```

### Pre-commit + Pyupgrade

The pyupgrade tool is run as a step in the pre-commit configuration. This will help you to use the modern syntax as you work on the codebase.

You can manually run the pre-commit checks on `*.py` files using the following command:

```bash
git ls-files -z -- '*.py' | xargs -0 | pre-commit run --files
```

## Django upgrades

If you are upgrading Django. There is a development tool available to help with modernising the codebase. This is installed as part of the poetry development dependencies.

### Django upgrade tool

If you are upgrading django. There is a development tool available to help with modernising the codebase. This is installed as part of the poetry development dependencies.

To run the tool, use the following command:

```bash
git ls-files -z -- '*.py' | xargs -0 django-upgrade --target-version [django-version-arg]
```

Where `[django-version-arg]` is the version of Django you are upgrading to.

### Pre-commit + django-upgrade

The django-upgrade tool is run as a step in the pre-commit configuration. This will help you to use the modern syntax as you work on the codebase.

You can manually run the pre-commit checks on `*.py` files using the following command:

```bash
git ls-files -z -- '*.py' | xargs -0 | pre-commit run --files
```
2 changes: 1 addition & 1 deletion fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Process .env file
if os.path.exists(".env"):
with open(".env", "r") as f:
with open(".env") as f:
for line in f.readlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
Expand Down
Loading
Loading