Skip to content

Commit 7cd05f6

Browse files
committed
Update python guidelines
Why these changes are being introduced: The python guidelines were remarkably accurate given a fairly lengthy stay between updates, but some areas were beginning to need some updates. Additionally, we are currently actively experimenting with a "specification" of sorts for python projects, a document that is designed to be a bit more granular than these guidelines. How this addresses that need: * Updates sections where small changes are needed (e.g. pipenv -> uv) * Adds new "python projects specification" section that briefly notes and links to a specification document with more granular details about project conventions Side effects of this change: * First experimental integration of the dev docs wiki and the new python project specification repository Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/IN-1697
1 parent 30751e7 commit 7cd05f6

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

languages/python.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ Note: it's important that you follow all of the setup instructions in the templa
1717

1818
If you notice anything that needs to be updated in either of the templates, please submit a PR!
1919

20+
## Python Project Specification
21+
22+
The [Python Project Specification](https://github.com/MITLibraries/spec-python-projects) repository is a declarative standard for Python projects. It defines the tooling, configuration, file structure, and workflow targets that a compliant project should have. The [SPECIFICATION.md](https://github.com/MITLibraries/spec-python-projects/blob/main/SPECIFICATION.md) file in that repository is designed to be a living document with fairly constant updates.
23+
24+
Where this page provides general principles and recommendations, the specification aims to provide auditable, concrete requirements, e.g. `pyproject.toml` configuration, Makefile targets, pre-commit hooks, CI workflows, Dockerfile patterns, etc.
25+
2026
## Style and coding Conventions
2127

2228
In general, you should follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) and [PEP 257](https://www.python.org/dev/peps/pep-0257/). Unless otherwise stated here, assume those two guidelines are in effect.
2329

24-
If you are providing function docstrings, use [reST](http://docutils.sourceforge.net/rst.html). In addition to a description of what a function does, you should document the parameters:
30+
If you are providing function docstrings, use [Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings). In addition to a description of what a function does, you should document the parameters:
2531

2632
```python
2733
def widgetize(widget):
@@ -30,7 +36,8 @@ def widgetize(widget):
3036
This ensures that the widget conforms to the strict standards
3137
governing conformant widgets.
3238
33-
:param widget: a widget what needs widgetizing
39+
Args:
40+
widget: A widget what needs widgetizing.
3441
"""
3542

3643
standardize(widget)
@@ -40,25 +47,17 @@ def widgetize(widget):
4047

4148
Our standard Python code checkers in all repositories include:
4249

43-
- [bandit](https://bandit.readthedocs.io/en/latest/) - security
44-
- [black](https://black.readthedocs.io/en/stable/) - formatting
45-
- [isort](https://pycqa.github.io/isort/) - import order
46-
- [mypy](https://mypy.readthedocs.io/en/stable/) - type hinting
47-
- [pylama](https://github.com/klen/pylama) - formatting and code quality (wrapper around several other tools)
50+
- [ruff](https://docs.astral.sh/ruff/) - formatting and linting (replaces black, isort, pylama, and bandit)
51+
- [mypy](https://mypy.readthedocs.io/en/stable/) - type checking
52+
- [pip-audit](https://pypi.org/project/pip-audit/) - dependency security auditing
4853

4954
These tools should be used during development and are run automatically in Github Actions during CI. They are all included in the template repositories listed above, and have integrations for common code editors to allow automatic checking and reformatting during development.
5055

51-
The linters are usually run together with the `make lint` command in a project's Makefile. See the template repositories for examples.
56+
The linters are usually run together with the `make lint` command in a project's Makefile, which runs `ruff check`, `ruff format`, and `mypy`. See the template repositories for examples.
5257

5358
## Dependencies
5459

55-
Use [Pipenv](https://pipenv.readthedocs.io/en/latest/) to manage dependencies for Python applications. If there's some reason you need to support pip, then you should still manage dependencies with pipenv, but generate your `requirements.txt` file as needed with:
56-
57-
```
58-
pipenv requirements > requirements.txt
59-
```
60-
61-
If you are creating a Python library, [Poetry](https://python-poetry.org/) is the preferred package and distribution manager.
60+
Use [uv](https://docs.astral.sh/uv/) to manage dependencies for Python applications. Dependencies should be declared in `pyproject.toml` and locked with `uv lock`.
6261

6362
## Project Documentation
6463

0 commit comments

Comments
 (0)