ML4GW / ML4GW/typeo

Add a `parameterize` keyword argument to `scriptify`

Open
#8 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

allow arguments in for the function passed to scriptify (including those passed by extends) to be parameterized by a set of subcommands that contain additional arguments. Something like the following:

def say_hello(friendliness: int, greeting: str = "hello"):
    if friendliness > 0:
        return f"{greeting} friend!"
    else:
        greeting

def say_goodbye(friendliness: int, see_again: bool = False):
    if friendliness > 0:
        greeting = "so long"
    else:
        greeting = "goodbye"

    if not see_again:
        return f"{greeting} forever!"
    else:
        return f"{greeting} until next time!"


@scriptify(message=[say_hello, say_goodbye])
def main(greeter: str, message: str):
    print(f"Message from {greeter}:\n{message}")

Which could be executed from the command line like:

$ greet --greeter Thom say_hello --friendliness 1 --greeting hi
Message from Thom:
Hi friend!

Under the hood, the parser would pass the friendliness and greeting arguments to say_hello, use those to create a message, and pass this message to main. This implementation should be pretty straightforward, but there is a question about how would this interact with the existing subcommands, and relatedly could we support multiple parameterizations? How would this look in the config? Maybe something like

[tool.typeo]
greeter = "Thom"

[tool.typeo.message.say_hello]
friendliness = 1
greeting = "hey"

[tool.typeo.message.say_goodbye]
friendliness = 0
see_again = false

and the command line execution might be greet --typeo .:::say_hello, with the extra colon indicating that there's no subcommand, but each colon after that reflects a different parameterization, in the order in which they're passed (would there be any order in this **kwargs-like setup?).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the scriptify entry point and the existing subcommands behavior. Define how parameterized functions, extends, multiple parameterizations, command-line syntax, and configuration should interact before implementing anything. Done means the command-line and TOML examples work without breaking existing subcommands.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.