Skip to content

Latest commit

 

History

History
118 lines (102 loc) · 4.73 KB

Developer-Setup.md

File metadata and controls

118 lines (102 loc) · 4.73 KB

Many different setups are possible. There is no right way of setting up your environment. The following serves as self-documentation and example.

rgaudin's with Sublime Text

# create (if missing) default env, installing dependencies
# also verifies default env's python version (use a matrix for default with a single value to set otherwise)
hatch run python -V

# make sure it's correct
hatch env show
hatch env find

# symlink hatch's default environment into `./.venv` (in project)
ln -s "$(hatch env find)" .venv

The key part is the symlink to .venv so that LSP-pyright and other tool can automatically find the environment and properly detect the installed dependencies.

benoit74's with Visual Studio Code

  • macOS
  • brew
  • pyenv (installed with brew)
  • Python:
    • at least each supported and released minor versions (i.e. security + bugfix on https://devguide.python.org/versions/)
    • installed with pyenv install x.y.z
    • all supported and released minor versions are set in /Users/<username>/.python-version (i.e. available when looking for a version with python, python3, python3.x, ...)
  • When doing some JS, you obviously need a Node.JS as well
  • hatch installed globally
  • Visual Studio Code with following extensions (more or less related to Python development)
    • Black Formater (Microsoft)
    • Dev Containers (Microsoft)
    • Docker (Microsoft)
    • Excalidraw (pomdtr)
    • Even Better TOML (tamasfe)
    • GitLens (GitKraken)
    • Jupyter (Microsoft)
    • Pylance (Microsoft)
    • Python (Microsoft)
    • Remote Development (Microsoft)
    • reStructuredText (LeXtudio Inc.)
    • Ruff (Astral Software)
    • Volar (Vue)
    • YAML (Red Hat)
    • Prettier (Prettier)
    • ESLint (Microsoft)

Hatch is configured with an additional section in config.toml (configuration file is located in ~/Library/Application Support/hatch, see https://hatch.pypa.io/latest/config/hatch/, correct file is shown by hatch status in any case).

[dirs.env]
virtual = ".hatch"

This additional Hatch config section ensures that all virtual environments (the only built-in environment in hatch is virtual - for now at least) are created in a .hatch subfolder inside the project folder ; it is mandatory so that Visual Studio Code will be able to find these dependencies.

On every project, create a local .vscode/settings.json to automatically format your code (adjust typeCheckingMode depending on your project):

{
  "[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.codeActionsOnSave": {
      "source.organizeImports": "explicit"
    }
  },
  "python.analysis.typeCheckingMode": "strict",
  "eslint.validate": ["javascript", "typescript", "vue"],
  "eslint.workingDirectories": [{ "mode": "auto" }],
  "editor.rulers": [88],
  "editor.codeActionsOnSave": {
    "source.fixAll": "always",
    "source.formatDocument": "always"
  },
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}

For some projects, you might need to add extra configuration to specify where Python modules can be found:

{
  ...
  "python.analysis.extraPaths": [
    "scraper/src",
    "scraper/.hatch/libretexts2zim/lib/python3.12/site-packages"
  ],
  ...
}

When starting to work on a project, start a shell on default env + installing dependencies + start VSCode ; starting VSCode from inside the hatch shell ensures he will find automatically the proper Python version and dependencies

hatch shell
pip install '.[dev]'
code .