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

Add bundle root directory to Python search directories automatically #6910

Merged
merged 19 commits into from
Aug 31, 2023

Conversation

KumoLiu
Copy link
Contributor

@KumoLiu KumoLiu commented Aug 29, 2023

Fixes #6722 .

Description

Add scripts directory to Python search directories automatically in the run function in ConfigWorkflow.

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.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • 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: KumoLiu <yunl@nvidia.com>
@KumoLiu
Copy link
Contributor Author

KumoLiu commented Aug 29, 2023

Hi @ericspod, could you please help review whether this one can help fix #6722? I added the scripts folder in the sys.path before running. This one should be merged after #6835.
cc @wyli @Nic-Ma

@wyli wyli requested review from ericspod and Nic-Ma August 29, 2023 09:43
monai/bundle/workflows.py Outdated Show resolved Hide resolved
@ericspod
Copy link
Member

This looks in the right direction. We should have a test for it which creates a bundle with a scripts directory containing __init__.py with a single function definition. The bundle would call this function which would just print something to stdout and we'd check that value appears in the output. This test should use subprocess to run the bundle as a command line program to ensure a new Python runtime is created which has its own isolated environment.

Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
@KumoLiu
Copy link
Contributor Author

KumoLiu commented Aug 29, 2023

This looks in the right direction. We should have a test for it which creates a bundle with a scripts directory containing __init__.py with a single function definition. The bundle would call this function which would just print something to stdout and we'd check that value appears in the output. This test should use subprocess to run the bundle as a command line program to ensure a new Python runtime is created which has its own isolated environment.

Agreed, will add the test ASAP, thanks!

KumoLiu and others added 12 commits August 30, 2023 22:19
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
This reverts commit 9fca72e.

Signed-off-by: KumoLiu <yunl@nvidia.com>
…-MONAI#6913)

Fixes Project-MONAI#6471 

### Description

A few sentences describing the changes proposed in this pull request.

### 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).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] 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: monai-bot <monai.miccai2019@gmail.com>
Co-authored-by: monai-bot <monai.miccai2019@gmail.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Fixes Project-MONAI#6911.

### 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.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] 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: KumoLiu <yunl@nvidia.com>
Fixes Project-MONAI#6834.

### Description
This PR introduces the idea of `BundleManager`, with `get` as one of the
methods, to avoid repeatedly instantiating `ConfigWorkflow`.

**usage**
```
bundle = BundleManager("spleen_ct_segmentation")
bundle.get("network_data_format")

or

bundle.get(property="train_preprocessing")
```

### 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).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] 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: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
…dd_scripts

Signed-off-by: KumoLiu <yunl@nvidia.com>
I, KumoLiu <yunl@nvidia.com>, hereby add my Signed-off-by to this commit: 1eb0d8c

Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
@KumoLiu KumoLiu marked this pull request as ready for review August 30, 2023 14:50
Signed-off-by: KumoLiu <yunl@nvidia.com>
@KumoLiu
Copy link
Contributor Author

KumoLiu commented Aug 30, 2023

Hi @ericspod, and @wyli, I have added unit tests for this PR, could you please help review it again? Thanks in advance!
cc @Nic-Ma

@KumoLiu KumoLiu requested review from ericspod and wyli August 30, 2023 14:56
Signed-off-by: KumoLiu <yunl@nvidia.com>
monai/bundle/workflows.py Outdated Show resolved Hide resolved
@KumoLiu KumoLiu changed the title Add scripts directory to Python search directories automatically Add bundle root directory to Python search directories automatically Aug 31, 2023
Signed-off-by: KumoLiu <yunl@nvidia.com>
@wyli
Copy link
Contributor

wyli commented Aug 31, 2023

/build

Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it looks good to me.

@wyli wyli enabled auto-merge (squash) August 31, 2023 06:25
@wyli wyli merged commit be4e1f5 into Project-MONAI:dev Aug 31, 2023
37 checks passed
@KumoLiu KumoLiu deleted the add_scripts branch August 31, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add scripts directory to Python search directories automatically and avoid using PYTHONPATH
4 participants