Poetry: Saving custom scripts in pyproject.toml (alias npm run)

Created on 5 Jun 2020  路  5Comments  路  Source: python-poetry/poetry

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

Feature Request

What do you think of having a scripts described in pyproject.toml ? Something like Procfile or script section in packages.json.

Here is a suggestion of configuration & usage:

[tools.poetry.proc]
build = "python manage.py collectstatic"
test = "pytest tests/unit/"
serve = "flask run"
$ poetry proc build
...
$ poetry proc serve
...

I think it would help project to not require Makefile nor tox to share commands and in the same time, ensure commands are properly executed in selected environment.

What do you think of this ?

Plugins

Most helpful comment

@SanketDG I think it's something else.

  • scripts is about shipping CLI entrypoints to final users. Think /usr/bin/command
  • proc is about sharing recipes or command alias to developers. Think tox -e unit

All 5 comments

@SanketDG I think it's something else.

  • scripts is about shipping CLI entrypoints to final users. Think /usr/bin/command
  • proc is about sharing recipes or command alias to developers. Think tox -e unit

This has been discussed in #591 which was closed with https://github.com/python-poetry/poetry/pull/591#issuecomment-504762152.

As was stated there, this might be a candidate feature for a plugin once we have that baked into poetry >=v1.1.0.

@abn yes, that's exactly the subject of this PR :-) A plugin is a good fit for this feature.

@bersace in the mean time I'd suggest checking out a project I'm working on that solves this problem in a slightly different way

Poe the Poet a task runner that works well with poetry.

It provides a flexible system for defining tasks in the pyroject.toml and executing them with a dedicated executable. Basic usage looks like:

Example configuration with different task types:

[tool.poe.tasks]
test       = "pytest --cov=poethepoet"                                # simple command based task
mksandwich = { script = "my_package.sandwich:build" }                 # python script based task
tunnel     = { shell = "ssh -N -L 0.0.0.0:8080:$PROD:8080 $PROD &" }  # shell script based task

Example invocation:

# extra argument is passed to the underlying pytest command
poe test -v   

# If poethepoet is added as a dev-dependency
poetry run poe tunnel

And it supports zsh command completion!

Was this page helpful?
0 / 5 - 0 ratings