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

Chore: housekeeping #3

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .devcontainer/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"result_backend": {
"redis": {
"url": "redis://redis:6379/0"
}
},
"state_backend": {
"redis": {
"url": "redis://redis:6379/0"
}
},
"broker": {
"amqp": {
"url": "amqp://rabbitmq:5672"
}
}
}
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{
"name": "Python 3",
"dockerComposeFile": [
"docker-compose.yaml"
"docker-compose.yaml",
"docker-compose-devcontainer.yaml"
],
"workspaceFolder": "/workspaces/project-mognet",
"service": "mognet",
Expand Down
35 changes: 35 additions & 0 deletions .devcontainer/docker-compose-devcontainer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "2.4"

services:
mognet:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
args:
VARIANT: "3.8"
INSTALL_NODE: "false"

mem_limit: 4g
cpus: 2
working_dir: /workspaces/project-mognet
volumes:
- ..:/workspaces/project-mognet:cached
- vscode_server_data:/home/vscode/.vscode-server
- cache:/home/vscode/.cache

environment:
- MOGNET_CONFIG_FILE=/workspaces/project-mognet/.devcontainer/config.json

command:
- bash
- -c
- |
set -e
sudo chown -R vscode:vscode /home/vscode/.vscode-server
sudo chown -R vscode:vscode /home/vscode/.cache
exec sleep infinity

volumes:
results_backend_data: {}
vscode_server_data: {}
cache: {}
40 changes: 7 additions & 33 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
version: "2.4"

services:
mognet:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
args:
VARIANT: "3.8"
INSTALL_NODE: "false"

mem_limit: 4g
cpus: 2
working_dir: /workspaces/project-mognet
volumes:
- ..:/workspaces/project-mognet:cached
- vscode_server_data:/home/vscode/.vscode-server
- cache:/home/vscode/.cache

command:
- bash
- -c
- |
set -e
sudo chown -R vscode:vscode /home/vscode/.vscode-server
sudo chown -R vscode:vscode /home/vscode/.cache
exec sleep infinity

redis:
image: redis
mem_limit: 128m
mem_reservation: 32m
cpus: 0.25
volumes:
- results_backend_data:/data
networks:
default:
aliases:
- cps-results-backend
ports:
- 6379:6379

rabbitmq:
image: rabbitmq:management
mem_limit: 512m
mem_limit: 1024m
mem_reservation: 128m
cpus: 0.5
cpus: 1
# Prevent huge memory usage by limiting the number
# of file descriptors
ulimits:
nofile:
soft: 8192
hard: 8192
ports:
- 5672:5672
- 15672:15672

volumes:
results_backend_data: {}
vscode_server_data: {}
cache: {}
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = E501,W503
exclude = .git,__pycache__,docs/,build,dist,demo
# max-complexity = 10
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Apply black and isort to project
# See https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html
bc7b568fe0f925558718a71fdd42b5289a20cab8
46 changes: 40 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,51 @@ env:
POETRY_VIRTUALENVS_CREATE: false

jobs:
test-build-docs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3

- name: Run docker-compose stack for testing
run: make docker-up

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# python-version: "^3.8"
cache: "pip"
cache-dependency-path: "poetry.lock"

- name: Install poetry
run: pip install poetry
- uses: actions/setup-python@v3

- name: Install dependencies
run: poetry install

- name: Lint
run: make lint

- name: Test
# Wait for RabbitMQ to start.
run: sleep 10 && make test
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't like this; it would be nice for the tests to wait for RabbitMQ to actually be ready. Also, for some reason the tests didn't do anything for 10 minutes on 3 runs, so maybe this should be disabled?

Suggestions welcome.


test-build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
cache: 'pip'
cache-dependency-path: 'poetry.lock'
python-version: "3.10"
cache: "pip"
cache-dependency-path: "poetry.lock"

- name: Install poetry
run: pip install poetry

- name: Install dependencies
run: poetry install
- run: mkdocs build --verbose --clean --strict

- run: poetry run mkdocs build --verbose --clean --strict
16 changes: 9 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ on:
env:
POETRY_VIRTUALENVS_CREATE: false


jobs:
deploy:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pip install poetry
- uses: actions/setup-python@v3
with:
python-version: 3.x
cache: 'pip'
cache-dependency-path: 'poetry.lock'
python-version: "3.10"
cache: "pip"
cache-dependency-path: "poetry.lock"

- name: Install poetry
run: pip install poetry

- name: Install dependencies
run: poetry install

- name: Build and push docs
run: mkdocs gh-deploy --force
run: poetry run mkdocs gh-deploy --force
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,windows,macos,virtualenv,linux,vim,emacs
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,windows,macos,virtualenv,linux,vim,emacs

/config.json

### Emacs ###
# -*- mode: gitignore; -*-
*~
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extension-pkg-whitelist=

# Specify a score threshold to be exceeded before program exits with error.
fail-under=10.0
fail-under=8.0

# Add files or directories to the blacklist. They should be base names, not
# paths.
Expand Down
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

DOCKER_COMPOSE_FILE=.devcontainer/docker-compose.yaml

.PHONY: format-black
format-black:
@poetry run black .

.PHONY: format-isort
format-isort:
@poetry run isort .

.PHONY: format
format: format-isort format-black

.PHONY: lint-isort
lint-isort:
@poetry run isort --check .

.PHONY: lint-black
lint-black:
@poetry run black --check .

lint-pylint:
@poetry run pylint mognet

lint-flake8:
@poetry run flake8

lint-mypy:
@poetry run mypy mognet

.PHONY: lint
lint: lint-isort lint-black lint-flake8 lint-pylint lint-mypy

.PHONY: docker-up
docker-up:
@docker-compose \
-f $(DOCKER_COMPOSE_FILE) \
up -d

.PHONY: docker-down
docker-down:
@docker-compose \
-f $(DOCKER_COMPOSE_FILE) \
down

.PHONY: test
test:
@poetry run pytest test/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Mognet is a fast, simple framework to build distributed applications using task queues.

[![PyPI](https://img.shields.io/pypi/v/mognet)](https://www.pypi.org/project/mognet)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mognet)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

## Installing

Mognet can be installed via pip, with:
Expand Down
5 changes: 2 additions & 3 deletions demo/mognet_demo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""

import asyncio
from contextlib import suppress
import os
from contextlib import suppress
from typing import Optional
from uuid import UUID, uuid4

Expand All @@ -18,13 +18,12 @@
Response,
UploadFile,
)
from pydantic import confloat

from mognet_demo.config import DemoConfig
from mognet_demo.models import Job, Upload, UploadJobResult
from mognet_demo.mognet_app import app as mognet_app
from mognet_demo.s3 import get_s3_client
from mognet_demo.tasks import process_document_upload
from pydantic import confloat

app = FastAPI(
title="Mognet Demo API",
Expand Down
4 changes: 2 additions & 2 deletions demo/mognet_demo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from pydantic import BaseModel, BaseSettings

from mognet import AppConfig
from mognet.app.app_config import ResultBackendConfig, StateBackendConfig, BrokerConfig
from mognet.app.app_config import BrokerConfig, ResultBackendConfig, StateBackendConfig
from mognet.backend.backend_config import RedisResultBackendSettings
from mognet.state.state_backend_config import RedisStateBackendSettings
from mognet.broker.broker_config import AmqpBrokerSettings
from mognet.state.state_backend_config import RedisStateBackendSettings


class S3Config(BaseModel):
Expand Down
5 changes: 3 additions & 2 deletions demo/mognet_demo/middleware/auto_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
import asyncio
import logging
from typing import TYPE_CHECKING, NoReturn, Optional
from mognet.middleware.middleware import Middleware

from mognet.cli.exceptions import GracefulShutdown
from mognet.middleware.middleware import Middleware

if TYPE_CHECKING:
from mognet import Result, Context, App
from mognet import App, Context, Result

_log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion demo/mognet_demo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""
from typing import List, Optional
from uuid import UUID
from pydantic import BaseModel

from pydantic import BaseModel

from mognet.model.result_state import ResultState

Expand Down
5 changes: 2 additions & 3 deletions demo/mognet_demo/mognet_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
It can be used both for submitting jobs and for launching the worker process via the CLI
"""

from mognet import App

from mognet_demo.config import DemoConfig
from mognet_demo.middleware.auto_shutdown import AutoShutdownMiddleware

from mognet import App

_mognet_config = DemoConfig.instance().mognet

Expand Down
4 changes: 1 addition & 3 deletions demo/mognet_demo/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from contextlib import asynccontextmanager

from aiobotocore.session import get_session

from mognet_demo.config import DemoConfig

from botocore.exceptions import ClientError
from mognet_demo.config import DemoConfig


@asynccontextmanager
Expand Down
Loading