Some coding recommendations specific to RERO+ projects.
Introduced since Python 3.5
, typing allows to specify types for variables or functions. For RERO+ projects, this feature is not recommended, since it doesn't add any value to the code.
Exporting long lists of results from an ES query implies using scan()
instead of execute()
. execute()
uses invenio-record-rest
but not scan()
. This means that we have to duplicate code when using scan()
.
invenio-record-rest
. When we need to stream an export with scan()
, we use a specific mounting point.Invenio resources
, which is more flexible and allows class supercharging.scan()
can create ElasticSearch timeouts. Each export task should be possible with a CLI that avoids any nginx or ES timeout.Recommended code prettyfier plugins:
Note: Cosmetic suggestions in code reviews should be identified as such, and can be ignored by the author of the original code.
Python imports can be reorganized, sorted, and changed during development.
Here are some best practices about Python imports.
Python allows importing of resources using a path that is either absolute, or relative to current file. The guidelines for RERO-ILS project are defined as follows:
into the file rero_ils.modules.items.api.record.py
# These imports reference classes/methods from file into `items` module.
# As we stay into the same module, we use relative imports
from .api import ItemsSearch
from ..models import TypeOfItem
from ..utils import item_pid_to_object
# These imports reference classes/methods from file outside `items` module.
# Use absolute imports in this case (even if we stay into the RERO-ILS project
# scope)
from rero_ils.modules.api import IlsRecord
from rero_ils.modules.location.api import Location
from rero_ils.modules.operation_logs.extensions import UntrackedFieldsOperationLogObserverExtension
from rero_ils.modules.utils import date_string_to_utc, extracted_data_from_ref
poetry run isort -rc rero_ils tests
poetry run autoflake --remove-all-unused-imports -i --ignore-init-module-imports -r .
Add a new line in your .bashrc or .zshrc:
alias fixsort="poetry run isort -rc rero_ils tests && poetry run autoflake --remove-all-unused-imports -i --ignore-init-module-imports -r ."
For commit messages, the editor should help you to :
" Filetype detection
filetype plugin on
autocmd FileType gitcommit set textwidth=72
set colorcolumn=+1 " Colors the tw+1 column
autocmd FileType gitcommit set colorcolumn+=51
autocmd FileType gitcommit setlocal spell
autocmd FileType gitcommit setlocal spelllang=en