Exemple #1
0
 def test_write(self):
     dfn = self.temp_filename()
     # Read legacy, write new
     sfn = os.path.join(HERE, 'fake_dists', 'choxie-2.0.0.9.dist-info',
                        'METADATA')
     md = Metadata(path=sfn)
     md.write(path=dfn)
     with codecs.open(dfn, 'r', 'utf-8') as f:
         data = json.load(f)
     self.assertEqual(data, {
         'metadata_version': '2.0',
         'generator': 'distlib (%s)' % __version__,
         'name': 'choxie',
         'version': '2.0.0.9',
         'license': 'BSD',
         'summary': 'Chocolate with a kick!',
         'description': 'Chocolate with a longer kick!',
         'provides': ['truffles (1.0)', 'choxie (2.0.0.9)'],
         'run_requires': [{'requires': ['towel-stuff (0.1)', 'nut']}],
         'keywords': [],
     })
     # Write legacy, compare with original
     md.write(path=dfn, legacy=True)
     nmd = Metadata(path=dfn)
     d1 = md.todict()
     d2 = nmd.todict()
     self.assertEqual(d1, d2)
Exemple #2
0
 def test_write(self):
     dfn = self.temp_filename()
     # Read legacy, write new
     sfn = os.path.join(HERE, 'fake_dists', 'choxie-2.0.0.9.dist-info',
                        LEGACY_METADATA_FILENAME)
     md = Metadata(path=sfn)
     md.write(path=dfn)
     with codecs.open(dfn, 'r', 'utf-8') as f:
         data = json.load(f)
     self.assertEqual(
         data, {
             'metadata_version': '2.0',
             'generator': 'distlib (%s)' % __version__,
             'name': 'choxie',
             'version': '2.0.0.9',
             'license': 'BSD',
             'summary': 'Chocolate with a kick!',
             'description': 'Chocolate with a longer kick!',
             'provides': ['truffles (1.0)', 'choxie (2.0.0.9)'],
             'run_requires': [{
                 'requires': ['towel-stuff (0.1)', 'nut']
             }],
             'keywords': [],
         })
     # Write legacy, compare with original
     md.write(path=dfn, legacy=True)
     nmd = Metadata(path=dfn)
     d1 = md.todict()
     d2 = nmd.todict()
     self.assertEqual(d1, d2)
Exemple #3
0
def make_metadata(project_dir):
    md = Metadata()
    md.name = input('name >>> ')
    md.version = input('version >>> ')
    md.summary = input('summary >>> ')
    dist_path = os.path.join(project_dir, 'dist-info')
    if not os.path.exists(dist_path):
        os.makedirs(dist_path)
    md.write(path=os.path.join(dist_path,
                               'pydist.json'))
    return md
Exemple #4
0
def convert_egg_info(libdir, prefix, options):
    files = os.listdir(libdir)
    ei = list(filter(lambda d: d.endswith('.egg-info'), files))[0]
    olddn = os.path.join(libdir, ei)
    di = EGG_INFO_RE.sub('.dist-info', ei)
    newdn = os.path.join(libdir, di)
    os.rename(olddn, newdn)
    if options.compatible:
        renames = {}
    else:
        renames = {
            'entry_points.txt': 'EXPORTS',
        }
    excludes = set([
        'SOURCES.txt',          # of no interest in/post WHEEL
        'installed-files.txt',  # replaced by RECORD, so not needed
        'requires.txt',         # added to METADATA, so not needed
        'PKG-INFO',             # replaced by METADATA
        'not-zip-safe',         # not applicable
    ])
    files = os.listdir(newdn)
    metadata = mdname = reqts = None
    for oldfn in files:
        pn = os.path.join(newdn, oldfn)
        if oldfn in renames:
            os.rename(pn, os.path.join(newdn, renames[oldfn]))
        else:
            if oldfn == 'requires.txt':
                with open(pn, 'r') as f:
                    reqts = get_requirements(f.read())
            elif oldfn == 'PKG-INFO':
                metadata = Metadata(path=pn)
                pd = get_package_data(metadata.name, metadata.version)
                metadata = Metadata(mapping=pd['index-metadata'])
                mdname = os.path.join(newdn, 'pydist.json')
            if oldfn in excludes or not options.compatible:
                os.remove(pn)
    if metadata:
        # Use Metadata 1.2 or later
        metadata.provides += ['%s (%s)' % (metadata.name,
                                           metadata.version)]
        # Update if not set up by get_package_data
        if reqts and not metadata.run_requires:
            metadata.dependencies = reqts
        metadata.write(path=mdname)
    manifest = Manifest(os.path.dirname(libdir))
    manifest.findall()
    paths = manifest.allfiles
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    dist.write_installed_files(paths, prefix)
Exemple #5
0
    def test_get_file(self):
        # Create a fake dist
        temp_site_packages = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_site_packages)

        dist_name = 'test'
        dist_info = os.path.join(temp_site_packages, 'test-0.1.dist-info')
        os.mkdir(dist_info)

        metadata_path = os.path.join(dist_info, 'pydist.json')
        resources_path = os.path.join(dist_info, 'RESOURCES')
        md = Metadata()
        md.name = 'test'
        md.version = '0.1'
        md.summary = 'test'
        md.write(path=metadata_path)
        test_path = 'test.cfg'

        fd, test_resource_path = tempfile.mkstemp()
        os.close(fd)
        self.addCleanup(os.remove, test_resource_path)

        fp = open(test_resource_path, 'w')
        try:
            fp.write('Config')
        finally:
            fp.close()

        fp = open(resources_path, 'w')
        try:
            fp.write('%s,%s' % (test_path, test_resource_path))
        finally:
            fp.close()

        # Add fake site-packages to sys.path to retrieve fake dist
        self.addCleanup(sys.path.remove, temp_site_packages)
        sys.path.insert(0, temp_site_packages)

        # Try to retrieve resources paths and files
        d = DistributionPath()
        self.assertEqual(d.get_file_path(dist_name, test_path),
                         test_resource_path)
        self.assertRaises(KeyError, d.get_file_path, dist_name,
                          'i-dont-exist')
Exemple #6
0
    def test_get_file(self):
        # Create a fake dist
        temp_site_packages = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_site_packages)

        dist_name = 'test'
        dist_info = os.path.join(temp_site_packages, 'test-0.1.dist-info')
        os.mkdir(dist_info)

        metadata_path = os.path.join(dist_info, 'pydist.json')
        resources_path = os.path.join(dist_info, 'RESOURCES')
        md = Metadata()
        md.name = 'test'
        md.version = '0.1'
        md.summary = 'test'
        md.write(path=metadata_path)
        test_path = 'test.cfg'

        fd, test_resource_path = tempfile.mkstemp()
        os.close(fd)
        self.addCleanup(os.remove, test_resource_path)

        fp = open(test_resource_path, 'w')
        try:
            fp.write('Config')
        finally:
            fp.close()

        fp = open(resources_path, 'w')
        try:
            fp.write('%s,%s' % (test_path, test_resource_path))
        finally:
            fp.close()

        # Add fake site-packages to sys.path to retrieve fake dist
        self.addCleanup(sys.path.remove, temp_site_packages)
        sys.path.insert(0, temp_site_packages)

        # Try to retrieve resources paths and files
        d = DistributionPath()
        self.assertEqual(d.get_file_path(dist_name, test_path),
                         test_resource_path)
        self.assertRaises(KeyError, d.get_file_path, dist_name, 'i-dont-exist')
Exemple #7
0
    def test_get_file(self):
        # Create a fake dist
        temp_site_packages = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_site_packages)

        dist_name = "test"
        dist_info = os.path.join(temp_site_packages, "test-0.1.dist-info")
        os.mkdir(dist_info)

        metadata_path = os.path.join(dist_info, "pydist.json")
        resources_path = os.path.join(dist_info, "RESOURCES")
        md = Metadata()
        md.name = "test"
        md.version = "0.1"
        md.summary = "test"
        md.write(path=metadata_path)
        test_path = "test.cfg"

        fd, test_resource_path = tempfile.mkstemp()
        os.close(fd)
        self.addCleanup(os.remove, test_resource_path)

        fp = open(test_resource_path, "w")
        try:
            fp.write("Config")
        finally:
            fp.close()

        fp = open(resources_path, "w")
        try:
            fp.write("%s,%s" % (test_path, test_resource_path))
        finally:
            fp.close()

        # Add fake site-packages to sys.path to retrieve fake dist
        self.addCleanup(sys.path.remove, temp_site_packages)
        sys.path.insert(0, temp_site_packages)

        # Try to retrieve resources paths and files
        d = DistributionPath()
        self.assertEqual(d.get_file_path(dist_name, test_path), test_resource_path)
        self.assertRaises(KeyError, d.get_file_path, dist_name, "i-dont-exist")
Exemple #8
0
def convert_egg_info(libdir, prefix):
    files = os.listdir(libdir)
    ei = list(filter(lambda d: d.endswith('.egg-info'), files))[0]
    olddn = os.path.join(libdir, ei)
    di = EGG_INFO_RE.sub('.dist-info', ei)
    newdn = os.path.join(libdir, di)
    os.rename(olddn, newdn)
    files = os.listdir(newdn)
    for oldfn in files:
        pn = os.path.join(newdn, oldfn)
        if oldfn == 'PKG-INFO':
            md = Metadata(path=pn)
            mn = os.path.join(newdn, METADATA_FILENAME)
            md.write(mn)
        os.remove(pn)
    manifest = Manifest(os.path.dirname(libdir))
    manifest.findall()
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    dist.write_installed_files(manifest.allfiles, prefix)
Exemple #9
0
def convert_egg_info(libdir, prefix):
    files = os.listdir(libdir)
    ei = list(filter(lambda d: d.endswith('.egg-info'), files))[0]
    olddn = os.path.join(libdir, ei)
    di = EGG_INFO_RE.sub('.dist-info', ei)
    newdn = os.path.join(libdir, di)
    os.rename(olddn, newdn)
    files = os.listdir(newdn)
    for oldfn in files:
        pn = os.path.join(newdn, oldfn)
        if oldfn == 'PKG-INFO':
            md = Metadata(path=pn)
            mn = os.path.join(newdn, METADATA_FILENAME)
            md.write(mn)
        os.remove(pn)
    manifest = Manifest(os.path.dirname(libdir))
    manifest.findall()
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    dist.write_installed_files(manifest.allfiles, prefix)
Exemple #10
0
    def test_write_metadata(self):
        # check support of non-ASCII values
        tmp_dir = self.mkdtemp()
        my_file = os.path.join(tmp_dir, 'f')

        metadata = Metadata(mapping={'author': 'Mister Café',
                                     'name': 'my.project',
                                     'author': 'Café Junior',
                                     'summary': 'Café torréfié',
                                     'description': 'Héhéhé',
                                     'keywords': ['café', 'coffee']})
        metadata.write(my_file)

        # the file should use UTF-8
        metadata2 = Metadata()
        fp = codecs.open(my_file, encoding='utf-8')
        try:
            metadata2.read_file(fp)
        finally:
            fp.close()

        # XXX when keywords are not defined, metadata will have
        # 'Keywords': [] but metadata2 will have 'Keywords': ['']
        # because of a value.split(',') in Metadata.get
        self.assertEqual(metadata.items(), metadata2.items())

        # ASCII also works, it's a subset of UTF-8
        metadata = Metadata(mapping={'author': 'Mister Cafe',
                                     'name': 'my.project',
                                     'author': 'Cafe Junior',
                                     'summary': 'Cafe torrefie',
                                     'description': 'Hehehe'})
        metadata.write(my_file)

        metadata2 = Metadata()
        fp = codecs.open(my_file, encoding='utf-8')
        try:
            metadata2.read_file(fp)
        finally:
            fp.close()
Exemple #11
0
 def wheel_modifier_ver(self, path_map):
     mdpath = path_map['dummy-0.1.dist-info/%s' % LEGACY_METADATA_FILENAME]
     md = Metadata(path=mdpath)
     md.version = '0.1+123'
     md.write(path=mdpath, legacy=True)
     return True
Exemple #12
0
 def wheel_modifier(self, path_map):
     mdpath = path_map['dummy-0.1.dist-info/%s' % LEGACY_METADATA_FILENAME]
     md = Metadata(path=mdpath)
     md.add_requirements(['numpy'])
     md.write(path=mdpath, legacy=True)
     return True
Exemple #13
0
 def wheel_modifier_ver(self, path_map):
     mdpath = path_map["dummy-0.1.dist-info/pydist.json"]
     md = Metadata(path=mdpath)
     md.version = "0.1+123"
     md.write(path=mdpath)
     return True
Exemple #14
0
 def wheel_modifier(self, path_map):
     mdpath = path_map["dummy-0.1.dist-info/pydist.json"]
     md = Metadata(path=mdpath)
     md.add_requirements(["numpy"])
     md.write(path=mdpath)
     return True
Exemple #15
0
 def wheel_modifier_ver(self, path_map):
     mdpath = path_map['dummy-0.1.dist-info/pydist.json']
     md = Metadata(path=mdpath)
     md.version = '0.1+123'
     md.write(path=mdpath)
     return True
Exemple #16
0
 def wheel_modifier(self, path_map):
     mdpath = path_map['dummy-0.1.dist-info/pydist.json']
     md = Metadata(path=mdpath)
     md.add_requirements(['numpy'])
     md.write(path=mdpath)
     return True