All new code should adhere as closely as possible to PEP008.
Use the Numpy style for docstrings.
Use Pylint to check your code prior to raising a pull request. The parameters below will be used when checking code cleanliness on commits, PRs, and tags, with a target score of >= 9/10.
If you're using Atom as your text editor, consider using the linter-pylama package for real-time feedback.
To verify the documentation style, use the tool PyDocStyle
Here's how we run pydocstyle in CI:
pipenv run pydocstyle --convention=numpy --add-ignore=D401 accounts users/arxiv
Use type hint annotations
wherever practicable. Use mypy to check your code.
If you run across typechecking errors in your code and you have a good reason
for mypy
to ignore them, you should be able to add # type: ignore
,
ideally along with an actual comment describing why the type checking should be
ignored on this line. In cases where it is hoped the types can be specified later,
just simplying adding the # type: ignore
without further comment is fine.
Try running mypy with (from project root):
pipenv run mypy accounts users/arxiv | grep -v "test.*" | grep -v "defined here"
Mypy options are most easily specified by adding them to mypy.ini
in the repo's
root directory.
mypy chokes on dynamic base classes and proxy objects (which you're likely
to encounter using Flask); it's perfectly fine to disable checking on those
offending lines using "# type: ignore
". For example:
>>> g.baz = get_session(app) # type: ignore
See this issue for more information.
Documentation is built with Sphinx.
The documentation source files (in reST markdown)
are in docs/source
. Everything in that directory is under version
control. The rendered documentation is located in docs/build
; those files
are not under version control (per .gitignore
).
To build the full documentation for this project:
cd <project_root>/docs
make html SPHINXBUILD=$(pipenv --venv)/bin/sphinx-build
Point your browser to: file:///path/to/arxiv-auth/docs/build/html/index.html
.
There are other build targets available. Run make
without any arguments
for more info.
Documentation for the (code) API is generated automatically with
sphinx-apidoc,
and lives in docs/source/api
.
sphinx-apidoc generates references to modules in the code, which are followed at build time to retrieve docstrings and other details. This means that you won't need to run sphinx-apidoc unless the structure of the project changes (e.g. you add/rename a module).
To rebuild the API docs, run (from the project root):
sphinx-apidoc -o docs/source/arxiv.users -e -f -M --implicit-namespaces users/arxiv *test*/*
sphinx-apidoc -o docs/source/accounts -e -f -M accounts *test*/*