Skip to content

Commit

Permalink
safe_name() now allows dots in project names, and there is a new
Browse files Browse the repository at this point in the history
``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.  :(

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041994
  • Loading branch information
PJ Eby committed Jan 10, 2006
1 parent f95da2a commit 51d68aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
22 changes: 11 additions & 11 deletions pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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):
Expand All @@ -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('-','_')



Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1846,7 +1846,7 @@ def activate(self,path=None):
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
)

Expand Down
13 changes: 13 additions & 0 deletions pkg_resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def testSafeName(self):
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")
Expand Down

0 comments on commit 51d68aa

Please sign in to comment.