Skip to the content.

PyPoject Starter

Build Status license Documentation Status GitHub repo size codecov

A template for the python project. It uses poetry for dependency management and tox for testing.

Features

Some features in this template project:

Project

Contains the following projects under src as demo:

Prerequisite

Run project need the following environment installed:

If you want development, you need to install pre-commit V3 for git hook scripts.

Installation

following the steps below to setup the project:

# Clone the repository
git clone git@github.com:funnyzak/pyproject-starter.git && cd pyproject-starter

# Install all dependencies
poetry install --sync --all-extras --with dev,test,coverage

# install git hook scripts for development
pre-commit install

# Other useful installation dependencies commands
# Install dependencies with all extras
poetry install --all-extras
# Install dependencies with extras 'pdf' for pdf_parse project
poetry install --extras "pdf"
# Install dependencies with group 'dev'、'test' for development
poetry install --with dev,test
# Only install required dependencies for production
poetry install

# Specify python version
poetry env use python3.9

Usage

There are some useful commands for development:

# Run project => hello
poetry run hello

# Run project => pdf_parse: merge pdf
poetry run merge_pdf_demo

# Run project => pdf_parse: parse multi pdf to multi-layer pdf
poetry run multi_layer_pdf_demo

# Extract text to json from pdf
poetry run extract_text_from_pdf

# Debug "hello" project with ipdb3
poetry run ipdb3 ./src/hello/main.py

# Code test
poetry run pytest -s

# Run default coverage test
poetry run tox

# Run hello project coverage test at python 3.9 and 3.10
poetry run tox -e py{39,310}-hello

# Lint with black
poetry run black ./src --check

# Format code with black
poetry run black ./src

# Check with mypy
poetry run mypy ./src

# Check import order with isort
poetry run isort ./src --check

# Lint with flake8
poetry run flake8 ./src

Q&A

Development

Add new project

  1. Create a new folder under src folder.
  2. You can copy the hello project as a template.
  3. Add folder name to packages in pyproject.toml file.
  4. Code and test it.

Tip for project

Environment setup

install poetry

See poetry installation.

install python3

See python installation.

install pre-commit

See pre-commit installation.

References

some useful references:

Contribution

If you have any questions or suggestions, please feel free to open an issue or pull request.

License

MIT License © 2022 funnyzak