Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for callable scripts #5396

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,20 @@ For example:
$ pipenv run echospam "indeed"
I am really a very silly example indeed

You can then display the names and commands of your shortcuts by running ``pipenv scripts`` in your terminal.
You can also specify pacakge functions as callables such as: ``<pathed.module>:<func>``. These can also take arguments.
For exaple:

.. code-block:: toml

[scripts]
my_func_with_args = {call = "package.module:func('arg1', 'arg2')"}
my_func_no_args = {call = "package.module:func()"}

::
oz123 marked this conversation as resolved.
Show resolved Hide resolved
$ pipenv run my_func_with_args
$ pipenv run my_func_no_args

You can display the names and commands of your shortcuts by running ``pipenv scripts`` in your terminal.

::

Expand Down
1 change: 1 addition & 0 deletions news/5396.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update pipenv docs for with example for callabale package functions in Pipfile scripts
4 changes: 3 additions & 1 deletion pipenv/cmdparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def _parse_toml_inline_table(value: tomlkit.items.InlineTable) -> str:
if cmd_key == "call":
module, _, func = str(value["call"]).partition(":")
if not module or not func:
raise ScriptParseError("Callable must be like: <pathed.module>:<func>")
raise ScriptParseError(
"Callable must be like: name = {call = \"package.module:func('arg')\"}"
)
if re.search(r"\(.*?\)", func) is None:
func += "()"
return f'python -c "import {module} as _m; _m.{func}"'
Expand Down