summaryrefslogtreecommitdiff
path: root/pkg_resources.py
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2005-07-21 01:11:31 +0000
committerPJ Eby <distutils-sig@python.org>2005-07-21 01:11:31 +0000
commit92cd79e46cb454878df36258c3731d0cf771ab55 (patch)
tree764331653c0c99588a7bd6d178ba256c4891c9a4 /pkg_resources.py
parenta462bb3f8cfdf798b62e7e4b5f06cbe56b2cedfd (diff)
downloadpython-setuptools-git-92cd79e46cb454878df36258c3731d0cf771ab55.tar.gz
Added support for handling MacOS platform information in ``.egg``
filenames, based on a contribution by Kevin Dangoor. (NOTE: this may make eggs compiled for OS X with older versions of setuptools unusable! If you have eggs whose file/directory names end with ``-darwin-*.egg``, you will probably need to rename them to ``-macosx-*.egg``, substituting your current Mac OS version for the darwin kernel version in the version number. Or, you can just delete and reinstall the problematic eggs.) --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041141
Diffstat (limited to 'pkg_resources.py')
-rw-r--r--pkg_resources.py81
1 files changed, 61 insertions, 20 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index 6c5f5ef1..509465ea 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -80,15 +80,47 @@ def get_provider(moduleName):
+def _macosx_vers(_cache=[]):
+ if not _cache:
+ info = os.popen('/usr/bin/sw_vers').read().splitlines()
+ for line in info:
+ key, value = line.split(None, 1)
+ if key == 'ProductVersion:':
+ _cache.append(value.strip().split("."))
+ break
+ else:
+ raise ValueError, "What?!"
+ return _cache[0]
+
+
def get_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``, but it
needs some hacks for Linux and Mac OS X.
"""
+ if sys.platform == "darwin":
+ try:
+ version = _macosx_vers()
+ machine = os.uname()[4].replace(" ", "_")
+ return "macosx-%d.%d.%d-%s" % (int(version[0]), int(version[1]),
+ int(version[2]), machine)
+ except ValueError:
+ # if someone is running a non-Mac darwin system, this will fall
+ # through to the default implementation
+ pass
+
from distutils.util import get_platform
return get_platform()
+macosVersionString = re.compile(r"macosx-(\d+)\.(\d+)\.(\d+)-(.*)")
+# XXX darwinVersionString = re.compile(r"darwin-(\d+)\.(\d+)\.(\d+)-(.*)")
+
+
+
+
+
+
def compatible_platforms(provided,required):
"""Can code for the `provided` platform run on the `required` platform?
@@ -99,9 +131,37 @@ def compatible_platforms(provided,required):
if provided is None or required is None or provided==required:
return True # easy case
- # XXX all the tricky cases go here
+ # Mac OS X special cases
+ reqMac = macosVersionString.match(required)
+ if reqMac:
+ provMac = macosVersionString.match(provided)
+
+ # is this a Mac package?
+ if not provMac:
+ # XXX backward compatibility should go here!
+ return False
+
+ # are they the same major version and machine type?
+ if provMac.group(1) != reqMac.group(1) or \
+ provMac.group(4) != reqMac.group(4):
+ return False
+
+ # is the required OS major update >= the provided one?
+ if int(provMac.group(2)) > int(reqMac.group(2)):
+ return False
+
+ return True
+
+ # XXX Linux and other platforms' special cases should go here
return False
+
+
+
+
+
+
+
def run_script(dist_spec, script_name):
"""Locate distribution `dist_spec` and run its `script_name` script"""
ns = sys._getframe(1).f_globals
@@ -113,14 +173,6 @@ def run_script(dist_spec, script_name):
run_main = run_script # backward compatibility
-
-
-
-
-
-
-
-
class IMetadataProvider:
def has_metadata(name):
@@ -151,17 +203,6 @@ class IMetadataProvider:
-
-
-
-
-
-
-
-
-
-
-
class IResourceProvider(IMetadataProvider):
"""An object that provides access to package resources"""