Skip to content

MNT: Finish removing distutils and setuptools dependencies #1190

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

Merged
merged 7 commits into from
Jan 31, 2023

Conversation

effigies
Copy link
Member

distutils is removed in Python 3.12. Looking at https://github.com/python/cpython/blob/3467991/Lib/distutils/ccompiler.py#L919-L956, it turns out the single place we were still importing it was redundant with checking os.name.

Setuptools has recommended against using pkg_resources for some time, and it seems that importlib.resources has settled on an API that has been stable since Python 3.9. We can use the importlib_resources backport for Python 3.8.

@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Base: 91.88% // Head: 92.17% // Increases project coverage by +0.29% 🎉

Coverage data is based on head (ad439f5) compared to base (3fabc03).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1190      +/-   ##
==========================================
+ Coverage   91.88%   92.17%   +0.29%     
==========================================
  Files          97       97              
  Lines       12317    12341      +24     
  Branches     2168     2535     +367     
==========================================
+ Hits        11317    11375      +58     
+ Misses        663      645      -18     
+ Partials      337      321      -16     
Impacted Files Coverage Δ
nibabel/gifti/gifti.py 93.33% <ø> (ø)
nibabel/__init__.py 100.00% <100.00%> (ø)
nibabel/pkg_info.py 66.66% <100.00%> (ø)
nibabel/testing/__init__.py 98.18% <100.00%> (+0.12%) ⬆️
nibabel/fileutils.py 100.00% <0.00%> (ø)
nibabel/arrayproxy.py 100.00% <0.00%> (ø)
nibabel/analyze.py 98.59% <0.00%> (+<0.01%) ⬆️
nibabel/freesurfer/mghformat.py 95.06% <0.00%> (+0.02%) ⬆️
nibabel/arraywriters.py 96.86% <0.00%> (+0.02%) ⬆️
nibabel/freesurfer/io.py 94.24% <0.00%> (+0.02%) ⬆️
... and 15 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@effigies effigies force-pushed the mnt/setuptools-distutils-purge branch from bb96b5d to 580b628 Compare January 30, 2023 02:26
@effigies
Copy link
Member Author

This is pretty straightforward, IMO, if anybody wants to do a review. Drive-bys welcome.

Will merge at the end of the week if no reviews.

Copy link
Contributor

@ZviBaratz ZviBaratz left a comment

Choose a reason for hiding this comment

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

👍🏼
Left one comment with something I wasn't sure about.

os.path.join(os.path.dirname(__file__), '..', 'tests', 'data')
)
for subdir in ('nicom', 'gifti', 'externals'):
assert test_data(subdir) == os.path.join(data_path[:-10], subdir, 'tests', 'data')
assert str(test_data(subdir)) == os.path.join(
data_path.parent.parent, subdir, 'tests', 'data'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is data_path a Path instance? If so, wouldn't it be more natural to use the / operator instead of os.path.join? Also, maybe the assertions could use the samefile method?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added fa5f920 to address this. LMK what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM.
I might, at some point in the future, if you don't think it's a bad idea, make a refactoring PR with a bunch of more explicit variable naming suggestions, e.g., here my instinct would be to do something like:

expected = data_path.parent.parent / subdir / 'tests' / 'data'
assert str(test_data(subdir)) == expected

Copy link
Member Author

Choose a reason for hiding this comment

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

You're more than welcome to.

@effigies effigies force-pushed the mnt/setuptools-distutils-purge branch from 580b628 to ad439f5 Compare January 30, 2023 21:25
@effigies
Copy link
Member Author

@ZviBaratz Thanks for the review. In addition to fa5f920, I also added ad439f5 to rename test_data to get_test_data while we're here. This resolves a complaint from pytest whenever we import the function at the module level of a test file:

PytestReturnNotNoneWarning: Expected None, but nibabel/cmdline/tests/test_conform.py::test_data returned '/home/chris/Projects/nipy/nibabel/nibabel/tests/data', which will be an error in a future version of pytest.  Did you mean to use `assert` instead of `return`?

Figured I'd throw it in while I was here.

@effigies effigies merged commit fc9a1c1 into nipy:master Jan 31, 2023
@effigies effigies deleted the mnt/setuptools-distutils-purge branch January 31, 2023 13:57
@effigies effigies added this to the 5.1.0 milestone Mar 29, 2023
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.

2 participants