diff options
-rw-r--r-- | pkg_resources.py | 22 | ||||
-rwxr-xr-x | pkg_resources.txt | 13 | ||||
-rw-r--r-- | setuptools/tests/test_resources.py | 2 |
3 files changed, 25 insertions, 12 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index 5dba07fb..d31a65fa 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -61,7 +61,7 @@ __all__ = [ # 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 get_default_cache(): 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 @@ def safe_extra(extra): 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 @@ def yield_lines(strs): 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 @@ class Distribution(object): 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 ) diff --git a/pkg_resources.txt b/pkg_resources.txt index b8705d47..851a3cf7 100755 --- a/pkg_resources.txt +++ b/pkg_resources.txt @@ -1445,6 +1445,12 @@ Parsing Utilities 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 @@ File/Path Utilities 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 diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py index 8ce1117a..b4dbfdbd 100644 --- a/setuptools/tests/test_resources.py +++ b/setuptools/tests/test_resources.py @@ -406,7 +406,7 @@ class ParseTests(TestCase): 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") |