vug / python-project-boilerplate

A skeleton repository to start new Python projects faster.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boilerplate for Python Projects

Description

Skeleton code for a new Python project.

  • Layout
  • Dependencies
    • pipenv based dependency management
    • It also handles virtual environment management
    • Basic development libraries included such as
      • flake8 for linting, formatting style and other warnings
      • black for auto formatting. Frees developers from thinking about style and bikeshedding
      • pytest for unittesting
      • mypy for static type checking (tried pyre-check first but thanks to Unix only dependency fcntl it does not work on windows.)
  • setup.py for distribution
  • README.md for project description
  • .gitignore for common files not needed in version control
  • Recommended editors

Usage

  • Download the project zip file (TODO: think about a flow with git clone)
  • Rename files and folder according to new project name
  • pipenv
    • if pipenv does not exist in base Python distribution install it via pip install pipenv
    • pipenv install --dev --pre to create virtual environment for the project under ~/.virtualenvs/PROJECT_NAME-hash and install developer dependencies. (Currently --pre is needed for black because its version is less then 1.)
    • to activate project environment pipenv shell
    • (note that the project itself is in "packages" of Pipfile, which runs pip install -e . with above command. That installs the project as a module to virtual environment too. It is required by pytest.)
  • git init to initialize a git repo
  • for VS Code
    • set python.pythonPath setting (TODO: figure out the right way of doing this.)
    • install following extensions if not already installed
  • Runing unittests
    • CLI: Run either pytest or python -m pytest from project root
      • (The latter puts project root to sys.path)
      • python -m pytest tests/ --collect-only command to only discover tests
    • VS Code: Tests can be discovered and run from the "Tests" tab. Individual tests can be run from the opened file directly.
      • (Added an __init__.py file in tests/ folder to turn it into a package (which can do imports from sibling packages). It shouldn't be needed but the way test discovery mechanism works in VS Code Python extension requires that. See 1, 2 )

About

A skeleton repository to start new Python projects faster.


Languages

Language:HTML 96.1%Language:Python 3.9%