[Python-checkins] r41994 - in sandbox/trunk/setuptools: pkg_resources.py pkg_resources.txt setuptools/tests/test_resources.py

phillip.eby python-checkins at python.org
Tue Jan 10 04:49:23 CET 2006


Author: phillip.eby
Date: Tue Jan 10 04:49:22 2006
New Revision: 41994

Modified:
   sandbox/trunk/setuptools/pkg_resources.py
   sandbox/trunk/setuptools/pkg_resources.txt
   sandbox/trunk/setuptools/setuptools/tests/test_resources.py
Log:
``safe_name()`` now allows dots in project names, and there is a new
``to_filename()`` function that escapes project names and versions for
safe use in constructing egg filenames from a Distribution object's 
metadata.

Note that allowing dots may now cause problems for projects with '.' in 
the name that were previously installed, since such projects had to be 
spelled with a '-' before.  The '-' name will no longer match the '.'
project, and there is no real room for backward compatibility here.  :(


Modified: sandbox/trunk/setuptools/pkg_resources.py
==============================================================================
--- sandbox/trunk/setuptools/pkg_resources.py	(original)
+++ sandbox/trunk/setuptools/pkg_resources.py	Tue Jan 10 04:49:22 2006
@@ -61,7 +61,7 @@
     # Parsing functions and string utilities
     'parse_requirements', 'parse_version', 'safe_name', 'safe_version',
     'get_platform', 'compatible_platforms', 'yield_lines', 'split_sections',
-    'safe_extra',
+    'safe_extra', 'to_filename',
 
     # filesystem utilities
     'ensure_directory', 'normalize_path',
@@ -821,9 +821,9 @@
 def safe_name(name):
     """Convert an arbitrary string to a standard distribution name
 
-    Any runs of non-alphanumeric characters are replaced with a single '-'.
+    Any runs of non-alphanumeric/. characters are replaced with a single '-'.
     """
-    return re.sub('[^A-Za-z0-9]+', '-', name)
+    return re.sub('[^A-Za-z0-9.]+', '-', name)
 
 
 def safe_version(version):
@@ -842,15 +842,15 @@
     Any runs of non-alphanumeric characters are replaced with a single '_',
     and the result is always lowercased.
     """
-    return re.sub('[^A-Za-z0-9]+', '_', extra).lower()
-
-
-
-
-
+    return re.sub('[^A-Za-z0-9.]+', '_', extra).lower()
 
 
+def to_filename(name):
+    """Convert a project or version name to its filename-escaped form
 
+    Any '-' characters are currently replaced with '_'.
+    """
+    return name.replace('-','_')
 
 
 
@@ -1529,7 +1529,7 @@
 
 LINE_END = re.compile(r"\s*(#.*)?$").match         # whitespace and comment
 CONTINUE = re.compile(r"\s*\\\s*(#.*)?$").match    # line continuation
-DISTRO   = re.compile(r"\s*((\w|-)+)").match       # Distribution or option
+DISTRO   = re.compile(r"\s*((\w|[-.])+)").match    # Distribution or extra
 VERSION  = re.compile(r"\s*(<=?|>=?|==|!=)\s*((\w|[-.])+)").match  # ver. info
 COMMA    = re.compile(r"\s*,").match               # comma between items
 OBRACKET = re.compile(r"\s*\[").match
@@ -1846,7 +1846,7 @@
     def egg_name(self):
         """Return what this distribution's standard .egg filename should be"""
         filename = "%s-%s-py%s" % (
-            self.project_name.replace('-','_'), self.version.replace('-','_'),
+            to_filename(self.project_name), to_filename(self.version),
             self.py_version or PY_MAJOR
         )
 

Modified: sandbox/trunk/setuptools/pkg_resources.txt
==============================================================================
--- sandbox/trunk/setuptools/pkg_resources.txt	(original)
+++ sandbox/trunk/setuptools/pkg_resources.txt	Tue Jan 10 04:49:22 2006
@@ -1445,6 +1445,12 @@
     similar to ``safe_name()`` except that non-alphanumeric runs are replaced
     by a single underbar (``_``), and the result is lowercased.
     
+``to_filename(name_or_version)``
+    Escape a name or version string so it can be used in a dash-separated
+    filename (or ``#egg=name-version`` tag) without ambiguity.  You
+    should only pass in values that were returned by ``safe_name()`` or
+    ``safe_version()``.
+
 
 Platform Utilities
 ------------------
@@ -1511,6 +1517,13 @@
 Release Notes/Change History
 ----------------------------
 
+0.6a10
+ * ``safe_name()`` now allows dots in project names.
+
+ * There is a new ``to_filename()`` function that escapes project names and
+   versions for safe use in constructing egg filenames from a Distribution
+   object's metadata.
+
 0.6a9
  * Don't raise an error when an invalid (unfinished) distribution is found
    unless absolutely necessary.  Warn about skipping invalid/unfinished eggs

Modified: sandbox/trunk/setuptools/setuptools/tests/test_resources.py
==============================================================================
--- sandbox/trunk/setuptools/setuptools/tests/test_resources.py	(original)
+++ sandbox/trunk/setuptools/setuptools/tests/test_resources.py	Tue Jan 10 04:49:22 2006
@@ -406,7 +406,7 @@
         self.assertEqual(safe_name("WSGI Utils"),  "WSGI-Utils")
         self.assertEqual(safe_name("WSGI  Utils"), "WSGI-Utils")
         self.assertEqual(safe_name("Money$$$Maker"), "Money-Maker")
-        self.assertEqual(safe_name("peak.web"), "peak-web")
+        self.assertNotEqual(safe_name("peak.web"), "peak-web")
 
     def testSafeVersion(self):
         self.assertEqual(safe_version("1.2-1"), "1.2-1")


More information about the Python-checkins mailing list