Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
version: 2
enable-beta-ecosystems: true
updates:
- package-ecosystem: "pip"
- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "daily"

ignore:
- dependency-name: "*"
update-types:
- version-update:semver-patch
- version-update:semver-minor
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
reviewers:
- "python-discord/devops"
11 changes: 8 additions & 3 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Python Dependencies
uses: HassanAbouelela/actions/setup-python@setup-python_v1.6.0
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python_version: '3.11'
enable-cache: true
cache-dependency-glob: "uv.lock"
activate-environment: true

- name: Install dependencies
run: uv sync --frozen --group lint --group test

# Start the database early to give it a chance to get ready before
# we start running tests.
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ repos:
- id: ruff
name: ruff
description: This hook runs ruff within our project's environment.
entry: poetry run ruff check --force-exclude
entry: uv run ruff check --force-exclude
language: system
types: [python]
39 changes: 28 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,40 @@
# update the contributor guide, which can be found at
# pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md
# Thank you!
FROM ghcr.io/owl-corp/python-poetry-base:3.11-slim
ARG python_version=3.11-slim

# Allow service to handle stops gracefully
STOPSIGNAL SIGQUIT
FROM python:$python_version AS builder
COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /bin/

# Copy the project files into working directory
WORKDIR /app
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy

# Install project dependencies with build tools available
WORKDIR /build

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-dev

# Install project dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install --only main
FROM python:$python_version

# Allow service to handle stops gracefully
STOPSIGNAL SIGQUIT

# Set Git SHA environment variable
ARG git_sha="development"
ENV GIT_SHA=$git_sha

# Install dependencies from build cache
# .venv not put in /app so that it doesn't conflict with the dev
# volume we use to avoid rebuilding image every code change locally
COPY --from=builder /build /build
COPY --from=builder /bin/uv /bin/uv
ENV PATH="/build/.venv/bin:$PATH"

# Copy the source code in last to optimize rebuilding the image
WORKDIR /app
COPY . .

# Set dummy variables so collectstatic can load settings.py
Expand All @@ -31,15 +48,15 @@ RUN \
SECRET_KEY=dummy_value \
DATABASE_URL=postgres://localhost \
METRICITY_DB_URL=postgres://localhost \
poetry run python manage.py collectstatic --noinput --clear
uv run python manage.py collectstatic --noinput --clear

# Build static files if we are doing a static build
ARG STATIC_BUILD=false
RUN if [ $STATIC_BUILD = "TRUE" ] ; \
then SECRET_KEY=dummy_value poetry run python manage.py distill-local build --traceback --force ; \
then SECRET_KEY=dummy_value uv run python manage.py distill-local build --traceback --force ; \
fi

ENTRYPOINT ["poetry", "run"]
ENTRYPOINT ["uv", "run"]
CMD ["gunicorn", "--preload", "-b", "0.0.0.0:8000", \
"pydis_site.wsgi:application", "-w", "2", "--statsd-host", \
"graphite.default.svc.cluster.local:8125", "--statsd-prefix", "site", \
Expand Down
1,328 changes: 0 additions & 1,328 deletions poetry.lock

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ With at least the site running in Docker already (see the previous section on ho
<div class="card-content">
Notice that the bot is started as a module. There are several ways to do so:
<ul>
<li>Through the command line, inside the bot directory, with either <code>poetry run task start</code>, or directly <code>python -m bot</code>.</li>
<li>Through the command line, inside the bot directory, with either <code>uv run task start</code>, or directly <code>python -m bot</code>.</li>
<li>If using PyCharm, enter <code>Edit Configurations</code> and set everything according to this image: <img src="/static/images/content/contributing/pycharm_run_module.png"></li>
<li>If using Visual Studio Code, set the interpreter to the poetry environment you created. In <code>launch.json</code> create a new Python configuration, and set the name of the program to be run to <code>bot</code>. VSC will correctly run it as a module.</li>
<li>If using Visual Studio Code, set the interpreter to the uv environment you created. In <code>launch.json</code> create a new Python configuration, and set the name of the program to be run to <code>bot</code>. VSC will correctly run it as a module.</li>
</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ This page will focus on the quickest steps one can take, with mentions of altern
Below are the dependencies you **must** have installed to get started with the bot.

1. Make sure you have [Python 3.12](https://www.python.org/downloads/) installed. It helps if it is your system's default Python version.
1. [Install Poetry](https://github.com/python-poetry/poetry#installation).
1. [Install the project's dependencies](../installing-project-dependencies).
1. Docker.
2. [Install uv](https://github.com/astral-sh/uv#installation).
3. [Install the project's dependencies](../installing-project-dependencies).
4. Docker.

<div class="card">
<button type="button" class="card-header collapsible">
Expand Down Expand Up @@ -87,7 +87,7 @@ Other values will be added to your `.env` over time as you need to interact with
#### .env.server
All server related configuration values are saved in this file, which also needs to be at the root directory of the project.

We provide a script to automatically generate a server config.
We provide a script to automatically generate a server config.
**Note**: The script **only** works with servers created with the template mentioned above.

If you want to setup the bot from an existing guild read out [manual configuration guide](../bot-extended-configuration-options#manual-constants-configuration). This is far more complicated and time consuming.
Expand All @@ -96,7 +96,7 @@ Running the below command will use the `BOT_TOKEN` and `GUILD_ID` from the `.env

**Note**: This script will overwrite the `.env.server` file. We suggest you put any configuration not generated by this script in to `.env` instead
```shell
$ poetry run task configure
$ uv run task configure
```

Once the script has finished running, you'll notice the creation of a new file called `.env.server` at your project's root directory.
Expand Down Expand Up @@ -163,7 +163,7 @@ Even if you run the bot through Docker, you might want to [setup a development e
### Lint before you push
As mentioned in the [contributing guidelines](../contributing-guidelines), you should make sure your code passes linting for each commit you make.

For ease of development, you can install the pre-commit hook with `poetry run task precommit`, which will check your code every time you try to commit it.
For ease of development, you can install the pre-commit hook with `uv run task precommit`, which will check your code every time you try to commit it.
For that purpose, even if you run the bot through Docker, you might want to [setup a development environment](../bot-extended-configuration-options#setting-up-a-development-environment), as otherwise the hook installation will fail.

### Issues?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,8 @@ You should have already cloned your fork as described in [**Cloning a Repository
---

```shell
$ poetry install
$ poetry run task precommit
$ uv sync
$ uv run task precommit
```

---

## Installing dependencies with PyCharm

1. Load up your project in PyCharm.
2. Go to the Project Settings by clicking `File`, then `Settings...`. Alternatively, use the shortcut key: `Ctrl+Alt+S` (`command+comma` on Mac OS).
3. Install the [poetry plugin](https://plugins.jetbrains.com/plugin/14307-poetry).
4. Navigate to `Project Interpreter`, then click the gear icon and click `Add`.<br/>
![PyCharm Interpreter Settings](/static/images/content/contributing/pycharm_interpreter.png)<br/>
5. Click `Poetry Environment`, then click `OK`.<br/>
![PyCharm Poetry Environment](/static/images/content/contributing/pycharm_poetry.png)<br/>
6. PyCharm will automatically install the packages required into a virtual environment.<br/>
![PyCharm Project Interpreter](/static/images/content/contributing/pycharm_poetry_success.png)
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ If the linter complains, the commit is aborted so that you can fix the linting e
That way, you never commit the problematic code in the first place!

Please refer to the project-specific documentation to see how to setup and run those tools.
In most cases, you can install pre-commit using `poetry run task precommit`, and lint using `poetry run task lint` in the console.
In most cases, you can install pre-commit using `uv run task precommit`, and lint using `uv run task lint` in the console.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Remember to ensure that you have read the [contributing guidelines](../contribut

### Requirements
- [Python 3.13.*](https://www.python.org/downloads/)
- [Poetry](https://github.com/python-poetry/poetry#installation)
- [uv](https://github.com/astral-sh/uv#installation)
- [Git](https://git-scm.com/downloads)
- [Windows Installer](https://git-scm.com/download/win)
- [MacOS Installer](https://git-scm.com/download/mac) or `brew install git`
Expand Down Expand Up @@ -108,10 +108,10 @@ If you get any Docker related errors, reference the [Possible Issues](../docker#
{: .notification .is-warning }

## Run on the host
After installing project dependencies use the poetry command `poetry run task start` in the project root.
After installing project dependencies use the uv command `uv run task start` in the project root.

```shell
$ poetry run task start
$ uv run task start
```
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ You should have already forked the [`site`](https://github.com/python-discord/si
### Requirements

- [Python 3.11](https://www.python.org/downloads/)
- [Poetry](https://python-poetry.org/docs/#installation)
- `pip install poetry`
- [uv](https://github.com/astral-sh/uv#installation)
- [Git](https://git-scm.com/downloads)
- [Windows](https://git-scm.com/download/win)
- [MacOS](https://git-scm.com/download/mac) or `brew install git`
Expand Down Expand Up @@ -114,10 +113,10 @@ If you're not using Docker, then use [pg_ctl](https://www.postgresql.org/docs/cu

### Webserver

Starting the webserver is done simply through poetry:
Starting the webserver is done simply through uv:

```shell
poetry run task start
uv run task start
```

---
Expand Down
74 changes: 39 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
[tool.poetry]
[project]
name = "site"
version = "1.0.0"
description = "The project responsible for maintaining our website and all of its subdomains."
authors = ["Python Discord <[email protected]>"]
authors = [{ name = "Python Discord", email = "[email protected]" }]
requires-python = "==3.11.*"
license = "MIT"
package-mode = false

[tool.poetry.dependencies]
python = "3.11.*"

django = "5.1.9"
django-distill = "3.2.7"
django-environ = "0.11.2"
django-filter = "25.1"
django-prometheus = "2.3.1"
django-simple-bulma = "2.6.0"
djangorestframework = "3.16.0"
gunicorn = "23.0.0"
httpx = "0.28.1"
markdown = "3.8"
psycopg = {extras = ["binary"], version = "3.2.6"}
pyjwt = {version = "2.10.1", extras = ["crypto"]}
pymdown-extensions = "10.14.3"
python-frontmatter = "1.1.0"
pyyaml = "6.0.2"
sentry-sdk = "2.22.0"
whitenoise = "6.9.0"

[tool.poetry.group.dev.dependencies]
python-dotenv = "1.1.0"
taskipy = "1.14.1"
ruff = "0.9.10"
dependencies = [
"django==5.1.9",
"django-distill==3.2.7",
"django-environ==0.11.2",
"django-filter==25.1",
"django-prometheus==2.3.1",
"django-simple-bulma==2.6.0",
"djangorestframework==3.16.0",
"gunicorn==23.0.0",
"httpx==0.28.1",
"markdown==3.8",
"psycopg[binary]==3.2.6",
"pyjwt[crypto]==2.10.1",
"pymdown-extensions==10.14.3",
"python-frontmatter==1.1.0",
"pyyaml==6.0.2",
"sentry-sdk==2.22.0",
"whitenoise==6.9.0",
]

[tool.poetry.group.lint.dependencies]
pre-commit = "4.2.0"
[dependency-groups]
dev = [
"python-dotenv==1.1.0",
"taskipy==1.14.1",
"ruff==0.9.10",
]
lint = ["pre-commit==4.2.0"]
test = ["coverage==7.8.0"]

[tool.poetry.group.test.dependencies]
coverage = "7.8.0"
[tool.uv]
package = false
default-groups = [
"dev",
"lint",
"test",
]

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
target-version = "py311"
Expand Down
4 changes: 2 additions & 2 deletions static-builds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ They are split into two parts:
To get started with building, you can use the following command:

```shell
poetry install
uv sync
python -m pip install httpx==0.19.0
poetry run task static
uv run task static
```

Alternatively, you can use the [Dockerfile](/Dockerfile) and extract the build.
Expand Down
Loading
Loading