Skip to main content

Python project quick scripts

Project description

Python project quick scripts

Define simple development scripts in pyproject.toml

Developing a Python project usually involves many tasks: setting up, installing prerequisites, building, testing, cleaning up build products, etc. It can be difficult to remember which program to run to perform a given task for a given project, particularly when many different tools are being used.

ppqs defines simple ("quick") scripts in pyproject.toml, and provides a command-line utility -- ppqs -- to run them. In this way ppqs hides the details of whatever dependency/virtual environment manager, build front-end, test harness, etc. the project uses behind a simple interface.

Here is an example of ppqs being used for its own project:

$ ppqs --help
Quick scripts for Python project: ppqs

Usage: ppqs {init,lint,build,test,clean}

Scripts:
  init   Initialise project
  lint   Perform linting checks
  build  Build project
  test   Run tests
  clean  Clean up build files

Scripts are always run from the project root directory, i.e. the directory containing pyproject.toml. ppqs traverses back through parent directories until it finds the root directory. It is therefore safe to run ppqs from any sub-directory within the project directory tree.

Script definition in pyproject.toml

ppqs scripts are simple lists of commands which are run in sequence. If a command errors, the remainder of the script is aborted.

Scripts are defined in pyproject.toml under the [tool.ppqs.scripts] section. Script names may contain only lowercase letters ([a-z]) and dashes (-). Scripts may be single or multi-line strings: commands are separated by newlines, and command arguments are separated by spaces.

[tool.ppqs.scripts]
init = "command"
lint = """
command
"""
build = """
command1 -v
command2 -q
"""

Scripts may also be defined as lists of lists, i.e. a list of commands, each of which is a list of arguments:

[tool.ppqs.scripts]
test = [
    ["command1"],
    ["command2", "-vv"],
]
clean = [
    ["command"],
]

If a script contains an ellipsis (...) it is replaced with any additional arguments passed to ppqs. For example, the following script:

[tool.ppqs.scripts]
print-something = "echo ..."

may be run as

$ ppqs print-something Hi
Hi

Scripts may also be defined in their own section, which permit a few options:

[tool.ppqs.scripts.init]
description = "Initialise project"
print_header = true
script = """
command
"""

[tool.ppqs.scripts.build]
# default description = "Run build script"
# default print_header = false
script = [
    ["command1", "-v"],
    ["command2", "-q"],
]
"""

where:

  • description [optional]: description of the script which appears in ppqs --help. Default is Run {name} script where name is the script name.

  • print_header [optional]: If true, print a header before running each command in the script. The header consists of the command to be run, centred on the console and padded with *s. Default is false.

Commands are not parsed to the shell, so e.g. wildcards are not expanded. If the features of a shell script are needed (wildcards, conditional statements, etc.), one can write a helper script, e.g. scripts/lots-to-do.py, which may then be called by ppqs as:

[tool.ppqs.scripts]
lots-to-do = [["python", "scripts/lots-to-do.py"]]

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

ppqs-1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

ppqs-1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ppqs-1.0.tar.gz.

File metadata

  • Download URL: ppqs-1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ppqs-1.0.tar.gz
Algorithm Hash digest
SHA256 2e059462dff5e7caaa3bec65eaa5a336f3be0428442bbe40ab667a68a8587255
MD5 f48cfaabec0b69debe038bfde8da52b7
BLAKE2b-256 eeae5886b39edc3f74c8f91b59c3b8b1d29715e9c68bb2e11420d98638126b1e

See more details on using hashes here.

File details

Details for the file ppqs-1.0-py3-none-any.whl.

File metadata

  • Download URL: ppqs-1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ppqs-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c28fc28dbd82caa1b6ea88cea2982124e441fd5986656e3b87c1650b7f23630c
MD5 caec03718efb01cf411b3a9fb482e026
BLAKE2b-256 d1ea67d30b5371db7cc1c0c754012a3b4612931d85598af96f13c5518f2ed151

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