-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
BUG: don't mutate list of fake libraries while iterating over it #18295
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2e8acc
BUG: don't mutate list of fake libraries while iterating over it
mckib2 9a23e7a
BUG: iterate over copy of list
mckib2 13603d4
TST: add build test for build_ext fix (#1)
mckib2 07730c1
FIX: check for f77 compiler before test is run
mckib2 8201407
DOC: add comment explaining that a list copy is necessary
mckib2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| '''Tests for numpy.distutils.build_ext.''' | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| from textwrap import indent, dedent | ||
| import pytest | ||
|
|
||
| @pytest.mark.slow | ||
| def test_multi_fortran_libs_link(tmp_path): | ||
| ''' | ||
| Ensures multiple "fake" static libraries are correctly linked. | ||
| see gh-18295 | ||
| ''' | ||
| # make some dummy sources | ||
| with open(tmp_path / '_dummy1.f', 'w') as fid: | ||
| fid.write(indent(dedent('''\ | ||
| FUNCTION dummy_one() | ||
| RETURN | ||
| END FUNCTION'''), prefix=' '*6)) | ||
| with open(tmp_path / '_dummy2.f', 'w') as fid: | ||
| fid.write(indent(dedent('''\ | ||
| FUNCTION dummy_two() | ||
| RETURN | ||
| END FUNCTION'''), prefix=' '*6)) | ||
| with open(tmp_path / '_dummy.c', 'w') as fid: | ||
| # doesn't need to load - just needs to exist | ||
| fid.write('int PyInit_dummyext;') | ||
|
|
||
| # make a setup file | ||
| with open(tmp_path / 'setup.py', 'w') as fid: | ||
| srctree = os.path.join(os.path.dirname(__file__), '..', '..', '..') | ||
| fid.write(dedent(f'''\ | ||
| def configuration(parent_package="", top_path=None): | ||
| from numpy.distutils.misc_util import Configuration | ||
| config = Configuration("", parent_package, top_path) | ||
| config.add_library("dummy1", sources=["_dummy1.f"]) | ||
| config.add_library("dummy2", sources=["_dummy2.f"]) | ||
| config.add_extension("dummyext", sources=["_dummy.c"], libraries=["dummy1", "dummy2"]) | ||
| return config | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import sys | ||
| sys.path.insert(0, r"{srctree}") | ||
| from numpy.distutils.core import setup | ||
| setup(**configuration(top_path="").todict())''')) | ||
|
|
||
| # build the test extensino and "install" into a temporary directory | ||
| build_dir = tmp_path | ||
| subprocess.check_call([sys.executable, 'setup.py', 'build', 'install', | ||
| '--prefix', str(tmp_path / 'installdir'), | ||
| '--record', str(tmp_path / 'tmp_install_log.txt'), | ||
| ], | ||
| cwd=str(build_dir), | ||
| ) | ||
| # get the path to the so | ||
| so = None | ||
| with open(tmp_path /'tmp_install_log.txt') as fid: | ||
| for line in fid: | ||
| if 'dummyext' in line: | ||
| so = line.strip() | ||
| break | ||
| assert so is not None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment above this line that
[:]is on purpose, to not modify the original list? Otherwise the next over-eager code cleanup may undo the fix again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an explanation is latest push, feel free to resolve or suggest different wording