import os
import sys
import glob


class Distribution:
    def __init__(self, path):
        """
        Construct a distribution from a path to the metadata dir
        """
        self.path = path

    @classmethod
    def for_name(cls, name, path=sys.path):
        for path_item in path:
            glob_spec = os.path.join(path_item, f'{name}-*.dist-info')
            match = next(glob.iglob(glob_spec))
            return cls(os.path.join(path_item, match))

    @classmethod
    def for_module(cls, mod):
        return cls.for_name(cls.dist_name_for_module(mod))

    @staticmethod
    def name_for_module(mod):
        return getattr(mod, '__dist_name__', mod.__name__)

@@ -26,16 +26,64 @@
 rt glob%0A
+import email%0Aimport itertools%0Aimport contextlib%0A
 %0A%0Aclass 
@@ -354,18 +354,37 @@
 lob_spec
+s
  =
+ (%0A               
  os.path
@@ -415,20 +415,81 @@
 %7D-*.
-dist
+*-info'),%0A                os.path.join(path_item, f'%7Bname%7D.*
 -info')
-%0A
+,%0A    
     
@@ -500,20 +500,63 @@
     
-match = next
+)%0A            globs = itertools.chain.from_iterable(map
 (glo
@@ -562,17 +562,18 @@
 ob.iglob
-(
+, 
 glob_spe
@@ -573,19 +573,52 @@
 lob_spec
+s
 ))%0A
+            match = next(globs)%0A
         
@@ -744,21 +744,16 @@
 ame(cls.
-dist_
 name_for
@@ -874,8 +874,478 @@
 name__)%0A
+%0A    @property%0A    def metadata(self):%0A        return email.message_from_string(%0A            self.load_metadata('METADATA') or self.load_metadata('PKG-INFO')%0A            )%0A%0A    def load_metadata(self, name):%0A        fn = os.path.join(self.path, name)%0A        with contextlib.suppress(FileNotFoundError):%0A            with open(fn, encoding='utf-8') as strm:%0A                return strm.read()%0A%0A    @property%0A    def version(self):%0A        return self.metadata%5B'Version'%5D%0A

Implement metadata loading and version retrieval