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: setup ruff #252

Draft
wants to merge 2 commits into
base: poetry
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
run: |
pip install poetry
poetry install --with=code_quality,docs,test,types
- name: Lint with flake8
run: poetry run flake8
- name: Lint with ruff
run: poetry run ruff check .
- name: Run mypy
run: poetry run mypy foca
- name: Start MongoDB
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cv: clean-venv
.PHONY: format-lint fl
format-lint:
@echo "\nRunning linter and formatter using ruff and typos +++++++++++++++++++++++++++++\n"
@poetry run flake8
@poetry run ruff format && poetry run ruff check --fix
@typos .

fl: format-lint
Expand Down
31 changes: 13 additions & 18 deletions docs/api/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

# -- Project information -----------------------------------------------------

project = 'FOCA'
copyright = '2022, ELIXIR Cloud & AAI'
author = 'ELIXIR Cloud & AAI'
project = "FOCA"
copyright = "2022, ELIXIR Cloud & AAI"
author = "ELIXIR Cloud & AAI"

# The full version, including alpha/beta/rc tags
release = __version__ # noqa: F821
Expand All @@ -36,28 +36,28 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]


# Default doc to search for
master_doc = 'index'
master_doc = "index"

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand All @@ -67,18 +67,13 @@

# -- Automation -------------------------------------------------------------


# Auto-generate API doc
def run_apidoc(_):
ignore_paths = [
]
argv = [
"--force",
"--module-first",
"-o", "./modules",
"../../foca"
] + ignore_paths
ignore_paths = []
argv = ["--force", "--module-first", "-o", "./modules", "../../foca"] + ignore_paths
apidoc.main(argv)


def setup(app):
app.connect('builder-inited', run_apidoc)
app.connect("builder-inited", run_apidoc)
6 changes: 2 additions & 4 deletions examples/petstore-access-control/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from foca import Foca

if __name__ == '__main__':
foca = Foca(
config_file="config.yaml"
)
if __name__ == "__main__":
foca = Foca(config_file="config.yaml")
app = foca.create_app()
app.run()
55 changes: 27 additions & 28 deletions examples/petstore-access-control/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,60 @@

import logging

from flask import (current_app, make_response)
from flask import current_app, make_response
from pymongo.collection import Collection

from exceptions import NotFound
from foca.security.access_control.register_access_control import (
check_permissions
)
from foca.security.access_control.register_access_control import check_permissions

logger = logging.getLogger(__name__)


@check_permissions
def findPets(limit=None, tags=None):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore-access-control']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore-access-control"]
.collections["pets"]
.client
)
filter_dict = {} if tags is None else {'tag': {'$in': tags}}
filter_dict = {} if tags is None else {"tag": {"$in": tags}}
if not limit:
limit = 0
records = db_collection.find(
filter_dict,
{'_id': False}
).sort([('$natural', -1)]).limit(limit)
records = (
db_collection.find(filter_dict, {"_id": False})
.sort([("$natural", -1)])
.limit(limit)
)
return list(records)


@check_permissions
def addPet(pet):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore-access-control']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore-access-control"]
.collections["pets"]
.client
)
counter = 0
ctr = db_collection.find({}).sort([('$natural', -1)])
ctr = db_collection.find({}).sort([("$natural", -1)])
if not db_collection.count_documents({}) == 0:
counter = ctr[0].get('id') + 1
record = {
"id": counter,
"name": pet['name'],
"tag": pet['tag']
}
counter = ctr[0].get("id") + 1
record = {"id": counter, "name": pet["name"], "tag": pet["tag"]}
db_collection.insert_one(record)
del record['_id']
del record["_id"]
return record


@check_permissions
def findPetById(id):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore-access-control']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore-access-control"]
.collections["pets"]
.client
)
record = db_collection.find_one(
{"id": id},
{'_id': False},
{"_id": False},
)
if record is None:
raise NotFound
Expand All @@ -67,17 +65,18 @@ def findPetById(id):
@check_permissions
def deletePet(id):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore-access-control']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore-access-control"]
.collections["pets"]
.client
)
record = db_collection.find_one(
{"id": id},
{'_id': False},
{"_id": False},
)
if record is None:
raise NotFound
db_collection.delete_one(
{"id": id},
)
response = make_response('', 204)
response = make_response("", 204)
return response
4 changes: 1 addition & 3 deletions examples/petstore-access-control/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
"code": 401,
},
Forbidden: {
"message": (
"Sorry, but you don't have permission to play with the pets."
),
"message": ("Sorry, but you don't have permission to play with the pets."),
"code": 403,
},
NotFound: {
Expand Down
6 changes: 2 additions & 4 deletions examples/petstore/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from foca import Foca

if __name__ == '__main__':
foca = Foca(
config_file="config.yaml"
)
if __name__ == "__main__":
foca = Foca(config_file="config.yaml")
app = foca.create_app()
app.run()
43 changes: 18 additions & 25 deletions examples/petstore/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from flask import (current_app, make_response)
from flask import current_app, make_response
from pymongo.collection import Collection

from exceptions import NotFound
Expand All @@ -12,46 +12,40 @@

def findPets(limit=None, tags=None):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore"].collections["pets"].client
)
filter_dict = {} if tags is None else {'tag': {'$in': tags}}
filter_dict = {} if tags is None else {"tag": {"$in": tags}}
if not limit:
limit = 0
records = db_collection.find(
filter_dict,
{'_id': False}
).sort([('$natural', -1)]).limit(limit)
records = (
db_collection.find(filter_dict, {"_id": False})
.sort([("$natural", -1)])
.limit(limit)
)
return list(records)


def addPet(pet):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore"].collections["pets"].client
)
counter = 0
ctr = db_collection.find({}).sort([('$natural', -1)])
ctr = db_collection.find({}).sort([("$natural", -1)])
if not db_collection.count_documents({}) == 0:
counter = ctr[0].get('id') + 1
record = {
"id": counter,
"name": pet['name'],
"tag": pet['tag']
}
counter = ctr[0].get("id") + 1
record = {"id": counter, "name": pet["name"], "tag": pet["tag"]}
db_collection.insert_one(record)
del record['_id']
del record["_id"]
return record


def findPetById(id):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore"].collections["pets"].client
)
record = db_collection.find_one(
{"id": id},
{'_id': False},
{"_id": False},
)
if record is None:
raise NotFound
Expand All @@ -60,17 +54,16 @@ def findPetById(id):

def deletePet(id):
db_collection: Collection = (
current_app.config.foca.db.dbs['petstore']
.collections['pets'].client
current_app.config.foca.db.dbs["petstore"].collections["pets"].client
)
record = db_collection.find_one(
{"id": id},
{'_id': False},
{"_id": False},
)
if record is None:
raise NotFound
db_collection.delete_one(
{"id": id},
)
response = make_response('', 204)
response = make_response("", 204)
return response
Loading
Loading