Python
With only a few exceptions, Smarter Framework is implemented in Python. There are certain conventions and best practices that we’ve adopted, and want to impress upon future contributors to the project.
Coding Style
Smarter Framework follows the PEP 8 – Style Guide for Python Code.
Smarter Framework uses Black as its code formatter.
isort to sort imports.
flake8 for linting: pyflakes, pycodestyle and mccabe’s cyclomatic complexity.
pylint for code linting.
pylint-django for Django-specific linting.
mypy for static type checking.
pyupgrade to automatically upgrade syntax for newer Python versions.
codespell to check for spelling errors.
bandit for security linting.
coverage to measure test coverage.
pydocstringformatter to format docstrings.
pre-commit for managing git hooks.
tox for running flake8 and pylint in isolated environments.
watchdog for file system monitoring.
pre-commit hooks for additional checks, such as fixing byte order markers, checking for merge conflicts, trailing whitespace, and more.
Type Hinting
Smarter Framework uses Python type hinting extensively throughout the codebase. This helps improve code readability, provides better support for IDEs, and enables static type checking with tools like mypy.
pandas-stubs for pandas type annotations.
types-lxml for lxml type annotations.
types-Markdown for Markdown type annotations.
types-paramiko for paramiko type annotations.
types-PyYAML for PyYAML type annotations.
types-requests for requests type annotations.
django-stubs for Django type annotations.
djangorestframework-stubs for Django REST Framework type annotations.
mypy_extensions for additional type annotation utilities.
Documentation
See the Documentation Style Guide.
Dependencies
Smarter Framework relies on a number of third-party Python packages to provide various functionalities. These are maintained in the smarter/requirements/in directory of the project, with separate files for different environments and use cases.
Smarter Framework Python Requirements
Dependabot Configuration for Python Dependencies
---
#------------------------------------------------------------------------------
# Dependabot version updates, as pull requests to alpha.
#
# cooldown: a new release isn't proposed until it has been published for two
# weeks. Most malicious releases are found and removed from their registry
# within days, so the wait keeps them out of the lockfiles. It applies to
# version updates only: Dependabot's security updates, for a release that
# fixes a published advisory, are proposed at once.
# See docs/source/smarter-platform/system-administration/security/supply-chain.rst.
#------------------------------------------------------------------------------
version: 2
updates:
# Python ("pip") is left out on purpose. Dependabot's changes to the
# pip-compile lockfiles routinely broke the platform: it moved pins in ways
# that left pip unable to install the lockfile. A maintainer updates the
# Python lockfiles with make python-requirements and runs the tests. The
# same two weeks' wait is checked there, by make python-cooldown.
- package-ecosystem: "npm"
directory: "/"
ignore:
# v10+ requires conventional-changelog-writer@9, but
# @semantic-release/release-notes-generator@14 still bundles writer@8.
- dependency-name: "conventional-changelog-conventionalcommits"
update-types: ["version-update:semver-major"]
labels:
- "dependencies"
- "javascript"
- "automated pr"
schedule:
interval: "monthly"
target-branch: "alpha"
cooldown:
default-days: 14
- package-ecosystem: "github-actions"
directory: "/.github"
labels:
- "dependencies"
- "automated pr"
schedule:
interval: "monthly"
target-branch: "alpha"
cooldown:
default-days: 14
- package-ecosystem: "helm"
directory: "/helm/charts/smarter"
labels:
- "dependencies"
- "automated pr"
target-branch: "alpha"
schedule:
interval: "quarterly"
cooldown:
default-days: 14