File tree Expand file tree Collapse file tree 5 files changed +39
-0
lines changed
Expand file tree Collapse file tree 5 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,17 @@ def _discover_resolvers():
242242 )
243243 return filter (None , declared )
244244
245+ @classmethod
246+ def _local (cls , root = '.' ):
247+ from pep517 import build , meta
248+ system = build .compat_system (root )
249+ builder = functools .partial (
250+ meta .build ,
251+ source_dir = root ,
252+ system = system ,
253+ )
254+ return PathDistribution (zipp .Path (meta .build_as_zip (builder )))
255+
245256 @property
246257 def metadata (self ):
247258 """Return the parsed metadata for this Distribution.
Original file line number Diff line number Diff line change 55v1.6.1
66======
77
8+ * Added ``Distribution._local() `` as a provisional
9+ demonstration of how to load metadata for a local
10+ package. Implicitly requires that
11+ `pep517 <https://pypi.org/project/pep517 >`_ is
12+ installed. Ref #42.
813* Ensure inputs to FastPath are Unicode. Closes #121.
914* Tests now rely on ``importlib.resources.files `` (and
1015 backport) instead of the older ``path `` function.
Original file line number Diff line number Diff line change @@ -166,6 +166,21 @@ def setUp(self):
166166 build_files (EggInfoFile .files , prefix = self .site_dir )
167167
168168
169+ class LocalPackage :
170+ files = {
171+ "setup.py" : """
172+ import setuptools
173+ setuptools.setup(name="local-pkg", version="2.0.1")
174+ """ ,
175+ }
176+
177+ def setUp (self ):
178+ self .fixtures = contextlib .ExitStack ()
179+ self .addCleanup (self .fixtures .close )
180+ self .fixtures .enter_context (tempdir_as_cwd ())
181+ build_files (self .files )
182+
183+
169184def build_files (file_defs , prefix = pathlib .Path ()):
170185 """Build a set of files/directories, as described by the
171186
Original file line number Diff line number Diff line change @@ -174,3 +174,10 @@ def test_distribution_at_str(self):
174174 dist_info_path = self .site_dir / 'distinfo_pkg-1.0.0.dist-info'
175175 dist = Distribution .at (str (dist_info_path ))
176176 assert dist .version == '1.0.0'
177+
178+
179+ class LocalProjectTests (fixtures .LocalPackage , unittest .TestCase ):
180+ def test_find_local (self ):
181+ dist = Distribution ._local ()
182+ assert dist .metadata ['Name' ] == 'local-pkg'
183+ assert dist .version == '2.0.1'
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ universal=1
5555testing =
5656 importlib_resources>=1.3; python_version < "3.9"
5757 packaging
58+ pep517
5859docs =
5960 sphinx
6061 rst.linker
You can’t perform that action at this time.
0 commit comments