Skip to content

Commit 4b10086

Browse files
committed
Now unconditionally run pep517 to retrieve metadata for a local package.
1 parent 8a62944 commit 4b10086

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

importlib_metadata/__init__.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,11 @@ def _discover_resolvers():
198198
return filter(None, declared)
199199

200200
@classmethod
201-
def find_local(cls):
202-
return cls._from_pyproject() or cls._heuristic_local()
203-
204-
@staticmethod
205-
def _from_pyproject():
206-
with suppress(Exception):
207-
from pep517.build_meta import build_meta_as_zip
208-
return PathDistribution(build_meta_as_zip())
209-
210-
@classmethod
211-
def _heuristic_local(cls):
212-
dists = itertools.chain.from_iterable(
213-
resolver(path=['.', 'src'])
214-
for resolver in cls._discover_resolvers()
215-
)
216-
dist, = dists
217-
return dist
201+
def find_local(cls, root='.'):
202+
import pep517.build_meta as bm
203+
system = bm.compat_build_system(root)
204+
builder = functools.partial(bm.build_meta, build_system=system)
205+
return PathDistribution(zipp.Path(bm.build_meta_as_zip(builder)))
218206

219207
@property
220208
def metadata(self):

importlib_metadata/tests/fixtures.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,18 @@ def setUp(self):
150150

151151

152152
class LocalPackage:
153+
files = {
154+
"setup.py": """
155+
import setuptools
156+
setuptools.setup(name="local-pkg", version="2.0.1")
157+
""",
158+
}
159+
153160
def setUp(self):
154161
self.fixtures = ExitStack()
155162
self.addCleanup(self.fixtures.close)
156163
self.fixtures.enter_context(tempdir_as_cwd())
157-
build_files(EggInfoPkg.files)
164+
build_files(self.files)
158165

159166

160167
def build_files(file_defs, prefix=pathlib.Path()):

importlib_metadata/tests/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,5 @@ def test_more_complex_deps_requires_text(self):
156156
class LocalProjectTests(fixtures.LocalPackage, unittest.TestCase):
157157
def test_find_local(self):
158158
dist = local_distribution()
159-
assert dist.metadata['Name'] == 'egginfo-pkg'
159+
assert dist.metadata['Name'] == 'local-pkg'
160+
assert dist.version == '2.0.1'

0 commit comments

Comments
 (0)