Skip to content

str2list utility for commandline parsing of comma separated lists#5358

Merged
wyli merged 4 commits intoProject-MONAI:devfrom
myron:argparse
Oct 19, 2022
Merged

str2list utility for commandline parsing of comma separated lists#5358
wyli merged 4 commits intoProject-MONAI:devfrom
myron:argparse

Conversation

@myron
Copy link
Copy Markdown
Collaborator

@myron myron commented Oct 19, 2022

This adds a utility function str2list to convert a string to a list. Useful with argparse commandline arguments:

        parser.add_argument("--blocks", default=[1,2,3], type=str2list)
        ...
        python mycode.py --blocks=1,2,2,4

Unit tests added.

It also includes a small fix for str2bool to accept input as bool (and return it right away).

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • [ x Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • [x]Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: myron <[email protected]>
@myron myron added the enhancement New feature or request label Oct 19, 2022
@myron myron added this to the Auto3D Seg framework [P0 v1.0] milestone Oct 19, 2022
myron added 2 commits October 18, 2022 18:49
Signed-off-by: myron <[email protected]>
Signed-off-by: myron <[email protected]>
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Oct 19, 2022

/build

@wyli wyli enabled auto-merge (squash) October 19, 2022 11:48
@wyli wyli merged commit c17c825 into Project-MONAI:dev Oct 19, 2022
wyli pushed a commit that referenced this pull request Oct 19, 2022
)

This adds a utility function str2list to convert a string to a list.
Useful with argparse commandline arguments:
```
        parser.add_argument("--blocks", default=[1,2,3], type=str2list)
        ...
        python mycode.py --blocks=1,2,2,4
```
Unit tests added.

It also includes a small fix for str2bool to accept input as bool (and
return it right away).

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ x Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x]Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

Signed-off-by: myron <[email protected]>
@myron myron deleted the argparse branch October 22, 2022 18:52
KumoLiu pushed a commit that referenced this pull request Nov 2, 2022
)

This adds a utility function str2list to convert a string to a list.
Useful with argparse commandline arguments:
```
        parser.add_argument("--blocks", default=[1,2,3], type=str2list)
        ...
        python mycode.py --blocks=1,2,2,4
```
Unit tests added.

It also includes a small fix for str2bool to accept input as bool (and
return it right away).

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ x Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x]Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

Signed-off-by: myron <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants