Python#

Note

This guide is under development and is likely to change.

python version

3.11

last-updated

Apr 24, 2024

The team uses the following files to configure, setup and install our python packages. This guide assumes a repo created with the Templates project or using the sqr-bot jr create a repo functionality.

pyproject.toml#
[build-system]
requires = ["setuptools>=45", "setuptools-scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "ts-{name}"
description = "{name} is a Commandable SAL Component for the `Vera C. Rubin Observatory <https://lsst.org>`_."
license = { text = "GPL" }
classifiers = [ "Programming Language :: Python :: 3" ]
dependencies = ["pymodbus"]
readme = "README.rst"
urls = { documentation = "https://ts-{name}.lsst.io", source_code = "https://github.com/lsst-ts/ts_{name}"}
dynamic = ["version"]

[tool.setuptools.dynamic]
version = { attr = "setuptools_scm.get_version" }

[tool.setuptools.packages.find]
where = [ "python" ]

[project.scripts]
run_{name} = "lsst.ts.{name}:run_{name}"

[tool.setuptools_scm]
write_to = "python/lsst/ts/{name}/version.py"
write_to_template = """
# Generated by setuptools_scm
__all__ = ["__version__"]
__version__ = "{version}"
"""

[tool.pytest.ini_options]
asyncio_mode = "auto"

[project.optional-dependencies]
dev = ["documenteer[pipelines]"]
setup.py#
import setuptools
import setuptools_scm

setuptools.setup(version=setuptools_scm.get_version())

Style Guide#

The team uses the following tools to enforce the style guide.

black

An opinionated autoformatter.

isort

An opinionated import sorter.

flake8

A style checker with many different plugins to enforce different rules.

check-yaml

Checks yaml files for proper format.

check-xml

Checks xml files for proper format.

mypy

Performs type checking on the code (optional).

There are several other optional style guide tools as well. This is enforced by a tool called pre-commit.