Commits

Anonymous committed 7eb4f89

added egg_info_dirname

Comments (0)

Files changed (2)

 
 
 SEP_TRANS = maketrans('/', os.path.sep)
+SPACE_TRANS = maketrans(' ', '.')
+DASH_TRANS = maketrans('-', '_')
 
 #
 # EggInfo class (with DistributionMetadata in it)
     dirs = EggInfoDirectories(paths)
     return dirs.get_file_users(path)
 
+def egg_info_dirname(name, version):
+    name = re.sub('[^A-Za-z0-9.]+', '_', name)
+    version = version.translate(SPACE_TRANS)
+    version = re.sub('[^A-Za-z0-9.]+', '_', version)
+    return '%s-%s.egg-info' % (name.translate(DASH_TRANS),
+                               version.translate(DASH_TRANS))
 
     users = list(get_file_users('mercurial/filelog.py', [SITE_PKG]))
     assert_equals(len(users), 2)
 
+def test_egg_info_dirname():
+    assert egg_info_dirname('zlib', '2.5.2') == 'zlib-2.5.2.egg-info'
+    assert egg_info_dirname('python-ldap', '2.5'), 'python_ldap-2.5.egg-info'
+    assert egg_info_dirname('python-ldap', '2.5 a---5'), 'python_ldap-2.5.a_5.egg-info'