Skip to content

Latest commit

 

History

History
127 lines (99 loc) · 4.97 KB

python.md

File metadata and controls

127 lines (99 loc) · 4.97 KB

Python

Books

Newsletters

Getting started

  1. Install python3 using ansible-ctrl/roles/dev
  2. Link python to python3
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 0
    

Libraries and frameworks

Name Description
Beautiful Soup Parser, scraper
DevPi Python PyPi staging server and packaging, testing, release tool
Django High-level web framework
FastAPI A modern, fast, web framework for building APIs. Based on Python type hints.
Flask Micro framework for building web applications
NumPy Scientific computing library
Pillow Open and manipulate many image file formats
pytest A framework that makes it easy to write small, readable tests
records A library for making raw SQL queries to most relational databases
requests A simple, yet elegant, HTTP library
SQLAlchemy SQL toolkit and Object Relational Mapper
Typer Build great CLIs. Easy to code. Based on Python type hints. Built on top of Click.

Tools

Name Description
Black Formatter for VS Code Support the black formatter (use ruff instead)
Flake8 for VS Code Support for the flake8 linter (use ruff instead)
Pipenv Dev workflows for humans (use Poetry instead)
Pipx
Poe A task runner that works well with poetry
Poetry Python packaging and dependency management made easy
pre-commit A framework for managing multi-language pre-commit hooks
Python for VS Code Support intelliSense, linting, debugging, code navigation, code formatting, etc
ruff

How-tos

Getting started with Poetry

  1. Install pipx
  2. Install poetry pipx install poetry
  3. Run poetry init
  4. Update pyproject.toml

Poetry configuration

  • Linux ~/.config/pypoetry
  • macOS ~/Library/Application\ Support/pypoetry/config.toml
# Configure Poetry to install venvs in the project directory, so that VSCode can enable them automatically
poetry config virtualenvs.in-project true

# Set PYPI access token
poetry config pypi-token.pypi ${token}

Develop a non-redistributable (no setup.py) local package using Pipenv

Add an .env file to the project root:

PYTHONPATH=.

Pipenv and

Add a pytest.ini file to the project root:

[pytest]
pythonpath = .

Add the following line to .vscode/launch.json configurations:

"envFile": "${workspaceFolder}/.env",

Example:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: File with env",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "justMyCode": true,
            "envFile": "${workspaceFolder}/.env",
        }
    ]
}

VS Code test discovery doesn't find any tests

This only occurs when starting VS Code from a terminal that already has an active virtualenv (eg. after running pipenv shell).

  1. CTRL+Shift+P
  2. Select "Python: Select Interpreter"
  3. Select the correct interpreter
  4. Open "Text Explorer"