Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
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
90 changes: 54 additions & 36 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ literal-multiline-quotes = "double"
literal-docstring-quotes = "double"
literal-include-name = true

rst-roles = py:class, py:func, py:ref, py:attr
rst-roles = py:mod, py:func, py:data, py:const, py:class, py:meth, py:attr, py:exc, py:obj, py:ref

extend-exclude =
alembic
Expand All @@ -19,45 +19,63 @@ max-line-length = 88

# ignores
extend-ignore =
# not required or shadowed by other plugins
# # not required or shadowed by other plugins
D I FI TC Q U101 S101 WPS400

# black
WPS317 WPS348 E501 C812 C816
WPS220 WPS317 WPS348 WPS352 E501 C812 C815 C816 C819 E203
# mypy (for __init__)
WPS410 WPS412
# pydantic-marshals & SQLAlchemy
VNE003 WPS115
# weird
PIE803 C101 FNE007 FNE008 N812 ANN101 ANN102 WPS110 WPS111 WPS114 WPS407 VNE001 CM001
# broken
PIE798 WPS226 WPS354 WPS432 WPS473 WPS507
U100 # fails to understand `raise NotImplementedError` and overloading
WPS338 # bad method ordering conventions
# __init__
WPS410 WPS412
WPS428 # fails to understand overloading
WPS465 # fails to understand pipe-unions for types
WPS601 # fails to same-name class and instance attributes (pydantic & sqlalchemy)
# to many
WPS201 WPS202 WPS204 WPS210 WPS214 WPS217 WPS218 WPS220 WPS221 WPS234 WPS235

# don't block features
WPS100 # utils is a module name
WPS237 WPS305 # f-strings are the best
WPS306 # python 2.x is deprecated
WPS347 # vague imports
WPS352 # multiline loops
WPS402 # noqa exists for a reason
WPS420 WPS604 # pass is a thing
WPS430 # nested functions
WPS451 # positional-only arguments
WPS501 # try-finally with no except
WPS600 # subclassing lowercase builtins
WPS602 # @staticmethod
WPS605 # methods with no arguments

# tastes differ
WPS337 # multiline conditions

# # weird
PIE803 C101 FNE007 FNE008 N812 ANN101 ANN102 WPS110 WPS111 WPS114 WPS338 WPS407 WPS414 VNE001 VNE002 CM001
# too many
WPS200 WPS201 WPS202 WPS204 WPS210 WPS211 WPS213 WPS214 WPS217 WPS218 WPS220 WPS221 WPS230 WPS231 WPS234 WPS235 WPS238

# # broken
PIE798 WPS226 WPS354 WPS432 WPS473 WPS507 FNE004
# fails to understand `raise NotImplementedError` and overloading
U100
# fails to understand enums
WPS115
# fails to understand overloading
WPS428
# fails to understand pipe-unions
WPS465
# fails to same-name class and instance attributes (pydantic & sqlalchemy)
WPS601

# # don't block features
# utils is a module name
WPS100
# f-strings are the best
WPS237 WPS305
# python 2.x is deprecated
WPS306
# multiline
WPS320 WPS337 WPS352
# noqa exists for a reason
WPS402
# pass is a thing
WPS420 WPS604
# nested functions
WPS430
# nested classes
WPS431
# positional-only arguments
WPS451
# try-finally with no except
WPS501
# subclassing lowercase builtins
WPS600
# @staticmethod
WPS602
# methods with no arguments
WPS605
# vague imports
WPS347

per-file-ignores =
*test*: TN101 FNE005 SCS108 VNE001 WPS118 WPS202 WPS211 WPS317 WPS407 WPS425 WPS432 WPS440 WPS437 WPS441 WPS442 WPS507 WPS520 WPS609
*test*: TN101 FNE005 SCS108 S311 VNE001 WPS118 WPS202 WPS211 WPS317 WPS407 WPS425 WPS432 WPS437 WPS440 WPS441 WPS442 WPS507 WPS520 WPS609
alembic/versions/*: WPS102 PEA001 NU001 SIM907
10 changes: 4 additions & 6 deletions .github/workflows/common-work.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ jobs:
runs-on: ubuntu-latest

env:
DB_LINK: 'postgresql+psycopg://test:test@localhost:5432/test'
DB_SCHEMA: ${{ inputs.database && 'xi_auth' || '' }}
MQ_URL: 'amqp://guest:guest@localhost/'
postgres_schema: ${{ inputs.database && 'xi_auth' || '' }}

services:
mq:
Expand Down Expand Up @@ -55,9 +53,9 @@ jobs:
cache: pip

- name: Install Poetry
uses: snok/install-poetry@v1
uses: snok/install-poetry@v1.3.4
with:
version: 1.4.1
version: 1.8.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down Expand Up @@ -120,7 +118,7 @@ jobs:
- name: Run pytest
run: pytest tests -p no:cacheprovider --cov=app ${{ !inputs.coverage && '--cov-fail-under=0' || ''}}
env:
DATABASE_MIGRATED: '1'
postgres_automigrate: false

- name: Run pre-commit for all files
if: success() || (failure() && steps.venv.conclusion == 'success')
Expand Down
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.10.0
hooks:
- id: black

Expand All @@ -49,18 +49,13 @@ repos:
name: mypy (full)
language: system
entry: mypy
args:
- "--strict"
- "."
require_serial: true
pass_filenames: false
types_or: [python, pyi]

- repo: https://github.com/python-poetry/poetry
rev: 1.4.1
rev: 1.8.2
hooks:
- id: poetry-check
files: ^(pyproject.toml|poetry.lock)$
- id: poetry-lock
files: ^(pyproject.toml|poetry.lock)$
args: ["--no-update"]
- id: poetry-check
- id: poetry-install
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM python:3.11-alpine
WORKDIR /backend
RUN pip install --upgrade pip

RUN pip install poetry==1.4.1
RUN pip install poetry==1.8.2
RUN poetry config virtualenvs.create false

COPY pyproject.toml poetry.lock ./
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Эта установка нужна для запуска бэкенда локально и запуска форматеров, линтеров и тайп чекеров перед каждым коммитом. Для корректной работы требуется Python 3.11

```sh
pip install poetry==1.4.1
pip install poetry==1.8.2
poetry install
pre-commit install
```
Expand Down Expand Up @@ -44,22 +44,22 @@ docker compose down
6. Добавить бота в группу (важно сделать это именно после шагов 4-5, иначе нужно выгнать бота и добавить заново)
7. Если хочется, можно теперь запретить добавлять бота в группы, т.е. отменить шаг 4 (шаг 5 отменять нельзя)
8. Дальше настраиваем переменные окружения в файле `.env` (не заливать в git!):
- `SUPBOT_POLLING` включить polling (поставить значение `"1"`), чтобы не тыкаться с webhook-ом
- `SUPBOT_TOKEN` это токен бота, созданного на первом этапе
- `SUPBOT_GROUP_ID` это id группы, в которую добавлен бот (id можно получить переслав сообщение из группы [боту](https://t.me/get_id_channel_bot) (начинается с -100))
- `SUPBOT_CHANNEL_ID` это id канала, в который добавлен бот (id можно получить переслав сообщение из канала [боту](https://t.me/get_id_channel_bot) (начинается с -100))
- `SUPBOT__POLLING` включить polling (поставить значение `"true"`), чтобы не тыкаться с webhook-ом
- `SUPBOT__TOKEN` это токен бота, созданного на первом этапе
- `SUPBOT__GROUP_ID` это id группы, в которую добавлен бот (id можно получить переслав сообщение из группы [боту](https://t.me/get_id_channel_bot) (начинается с -100))
- `SUPBOT__CHANNEL_ID` это id канала, в который добавлен бот (id можно получить переслав сообщение из канала [боту](https://t.me/get_id_channel_bot) (начинается с -100))

Пример `.env`-файла:
```txt
SUPBOT_POLLING=1
SUPBOT_TOKEN=0000000000:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
SUPBOT_GROUP_ID=-100123456
SUPBOT_CHANNEL_ID=-100123456
SUPBOT__POLLING=true
SUPBOT__TOKEN=0000000000:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
SUPBOT__GROUP_ID=-100123456
SUPBOT__CHANNEL_ID=-100123456
```

После всех настроек можно запускать приложение, как сказано в [инструкции выше](#run). Важно использовать `--port 5100`, а если хочется использовать иной порт, то его нужно указать в переменной `SUPBOT_WEBHOOK_URL` в `.env`, например, так:
После всех настроек можно запускать приложение, как сказано в [инструкции выше](#run). Важно использовать `--port 5100`, а если хочется использовать иной порт, то его нужно указать в переменной `SUPBOT__WEBHOOK_URL` в `.env`, например, так:
```txt
SUPBOT_WEBHOOK_URL=http://localhost:8000
SUPBOT__WEBHOOK_URL=http://localhost:8000
```

### Pochta
Expand All @@ -71,9 +71,9 @@ SUPBOT_WEBHOOK_URL=http://localhost:8000
5. Добавляем в .env файл следующего формата:

```txt
EMAIL_USERNAME=your_email@gmail.com
EMAIL_PASSWORD=asdf lkjh zxcv qere
EMAIL_HOSTNAME=smtp.gmail.com
EMAIL__USERNAME=your_email@gmail.com
EMAIL__PASSWORD=asdf lkjh zxcv qere
EMAIL__HOSTNAME=smtp.gmail.com
```

## Info
Expand Down
7 changes: 4 additions & 3 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from sqlalchemy.sql.ddl import CreateSchema

import app.main # noqa: F401
from app.common.config import DB_URL, db_meta
from app.common.config import db_meta, settings

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
config.set_main_option("sqlalchemy.url", DB_URL)
config.set_main_option("sqlalchemy.url", settings.postgres_dsn)

# Interpret the config file for Python logging.
# This line sets up loggers basically.
Expand Down Expand Up @@ -66,7 +66,8 @@ def do_run_migrations(connection: Connection) -> None:
)

with context.begin_transaction():
context.execute(CreateSchema("xi_auth", if_not_exists=True))
if settings.postgres_schema is not None:
context.execute(CreateSchema(settings.postgres_schema, if_not_exists=True))
context.run_migrations()


Expand Down
4 changes: 2 additions & 2 deletions app/common/bridges/public_users_bdg.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from httpx import AsyncClient

from app.common.config import BRIDGE_BASE_URL
from app.common.config import settings
from app.common.schemas.vacancy_form_sch import VacancyFormSchema


class PublicUsersBridge:
def __init__(self) -> None:
self.client = AsyncClient(
base_url=BRIDGE_BASE_URL,
base_url=settings.bridge_base_url,
)

async def apply_for_vacancy(self, vacancy_form: VacancyFormSchema) -> None:
Expand Down
Loading
Loading