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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move future.graph to skimage.graph #6674

Merged
merged 8 commits into from Jan 18, 2023
Merged

Conversation

lagru
Copy link
Member

@lagru lagru commented Jan 17, 2023

Description

Closes #3105.

Not sure if we want some outstanding changes to the API but I figured, this way we could get the discussion started. I opted to make all moved submodules private as I expect the contained public functions to be exposed in skimage.graph. Also, I removed the duplication of cut_normalized in ncut; unless there is a specific reason to keep both functions, I'd rather have "one-- and preferably only one --obvious way to [call] it". 馃槈

Checklist

  • Docstrings for all functions
  • Gallery example in ./doc/examples (new features only)
  • Benchmark in ./benchmarks, if your changes aren't covered by an
    existing benchmark
  • Unit tests
  • Clean style in the spirit of PEP8
  • Descriptive commit messages (see below)

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • There is a bot to help automate backporting a PR to an older branch. For
    example, to backport to v0.19.x after merging, add the following in a PR
    comment: @meeseeksdev backport to v0.19.x
  • To run benchmarks on a PR, add the run-benchmark label. To rerun, the label
    can be removed and then added again. The benchmark output can be checked in
    the "Actions" tab.

I opted to make all moved submodules private as I expect the contained
public functions to be exposed in `skimage.graph`.

Also, I removed the duplication of `cut_normalized` in `ncut`.
@lagru lagru added the 馃摐 type: API Involves API change(s) label Jan 17, 2023
@stefanv
Copy link
Member

stefanv commented Jan 17, 2023

How about an error upon import of skimage.future.graph with an appropriate message on how to update code?

@lagru
Copy link
Member Author

lagru commented Jan 17, 2023

Great, call. Seems like an obvious thing to do now. 馃檲 I'm on it.

I'm optimistically using v0.20 here. If this is not merged in time,
I'll update it accordingly for v0.21.
skimage/future/graph.py Outdated Show resolved Hide resolved
Copy link
Member

@stefanv stefanv left a comment

Choose a reason for hiding this comment

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

Some minor suggestions to take or leave.

Comment on lines +6 to +10
with pytest.raises(ModuleNotFoundError, match=error_msg):
import skimage.future.graph

with pytest.raises(ModuleNotFoundError, match=error_msg):
from skimage.future import graph
Copy link
Member

Choose a reason for hiding this comment

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

These two tests test the same import?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the module and the contained raise statement is run regardless of the import statement. This even applies for the from skimage.future.graph import x case! You can see the test's passing in the CI for the install from sdist job. Other jobs fail because they trigger the raise statement during doctest collection...

I haven't yet figured out the best approach to resolve this. We could likely use pytest_ignore_collect but I'd like to avoid that for a temporary patch.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using a warning instead would work. But the migration message doesn't appear as nicely at the end of the traceback..

Copy link
Member Author

@lagru lagru Jan 18, 2023

Choose a reason for hiding this comment

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

Interesting. Adding the following to our conftest.py

def pytest_ignore_collect(collection_path, path, config):
    return str(collection_path).endswith("skimage/future/graph.py")

works to ignore the ModuleNotFoundError in graph.py . However, it then stumbles across

raise ImportError("The GDAL Library could not be found. "
"Please refer to http://www.gdal.org/ "
"for further instructions.")

I'm lost why that isn't the case if I remove pytest_ignore_collect. 馃 Do we have some magic somewhere that ignores that file during doctest collection?

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha:

collect_ignore = ["io/_plugins",]

Comment on lines +12 to +13
with pytest.raises(ModuleNotFoundError, match=error_msg):
from skimage.future.graph import rag
Copy link
Member

Choose a reason for hiding this comment

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

No way the above tests pass and this one fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

But they do. See #6674 (comment). 馃槄

Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
@lagru lagru force-pushed the move-future-graph branch 3 times, most recently from 9f2f7c6 to 9dc056e Compare January 18, 2023 12:07
Not doing this will trigger the ModuleNotFoundError in
skimage/future/graph/__init__.py. The ignore_collect entry doesn't seem
to work if `graph` is a module in `skimage.future`; it works when we
turn it into a package.
@jarrodmillman jarrodmillman added this to the 0.20 milestone Jan 18, 2023
@lagru
Copy link
Member Author

lagru commented Jan 18, 2023

Finally green. As both of you approved I'm going ahead and merge this now. Thanks for the fast reviews!

@lagru lagru merged commit bf3cd84 into scikit-image:main Jan 18, 2023
@lagru lagru deleted the move-future-graph branch January 18, 2023 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃摐 type: API Involves API change(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move future.graph.* to skimage.graph
3 participants