Skip to content

Move future.graph to skimage.graph#6674

Merged
lagru merged 8 commits intoscikit-image:mainfrom
lagru:move-future-graph
Jan 18, 2023
Merged

Move future.graph to skimage.graph#6674
lagru merged 8 commits intoscikit-image:mainfrom
lagru:move-future-graph

Conversation

@lagru
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

lagru commented Jan 17, 2023

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

lagru added 2 commits January 17, 2023 22:50
I'm optimistically using v0.20 here. If this is not merged in time,
I'll update it accordingly for v0.21.
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.
@lagru lagru force-pushed the move-future-graph branch from 9dc056e to 4a36c0f Compare January 18, 2023 12:08
@jarrodmillman jarrodmillman added this to the 0.20 milestone Jan 18, 2023
@lagru
Copy link
Copy Markdown
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