-
Notifications
You must be signed in to change notification settings - Fork 553
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
Add params to brownie run #398
Comments
Thanks for this proposal! I agree with you on all points:
If you are OK with implementing the functionality, I'm happy to add it to the next release 👍 |
hey folks, came across this issue cause i was hoping to add command-line arguments to a brownie |
@davidfloyd91 yes, sorry, but I could not to find any time for this proposal implementation last year. I'm not python developer so can't develop it fast |
Hiya Did this ever get resolved? Im trying to run I have args = sys.argv[1:] to catch --name etc like normal python But brownie doesnt seem to like this command line format and returns error Is there a solution ? Cheers |
looks to be included in https://github.com/eth-brownie/brownie/releases/tag/v1.17.0 👀 |
@iamdefinitelyahuman close plz |
yes, can confirm this works! thank you kindly for your work @wysenynja! just note that args are always parsed as strings, so they might require some casting. |
@jorijnsmit @wysenynja @pjenness I was wondering if you can provide some clarification on usage. Is it possible to have For example, I have this script with two required arguments (aaa, bbb) and one optional (ccc): import argparse
from brownie import config, network
def run(aaa, bbb, ccc=None):
print("in run")
print(aaa)
print(bbb)
print(ccc)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
# configure default parameters for event messaging
parser.add_argument("--aaa", type=int, required=True, help="aaa")
parser.add_argument("--bbb", type=str, required=True, help="bbb")
parser.add_argument("--ccc", type=str, required=False, help="ccc (optional)")
args = parser.parse_args()
print("Inside main (never prints with `brownie run` call)", args)
run(args.aaa, args.bbb, args.ccc) If I run with python directly, i.e.
I get:
However, if I run with
Example 1: No optional argument, works
Example 2: With optional argument, works
Example 3: With dashes, does NOT work:
|
Ok, now digging a bit into the code. It is right around here where it checks the parsed arguments: brownie/brownie/utils/docopt.py Line 842 in ef0d5af
When running the above code,
I see this pattern defined:
Notice matched
left
collected
The next line: brownie/brownie/utils/docopt.py Line 843 in ef0d5af
sees left contains something (--ccc ) and as a result bombs out with DocoptExit exception.
So given that, I'm not sure how to pass |
I use click for my extra parsing. I have it use \ as my prefix (instead of --) so that docopt doesn't try to parse them
… On Mar 24, 2022, at 7:31 AM, ClaudeF4491 ***@***.***> wrote:
Ok, now digging a bit into the code. brownie run calls doctopt to parse out all the configs.
@iamdefinitelyahuman tagging you since I see you were the contributor to doctopt. Wondering if you have any ideas or ways to get kwargs to work with brownie commands.
It is right around here where it checks the parsed arguments:
https://github.com/eth-brownie/brownie/blob/ef0d5af3bb48edcd11abf985626fc99dbc577c7d/brownie/utils/docopt.py#L842
When running the above code,
$ brownie run scripts/sample.py run 1 2 --ccc=3
I see this pattern defined:
Required(
Required(
Command('run', False),
Argument('<filename>', None),
NotRequired(
Argument('<function>', None)
),
NotRequired(
OneOrMore(
Argument('<arg>', None)
)
),
NotRequired(
OptionsShortcut(
Option(None, '--network', 1, None),
Option(None, '--silent', 0, False),
Option('-I', '--interactive', 0, False),
Option('-r', '--raise', 0, False),
Option('-g', '--gas', 0, False),
Option('-t', '--tb', 0, False),
Option('-h', '--help', 0, False)
)
)
)
)
Notice OptionsShortcut. That's the only place where -- kwargs can be caught. As a result, the pattern.fix().match(parsed_arg_vector) sticks --ccc argument into the left variable.
matched
matched = True
left
left = [Option(None, '--ccc', 1, '3')]
collected
collected = [Command('run', True), Argument('<filename>', 'scripts/sample.py'), Argument('<function>', 'run'), Argument('<arg>', ['1', '2'])]
[Option(None, '--ccc', 1, '3')]
[Command('run', True), Argument('<filename>', 'scripts/sample.py'), Argument('<function>', 'run'), Argument('<arg>', ['1', '2'])]
n
The next line: https://github.com/eth-brownie/brownie/blob/ef0d5af3bb48edcd11abf985626fc99dbc577c7d/brownie/utils/docopt.py#L843
sees left contains something (--ccc) and as a result bombs out with DocoptExit exception.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
|
Overview
Now we can put args and kwargs into brownie run, when we are using brownie console mode (here in code), but we can't do it through calling of
brownie run
from shell. Possible it's very useful feature in CI/CD, scripts etcSpecification
For example we can add args and kwargs so:
brownie run <filename> [<function>] [<args1>] … [<argsN>] [options] [kwargs]
, where*
[<args1>] … [<argsN>]
- is tuple of args*
[kwars]
- is kwargs, but without reserves keys like--network
Dependencies
I could not search.
If we can do these changes, than I can implement it at the next week.
The text was updated successfully, but these errors were encountered: