Some conventions on coding style and tools for the Javascript and Python in this repository.
What is a ...
- Controller-Service-Repository design-pattern ?
- An introduction: https://tom-collings.medium.com/controller-service-repository-16e29a4684e5
- Example of adopted convention: ITISFoundation#4389
We should avoid merging PRs with TODO:
and FIXME:
into master. One of our bots detects those and flag them as code-smells. If we still want to keep this idea/fix noted in the code, those can be rewritten as NOTE:
and should be extended with a link to a github issue with more details. For a context, see discussion here.
Avoid commented code, but if you really want to keep it then add an explanatory NOTE:
import os
# import bar
# x = "not very useful"
# NOTE: I need to keep this becase ...
# import foo
# x = "ok"
- If the callable creates an instance, you can use
_factory
as suffix instead (e.g. thetmp_path_factory
fixture) - Use verb as prefix, as seen in the example below
@pytest.fixture
def something() -> Something:
return Something("nice")
@pytest.fixture
def create_something() -> Callable[..., Something]:
def _create(*args, **kwargs) -> Something:
# ...
return _create
def test_it(something: Something, create_something: Callable[..., Something]):
new_something = create_something(color="blue")
assert new_something != something
In short we use the following naming convention ( roughly PEP8 ):
example | |
---|---|
Function | function , my_function |
Variable | x , var , my_variable |
Class | Model , MyClass |
Method | class_ method , method |
Constant | CONSTANT , MY_CONSTANT , MY_LONG_CONSTANT |
Module | module.py , my_module.py |
Package | package , my_package |
- We encourage marking protected/private entities. We do it adding the prefix
_
/__
: e.g._PROTECTED_CONSTANT
,A.__private_func
- We encourage meaningful type annotations
- We encourage pep257 for simple code documentation
- Priorize having good variable names and type annotations than a verbose and redundant documentation
- Examples of useful documentation:
- Raised Exceptions in a function
- Rationale of a design
- Extra information on variable/argument that cannot be deduced from its name or type annotation
- Use vscode tool
njpwerner.autodocstring
- See example of pep257 doc.
- black will enforce the style: Just use it.
- pylint will check the some extra conventions: see .pylintrc.
make pylint
recipe available onpackages
orservices
- mypy is a type-checker that will check syntax : see mypy.ini
- See intro in mypy-doc
make mypy
recipe available onpackages
orservices
- Foreign Keys follow this name pattern:
fk_$(this_table)_$(this_column)
, for examplefk_projects_to_product_product_name
- Recommended style: https://google.github.io/styleguide/shellguide.html
- Automatic analysis tool: shellcheck
- see
scripts/shellcheck.bash
and.vscode/settings.template.json
- see
- Recommended inside of a
scripts
folder
In general the qooxdoo
naming convention/style is followed. The Access paragraph is the most notable. It is recommended to read the entire document.
Have a look at ESLint
's configuration files .eslintrc.json and .eslintignore.
- Make sure to run
make mypy
andmake pylint
, as the associated github-actions are required to pass. If you include new dependencies inrequirements/*.in
, make sure to runmake touch && make reqs "upgrade=NAME_OF_YOUR_NEW_DEPENDENCY"
. It is best to do this inside a reproducible environment, for this purpose a shell inside a docker container can be used: Go toosparc-simcore/requirements/tools
and runmake shell
. Inside the new shell the osparc-simcore repo is placed in~
. Runmake reqs
from inside this shell.