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

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.

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.

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