Skip to main content

Python project template

Project description

python-projector: A collection of simple scripts to manage Python projects

Ruff Actions status
Ruff Actions status
pytest doctest Actions status
uv Actions status

๐Ÿ› ๏ธ Installation

# install with pip
pip install python-projector

# install with uv tool
uv tool install python-projector

[!NOTE] pip-compile and gen-init-py commands depend on uv and ruff.

๐Ÿš€ Usage

 Usage: projector [OPTIONS] COMMAND [ARGS]...

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --version             -v        Show version                                                                         โ”‚
โ”‚ --install-completion            Install completion for the current shell.                                            โ”‚
โ”‚ --show-completion               Show completion for the current shell, to copy it or customize the installation.     โ”‚
โ”‚ --help                -h        Show this message and exit.                                                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ find-pyproject-toml      Find the pyproject.toml file in the current directory or any parent directory.              โ”‚
โ”‚ get-min-python-version   Get the minimum python version from the pyproject.toml file.                                โ”‚
โ”‚ get-src-dir              Print the `src/` directory based on the pyproject.toml file.                                โ”‚
โ”‚ gen-init-py              Generate __init__.py files for all subdirectories of src/.                                  โ”‚
โ”‚ pip-compile              Generate requirements.txt and requirements-dev.txt files.                                   โ”‚
โ”‚ run-doctest              Run doctest for all modules in `src/` directory.                                            โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Find nearest pyproject.toml file with projector find-pyproject-toml

It will find the nearest pyproject.toml file in the current directory or its parent directories.

Get src/ directory with projector get-src-dir

It will read the pyproject.toml's tool.setuptools.packages.find.where setting. If the configuration is not found, it will assume src/ as the default value.

[tool.setuptools.packages.find]
where = ["src"]

Apply uv pip compile with projector pip-compile

Background:

  • uv pip compile is a command that generates a requirements.txt file from a requirements.in file.
  • requirements.in file should contain the direct dependencies of the project, with dynamic versions.
  • requirements.txt file contains all dependencies with pinned versions.
  • This is a thin wrapper around the command to generate requirements.txt files per architecture.
  • There exists --universal flag to generate a universal requirements.txt file, but we don't use it. Instead, we just separate the files per architecture.
    • This is because it makes the requirements overly complicated to read and parse.
  • There exists a better format called uv.lock but this is also more complicated to read and parse.
  • For now, we stick to the requirements.txt format for the sake of simplicity.

Usage:

First, configure in the pyproject.toml file:

[tool.projector.pip-compile]
requirements-in-dir = "deps"
requirements-out-dir = "deps/lock"
python-platforms = ["x86_64-manylinux_2_28", "aarch64-apple-darwin", "x86_64-apple-darwin"]

Then, run the command:

projector pip-compile

It will make deps/lock/{platform}/requirements*.txt files based on the deps/requirements*.in files.

Get minimum Python version with projector get-min-python-version

Given the pyproject.toml file:

[tool.project]
requires-python = ">=3.10,<4"

It will output the minimum Python version:

$ projector get-min-python-version
3.10

This is useful in CI where you want to run unit test etc. with the minimum Python version.
For example, in GitHub Actions:

jobs:
  job-name:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install uv
        uses: astral-sh/setup-uv@v4
      - name: Get minimum Python version
        run: |
          uv tool install python-projector
          echo "min_python_version=$(projector get-min-python-version)" >> "$GITHUB_OUTPUT"
        id: parse-python-version
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ steps.parse-python-version.outputs.min_python_version }}
      # ...

[!NOTE] The above is just for a demonstration. You can use deargen/workflows/actions/setup-python-and-uv action to simplify the process.

jobs:
  job-name:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: deargen/workflows/actions/setup-python-and-uv@master

Generate __init__.py files with projector gen-init-py

Generate __init__.py files recursively in the src/ directory found like projector get-src-dir.

This is useful for mkdocs because it requires __init__.py in all modules.

Run doctest with projector run-doctest

Run doctest with all modules in the src/ directory found like projector get-src-dir.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_projector-0.1.9.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_projector-0.1.9-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file python_projector-0.1.9.tar.gz.

File metadata

  • Download URL: python_projector-0.1.9.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for python_projector-0.1.9.tar.gz
Algorithm Hash digest
SHA256 fdf396c082ca4b81fe6921dac1816ec0a85828a3fb33b7d9ff86aae5da945c2c
MD5 f5f872acfc45734ae765e919de54e0d4
BLAKE2b-256 ab7f01bdbb09fd8c8c5089a744f34a1d34b00d54e16508f8249fa75cd8f05101

See more details on using hashes here.

File details

Details for the file python_projector-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for python_projector-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 804abf200f4dfe2b5a6f6c49fb4368d672ed58ae486aa2dabe1c2e4740ff4afb
MD5 56812c6a2894d5629b2dafc5b2534e02
BLAKE2b-256 1b8716160aac6ee0d9bf9a37faf0164d3421d5e1ea6f8f019b9f9ea000a0b738

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page