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

bpo-34632: Add importlib.metadata #12547

Merged
merged 27 commits into from
May 24, 2019
Merged

bpo-34632: Add importlib.metadata #12547

merged 27 commits into from
May 24, 2019

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Mar 26, 2019

This PR is a revised submission of #9327, based on bugfixes and improvements in importlib_metadata and taken directly from this branch.

https://bugs.python.org/issue34632

@jaraco jaraco requested a review from warsaw March 26, 2019 02:27
@brettcannon brettcannon added the type-feature A feature request or enhancement label Mar 27, 2019
@warsaw warsaw self-assigned this May 8, 2019
@jaraco
Copy link
Member Author

jaraco commented May 8, 2019

Looks now like failure is due to “test altered execution environment”. I think I saw sys.path being the environment that changed.

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

I suspect here is where sys.path is modified, but it is configured for teardown... so I'm surprised that it's triggering an 'altered' state.

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

Is the problem that self.addCleanup triggers the cleanup after another cleanup which is the 'altered' state check?

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

It seems the cleanup isn't getting called at all. I see sys.path with lots of entries for each test.

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

I'm able to replicate the "env changed" message locally:

$ ./python.exe Tools/scripts/run_tests.py test_importlib                                                                              
/Users/jaraco/code/public/cpython/python.exe -u -W default -bb -E -m test -r -w -j 0 -u all,-largefile,-audio,-gui test_importlib
Using random seed 1623474
Run tests in parallel using 6 child processes
0:00:01 load avg: 2.62 [1/1/1] test_importlib failed (env changed)

== Tests result: SUCCESS ==

1 test altered the execution environment:
    test_importlib

Total duration: 1 sec 540 ms
Tests result: SUCCESS
Warning -- sys.path was modified by test_importlib
  Before: (4439706808, ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'], ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'])
  After:  (4439706808, ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'], ['/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp3un01wot', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpm4bh4sb8', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2glvc5g4', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpxagbns7g', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpkqq09z88', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpybwwkldb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpjrxbrcx4', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp3bqfx8c_', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpxglfdb3u', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2zh5smyz', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp0bki67z5', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpd5ti08im', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp774axu9f', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpyjsv0_ei', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpdcynlnrx', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpbmrhx8oi', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmppkmtdnhy', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpog7645lh', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpha97_n7i', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpf8yr_9fy', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi9kpfvfi', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmphfvcyaey', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp77b982cd', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpwo5jn6hb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp9kz9gl_r', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpnshum4ni', '/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'])

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

I can see that the cleanup is happening after the "env changed" test:

cpython feature/34632-importlib-metadata $ ./python.exe Tools/scripts/run_tests.py test_importlib                                                                              
/Users/jaraco/code/public/cpython/python.exe -u -W default -bb -E -m test -r -w -j 0 -u all,-largefile,-audio,-gui test_importlib
Using random seed 3567225
Run tests in parallel using 6 child processes
Warning -- sys.path was modified by test_importlib
  Before: (4451798200, ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'], ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'])
  After:  (4451798200, ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'], ['/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp9cq08gun', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpq_z03ei5', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpgu1o2fta', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpoewzu0wd', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp5bd2m0gt', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpehnzjm5b', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp_xro47k9', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpv0o7v2p_', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpg2hgwlfx', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp8elix7w0', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpqf_8zguy', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpp2em5inv', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmppoznxfez', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpqfk3fa7x', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpmnp9cc4i', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmprwxxp8vb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp_hnhesk1', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpw4w2t3jb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpq1n27cy4', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpa8bun_kk', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpushi37s7', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2uv_i5lb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp56iz114p', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp_b9751hb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp9re6n3sa', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpc2q0ee23', '/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'])
0:00:01 load avg: 2.02 [1/1/1] test_importlib failed (env changed)
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpc2q0ee23
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp9re6n3sa
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp_b9751hb
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp56iz114p
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2uv_i5lb
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpushi37s7
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpa8bun_kk
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpq1n27cy4
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpw4w2t3jb
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp_hnhesk1
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmprwxxp8vb
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpmnp9cc4i
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpqfk3fa7x
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmppoznxfez
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpp2em5inv
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpqf_8zguy
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp8elix7w0
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpg2hgwlfx
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpv0o7v2p_
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp_xro47k9
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpehnzjm5b
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp5bd2m0gt
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpoewzu0wd
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpgu1o2fta
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpq_z03ei5
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp9cq08gun
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpeaezl_wj

== Tests result: SUCCESS ==

1 test altered the execution environment:
    test_importlib

Total duration: 1 sec 561 ms
Tests result: SUCCESS

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

I tried changing addCleanup to use a tearDown method:

$ git diff                                                                                                                            
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py
index 737ea4be7a..d0078d913d 100644
--- a/Lib/test/test_importlib/fixtures.py
+++ b/Lib/test/test_importlib/fixtures.py
@@ -28,6 +28,7 @@ def tempdir():
     try:
         yield pathlib.Path(tmpdir)
     finally:
+        print('removing', tmpdir)
         sys.path.remove(tmpdir)
         shutil.rmtree(tmpdir)
 
@@ -59,9 +60,11 @@ class SiteDir:
 
     def setUp(self):
         self.fixtures = ExitStack()
-        self.addCleanup(self.fixtures.close)
         self.site_dir = self.fixtures.enter_context(self.site_dir())
 
+    def tearDown(self):
+        self.fixtures.close()
+
 
 class DistInfoPkg(SiteDir):
     files = {

But in that case, the result is very similar:

$ ./python.exe Tools/scripts/run_tests.py test_importlib                                                                              
/Users/jaraco/code/public/cpython/python.exe -u -W default -bb -E -m test -r -w -j 0 -u all,-largefile,-audio,-gui test_importlib
Using random seed 5122858
Run tests in parallel using 6 child processes
0:00:01 load avg: 2.09 [1/1/1] test_importlib failed (env changed)
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2mn8c_rt
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpjojbdy6h
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmplzrf45xw
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp5xc2nqgv
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2wh1c2cl
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpxbneoebv
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpb0ha4jzr
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp631lolar
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpvgq1xqwz
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmptsv8ofbr
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmprqggn4a0
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp19ja_08v
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpzcbzq1p1
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpgd9gfxkx
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp3fmpsw8v
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp3ydo05ba
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpjy8kgxhd
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpio3gjcx7
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi93snf1a
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpv_bdmvcu
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmplu54y0iw
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpukmkbivj
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpo6chps4r
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp8htx0s1u
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2tinzf17
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpczvuokxb
removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp5qyepn45

== Tests result: SUCCESS ==

1 test altered the execution environment:
    test_importlib

Total duration: 1 sec 514 ms
Tests result: SUCCESS
Warning -- sys.path was modified by test_importlib
  Before: (4511550648, ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'], ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'])
  After:  (4511550648, ['/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'], ['/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpczvuokxb', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2tinzf17', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp8htx0s1u', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpo6chps4r', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpukmkbivj', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmplu54y0iw', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpv_bdmvcu', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi93snf1a', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpio3gjcx7', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpjy8kgxhd', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp3ydo05ba', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp3fmpsw8v', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpgd9gfxkx', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpzcbzq1p1', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp19ja_08v', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmprqggn4a0', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmptsv8ofbr', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpvgq1xqwz', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp631lolar', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpb0ha4jzr', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpxbneoebv', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2wh1c2cl', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp5xc2nqgv', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmplzrf45xw', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpjojbdy6h', '/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmp2mn8c_rt', '/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages'])

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

If I run the tests thus:

$ git diff                                                                                                                            
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py
index 737ea4be7a..bd5d0e48da 100644
--- a/Lib/test/test_importlib/fixtures.py
+++ b/Lib/test/test_importlib/fixtures.py
@@ -28,7 +28,9 @@ def tempdir():
     try:
         yield pathlib.Path(tmpdir)
     finally:
+        print('removing', tmpdir)
         sys.path.remove(tmpdir)
+        print(sys.path)
         shutil.rmtree(tmpdir)

I can see the remove operation seems to be failing to remove items from sys.path:

removing /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmppi9fuire
['/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmppi9fuire', '/Users/jaraco/code/public/cpython', '/usr/local/lib/python38.zip', '/Users/jaraco/code/public/cpython/Lib', '/Users/jaraco/code/public/cpython/build/lib.macosx-10.14-x86_64-3.8', '/usr/local/lib/python3.8/site-packages']

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

Aha! So it seems that the path items are somehow getting added to sys.path twice, causing the .remove to only remove one.

@jaraco
Copy link
Member Author

jaraco commented May 10, 2019

In this ticket, I describe the issue and implemented the change, ported in 58533a7.

@jaraco
Copy link
Member Author

jaraco commented May 11, 2019

@warsaw Tests are passing, so I think this is ready for your final review and merge. We can of course iterate over the coming weeks to refine the implementation.

@jaraco
Copy link
Member Author

jaraco commented May 11, 2019

Oh - still needs:

  • "provisional" note.

@jaraco
Copy link
Member Author

jaraco commented May 14, 2019

@warsaw I think we're ready to accept this. Is there anything more you want to see before landing it?

an iterator over instances of the ``Distribution`` abstract class. This
method must have the signature::

def find_distributions(name=None, path=sys.path):
Copy link
Member

Choose a reason for hiding this comment

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

We actually changed this signature to find_distributions(name=None, path=None) to account for changes in sys.path after the function's definition. See this MR.

@warsaw
Copy link
Member

warsaw commented May 24, 2019

Hi @jaraco - I had just one comment about the documentation. If you can update that and resolve the conflict, I am ready to approve this PR. Thanks!

@jaraco
Copy link
Member Author

jaraco commented May 24, 2019

Yes, good catch. I'm also planning to merge in the 0.14 release. I'll make sure this change happens with that as well.

@warsaw
Copy link
Member

warsaw commented May 24, 2019

Yes, good catch. I'm also planning to merge in the 0.14 release. I'll make sure this change happens with that as well.

I just tagged 0.15 with this fix (without updating the changelog :( ) but I'm not sure I did that correctly.

@jaraco
Copy link
Member Author

jaraco commented May 24, 2019

OOh. Got almost all c's in that last shorthash. (small pleasures)

@warsaw
Copy link
Member

warsaw commented May 24, 2019

Sigh, if only GH had "merge when CI succeeds" button. :/

I will hover over "Squash and merge" as if I was trying to get an A position on Southwest.

@vstinner
Copy link
Member

vstinner commented Jun 4, 2019

This change should be mention in https://docs.python.org/dev/whatsnew/3.8.html : it's a new module, no?

DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
Add importlib.metadata module as forward port of the standalone importlib_metadata.
@jaraco jaraco deleted the feature/34632-importlib-metadata branch May 9, 2020 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants