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

rework to uv and ruff #481

Merged
merged 2 commits into from
Dec 5, 2024
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
7 changes: 4 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install dependencies
run: |
pip install poetry
poetry install
run: uv sync
- name: Run checks
run: make check
env:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ repos:
- repo: local
hooks:
- id: lint
name: flake8 linter check
name: ruff linter check
entry: make lint
language: system
pass_filenames: false
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
7. Checkout Makefile or README.md for commands like `make check` `make lint` `make test`
8. Run tests and linters (`make check`)
9. Commit your changes (`git commit -am 'Added some feature'`)
* "When you install a project, scripts for the flake8 pre-commit hooks are added to the .git folder.
* "When you install a project, scripts for the ruff pre-commit hooks are added to the .git folder.
When you make your first commit, you will see the environment settings for the pre-commit hook displayed
in the terminal. This is normal behavior and will only happen
on your first commit. In general, you will see in the terminal the status of the flake8 check for the pre-commit hook.
on your first commit. In general, you will see in the terminal the status of the ruff check for the pre-commit hook.
In case of linter errors, they will be displayed in the
terminal and abort the commit to fix them. If there are any errors, fix these errors and try to commit again. You can read more about pre-commit hooks [here](https://pre-commit.com/).*
10. Push to the branch (`git push origin my-new-feature`)
Expand Down
5 changes: 2 additions & 3 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
GITHUB_AUTH_CLIENT_ID=<Нужна для авторизации через GitHub>
GITHUB_AUTH_CLIENT_SECRET=<Нужна для авторизации через GitHub>
PYTHON_VERSION=<Желаемая версия Python>
POETRY_VERSION=<Желаемая версия Poetry>
GITHUB_AUTH_TOKEN=<Токен личного доступа из настроек GitHub>
GITHUB_WEBHOOK_TOKEN=<можно сгенерировать командой терминала make secretkey в каталоге проекта или создать самостоятельно>
SECRET_KEY=<можно сгенерировать командой терминала make secretkey в каталоге проекта или создать самостоятельно>
Expand All @@ -94,7 +93,7 @@
Выполните команду:

```bash
poetry run python manage.py dumpdata --indent 2 > db_fixture.json
uv run python manage.py dumpdata --indent 2 > db_fixture.json
```

### Применение фикстуры
Expand All @@ -103,5 +102,5 @@ poetry run python manage.py dumpdata --indent 2 > db_fixture.json
Выполните команду:

```bash
poetry run python manage.py loaddata db_fixture.json
uv run python manage.py loaddata db_fixture.json
```
50 changes: 9 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,20 @@
FROM python:3.11-alpine as builder
FROM python:3.11.5-slim

ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
POETRY_VERSION=1.2.2 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
PATH="$PATH:/root/.local/bin"

RUN apk add --no-cache \
gcc \
musl-dev \
postgresql-dev \
libffi-dev \
openssl-dev \
cargo \
curl \
gettext \
git

RUN curl -sSL https://install.python-poetry.org | python3 - && poetry --version
UV_NO_SYNC=1 \
UV_COMPILE_BYTECODE=1

WORKDIR /usr/local/src/hexlet-friends

COPY . .

RUN poetry install --extras psycopg2-binary --only main

FROM python:3.11-alpine as runner

ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

RUN apk add --no-cache libpq gettext

RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY pyproject.toml uv.lock ./

COPY --from=builder /usr/local/src/hexlet-friends /usr/local/src/hexlet-friends
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
RUN apt-get update && \
apt-get install -y --no-install-recommends make git

RUN chown -R appuser:appgroup /usr/local/src/hexlet-friends

USER appuser

WORKDIR /usr/local/src/hexlet-friends
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
RUN git config --global --add safe.directory "$(pwd)"
RUN uv sync
20 changes: 0 additions & 20 deletions Dockerfile.dev

This file was deleted.

24 changes: 8 additions & 16 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Installing and running the app

You can run the application using both Poetry and Docker.
You can run the application using both uv and Docker.

**Poetry** is setup by the commands:
**uv** is setup by the commands:

**Linux, macOS, Windows (WSL):**

```bash
curl -sSL https://install.python-poetry.org | python3 -
curl -LsSf https://astral.sh/uv/install.sh | sh
```

Details on installing and using the **Poetry** package are available in [official documentation](https://python-poetry.org/docs/).

To install **Poetry** you need **Python 3.7+** use the information from the official website [python.org](https://www.python.org/downloads/)
Details on installing and using the **uv** package are available in [official documentation](https://docs.astral.sh/uv/getting-started/installation/).

To install **Docker**, use the information from the official website [docs.docker.com](https://docs.docker.com/engine/install/)

Expand All @@ -27,18 +25,12 @@ git clone https://github.com/Hexlet/hexlet-friends
cd hexlet-friends
```

Installing dependencies if you use **Poetry**
Installing dependencies if you use **uv**

```bash
make setup
```

Activate virtual environment

```bash
poetry shell
```

Installing dependencies if you use **Docker**

```bash
Expand Down Expand Up @@ -97,7 +89,7 @@ You can get the data through the interface of the administration panel or by run

### **By organization name:**

*With Poetry*
*With uv*

```bash
make sync ARGS='ORG [ORG ...]'
Expand Down Expand Up @@ -128,7 +120,7 @@ is related to a specific repository, you can upload data for a specific reposito

**By full repository names:**

*Poetry*
*uv*

```bash
make sync ARGS='--repo REPO [REPO ...]'
Expand Down Expand Up @@ -162,7 +154,7 @@ make sync

## 3. Running a server for development

### Poetry
### uv

```bash
make start
Expand Down
49 changes: 24 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
test ! -f .env && cp .env.example .env

build-production:
poetry install --extras psycopg2-binary
pip install -r requirements.txt
$(MAKE) collectstatic
$(MAKE) migrate

build:
poetry install --extras psycopg2-binary
poetry run python manage.py migrate
uv run python manage.py migrate

check: lint test requirements.txt

collectstatic:
poetry run python manage.py collectstatic --no-input
uv run python manage.py collectstatic --no-input

compose-build: .env
docker compose build
Expand All @@ -40,68 +39,68 @@ deploy:
git push heroku

setup-pre-commit-hooks:
poetry run pre-commit install
uv run pre-commit install

install-dependencies: .env
poetry install --extras psycopg2-binary
uv sync

install: install-dependencies setup-pre-commit-hooks

lint:
poetry run flake8
uv run ruff check

migrate:
poetry run python manage.py migrate
uv run python manage.py migrate

requirements.txt: poetry.lock
poetry export --format requirements.txt --output requirements.txt --extras psycopg2 --without-hashes
requirements.txt:
uv pip compile pyproject.toml -o requirements.txt

secretkey:
poetry run python -c 'from django.utils.crypto import get_random_string; print(get_random_string(40))'
uv run python -c 'from django.utils.crypto import get_random_string; print(get_random_string(40))'

setup: install
$(MAKE) migrate
$(MAKE) updatesuperuser

updatesuperuser:
poetry run python manage.py updatesuperuser --username admin --email [email protected]
uv run python manage.py updatesuperuser --username admin --email [email protected]

shell:
poetry run python manage.py shell_plus --plain
uv run python manage.py shell_plus --plain

start-deploy:
gunicorn config.wsgi
uv run gunicorn config.wsgi

start-production:
gunicorn -b 0.0.0.0:8000 config.wsgi:application
uv run gunicorn -b 0.0.0.0:8000 config.wsgi:application

start:
poetry run python manage.py runserver 0.0.0.0:8000
uv run python manage.py runserver 0.0.0.0:8000

sync:
poetry run python manage.py fetchdata $(ARGS)
uv run python manage.py fetchdata $(ARGS)

test-coverage-report-xml:
poetry run coverage xml
uv run coverage xml

test-coverage-report: test
poetry run coverage report -m $(ARGS)
poetry run coverage erase
uv run coverage report -m $(ARGS)
uv run coverage erase

test:
poetry run coverage run --source='.' manage.py test
uv run coverage run --source='.' manage.py test

transcompile:
poetry run django-admin compilemessages
uv run django-admin compilemessages

# Need to have GNU gettext installed
transprepare:
poetry run django-admin makemessages --locale ru --add-location file
poetry run django-admin makemessages --locale ru --add-location file --domain djangojs
uv run django-admin makemessages --locale ru --add-location file
uv run django-admin makemessages --locale ru --add-location file --domain djangojs

# Need to have graphviz installed
erd-dot:
poetry run python manage.py graph_models -a -g > erd.dot
uv run python manage.py graph_models -a -g > erd.dot

erd-in-png: erd-dot
dot -Tpng erd.dot -o erd.png
Expand Down
Loading
Loading