Skip to content

edchapman88/python-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recommended linter and formatter:

  • Ruff, also available as a VSCode extension.
  • Ruff config in pyproject.toml under [tool.ruff].
  • Linting and format-on-save are available by adding the following to VSCode settings.json once the extension is installed:
"[python]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "charliermarsh.ruff"
  },
  • settings.json can be accessed by searching for Preferences: Open User Settings (JSON) in the VSCode command palette.

Pre-commit hook

  • Check pre-commit is installed:
pre-commit --version
  • If not installed:
brew install pre-commit
  • Generate the git hooks script from the .pre-commit-config.yaml file:
pre-commit install

MyPy type checking

Local workspace checking:

  • mypy must be installed.
    • The best option seems to be to install mypy locally (in the project virtual environment), and then set "mypy.runUsingActiveInterpreter" : true, in VSCode user setting (mentioned above how to find these). The Mypy daemon can then have visibility on the dependencies currently isntalled in the project environment (see info on the daemon below).
  • The VSCode extension (Mypy by Matan Gover, which is better than the Microsoft Mypy Type Checker extension) will run a server to do live type checking of the entire workspace, not just files that have changes.
  • Config in pyproject.toml under [tool.mypy] (it's set up to leave any entirely un-annotated functions un-checked, to provide good type checking whilst allowing for partial type coverage).
  • [[tool.mypy.overrides]] sections in pyproject.toml allow for module specific settings, or applying a set of settings to a list of modules - eg. to blacklist a set of modules that do not have type support and are to be ignored by mypy.

Pre-commit checking:

  • The pre-commit hook will only type check files that have changed, so is not as strict as the local type checking with the VSCode extension (mypy daemon).
  • If an external module does have type support, it should not be blacklisted, and instead the dependency must be added to the .pre-commit-config.yaml file, under additional_dependencies for the mypy hook.
  • The mypy pre-commit checks are run in a seperate python environment, without the modules that have been installed into the project working envionment. This is the reason that the pre-commit hook needs to be aware of the 3rd-party modules that do have type support, and for which type stubs must be fetched.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages