Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint -d C0200,C0301,C0114,R0903,C0115,W0246,R0914,C0209,E1121,C0103,C2801,R0801,E1101,E0401,E0611,R0911,C0116,W0212,W0719,W0601,W1203,W0123,W0511 $(git ls-files '*.py')
pylint -d C0200,C0301,C0114,R0903,C0115,W0246,R0914,C0209,E1121,C0103,C2801,R0801,E1101,E0401,E0611,R0911,C0116,W0212,W0719,W0601,W1203,W0123,W0511,W0621 $(git ls-files '*.py')
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
black:
black ./lib
format: flake8 pylint ruff black

lint: flake8 pylint
black:
black ./lib || true
black ./tests || true

flake8:
flake8 --ignore E501,E402,F401,W503 ./lib
flake8 --ignore E501,E402,F401,W503,C0414 ./lib || true
flake8 --ignore E501,E402,F401,W503,C0414 ./tests || true

pylint:
pylint --extension-pkg-whitelist='pydantic' ./lib/*
pylint --extension-pkg-whitelist='pydantic' ./lib || true
pylint --extension-pkg-whitelist='pydantic' --disable=E0401,W0621 ./tests || true

ruff:
ruff check --fix ./lib || true
ruff check --fix ./tests || true

test:
python3 -m pytest .

dev:
python3 -m uvicorn lib:app --reload --port 3000
Expand All @@ -19,3 +29,5 @@ clean:

build:
docker build -t infinity-api . --no-cache

.PHONY: black flake8 pylint test dev clean build ruff format
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
- Install dependencies `python3 -m pip install -r requirements.txt`

## Development
- black ./lib
- pylint --extension-pkg-whitelist='pydantic' ./lib/*
- flake8 --ignore E501,E402,F401,W503 ./lib
- make format
- make test
- make clean
- make build

## Starting the server
- Setup MONGODB_CONNECTION_STRING:
Expand Down
4 changes: 3 additions & 1 deletion lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ def parse_error(error):
return f"{exc_type}: {exc_obj}"


from lib.api import app # pylint: disable=wrong-import-position,cyclic-import
from lib.api import ( # pylint: disable=wrong-import-position,cyclic-import,useless-import-alias
app as app,
)
21 changes: 6 additions & 15 deletions lib/controllers/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,16 @@ class EnvController:
- CRUD operations over models.Env on the database
"""

def __init__(self, env: Env):
self._env = env

@property
def env(self) -> Env:
return self._env

@env.setter
def env(self, env: Env):
self._env = env

async def create_env(self) -> Union[EnvCreated, HTTPException]:
@staticmethod
async def create_env(env: Env) -> Union[EnvCreated, HTTPException]:
"""
Create a env in the database.

Returns:
views.EnvCreated
"""
try:
async with EnvRepository(self.env) as env_repo:
async with EnvRepository(env) as env_repo:
await env_repo.create_env()
except PyMongoError as e:
logger.error(
Expand Down Expand Up @@ -157,8 +147,9 @@ async def get_rocketpy_env_binary(
f"Call to controllers.environment.get_rocketpy_env_binary completed for Env {env_id}"
)

@staticmethod
async def update_env_by_id(
self, env_id: str
env_id: str, env: Env
) -> Union[EnvUpdated, HTTPException]:
"""
Update a models.Env in the database.
Expand All @@ -173,7 +164,7 @@ async def update_env_by_id(
HTTP 404 Not Found: If the env is not found in the database.
"""
try:
async with EnvRepository(self.env) as env_repo:
async with EnvRepository(env) as env_repo:
await env_repo.update_env_by_id(env_id)
except PyMongoError as e:
logger.error(
Expand Down
8 changes: 4 additions & 4 deletions lib/routes/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def create_env(env: Env) -> EnvCreated:
``` models.Env JSON ```
"""
with tracer.start_as_current_span("create_env"):
return await EnvController(env).create_env()
return await EnvController.create_env(env)


@router.get("/{env_id}")
Expand All @@ -63,11 +63,11 @@ async def update_env(env_id: str, env: Env) -> EnvUpdated:
```
"""
with tracer.start_as_current_span("update_env"):
return await EnvController(env).update_env_by_id(env_id)
return await EnvController.update_env_by_id(env_id, env)


@router.get(
"/rocketpy/{env_id}",
"/{env_id}/rocketpy",
responses={
203: {
"description": "Binary file download",
Expand Down Expand Up @@ -118,4 +118,4 @@ async def delete_env(env_id: str) -> EnvDeleted:
``` env_id: str ```
"""
with tracer.start_as_current_span("delete_env"):
return await EnvController(env_id).delete_env_by_id(env_id)
return await EnvController.delete_env_by_id(env_id)
23 changes: 13 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
[build-system]
requires = ["setuptools", "setuptools_scm"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[project]
name = "Infinity-API"
version = "2.2.0"
version = "2.3.0"
description = "RESTFULL open API for rocketpy"
dynamic = ["dependencies"]
requires-python = ">=3.12"
authors = [
{name = "Gabriel Barberini", email = "[email protected]"}
Expand All @@ -21,7 +13,7 @@ maintainers = [
readme = "README.md"
keywords = ["rocketpy", "API", "simulation", "rocket", "flight"]
classifiers = [
"Development Status :: Alpha",
"Development Status :: Production",
"Programming Language :: Python"
]

Expand Down Expand Up @@ -52,3 +44,14 @@ disable = """
raise-missing-from,
too-many-instance-attributes,
"""

[tool.ruff]
line-length = 79
Copy link
Member

Choose a reason for hiding this comment

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

79? I usually see 88 instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For the API development we set PEP-8 as a north

target-version = "py313"

[tool.ruff.lint]
select = ["E", "F", "N", "Q"]
ignore = ["N815", "E501", "Q000", "E402"]
fixable = [
"F401",
]
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flake8
pylint
ruff
Loading
Loading