Hi all -- for months I have resisted the urge to turn the 'util.get_platform()' function into a miniaturized version of Marc-André's platform.py or the GNU script that spits out the old familar "os-vendor-hardware" triple. Well, today I succumbed. The idea is to generate a string that does a better job of describing the current platform than sys.platform or os.name. This has (so far) two purposes in the distutils: naming the build directories where platform-specific files (.o, .so, etc.) go, and naming built distributions. IMHO the exact information to include depends on the OS: eg. for Linux, the exact kernel version isn't very relevant, whereas for IRIX the version is crucial but the hardware isn't. Typically, though, OS, OS version, and hardware are all relevant. This information is, AFAIK, always available from the 'uname()' system call, exposed in Python as 'os.uname()'. However, it typically needs a bit of massaging to become something that we all know and recognize: eg. "SunOS 5.x" is really "Solaris 2.x". So, here's my initial crack at a rewritten 'get_platform()'. Currently it only handles POSIX platforms; on Windows and Mac OS it'll just return sys.platform (as it has always done). ------------------------------------------------------------------------ def get_platform (): """Return a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by 'os.uname()'), although the exact information included depends on the OS; eg. for IRIX the architecture isn't particularly important (IRIX only runs on SGI hardware), but for Linux the kernel version isn't particularly important. Examples of returned values: linux-i586 linux-alpha (?) solaris-2.6-sun4u irix-5.3 irix64-6.2 For non-POSIX platforms, currently just returns 'sys.platform'. """ if os.name != "posix": # XXX what about the architecture? NT is Intel or Alpha, # Mac OS is M68k or PPC, etc. return sys.platform # Try to distinguish various flavours of Unix (os, host, release, version, machine) = os.uname() os = string.lower(os) if os[:5] == "linux": # At least on Linux/Intel, 'machine' is the processor -- # i386, etc. # XXX what about Alpha, SPARC, etc? return "%s-%s" % (os, machine) elif os[:5] == "sunos": if release[0] >= "5": # SunOS 5 == Solaris 2 os = "solaris" release = "%d.%s" % (int(release[0]) - 3, release[2:]) # fall through to standard os-release-machine representation elif os[:4] == "irix": # could be "irix64"! return "%s-%s" % (os, release) return "%s-%s-%s" % (os, release, machine) ------------------------------------------------------------------------ There are a heck of a lot of POSIX-ish platforms out there, and I'll be very happy if this function returns something sensible for the following: * Linux on any architecture * {Free,Net,Open}BSD on any architecture * Solaris on SPARC, Intel * IRIX * AIX * HP-UX ...plus of course Windows and Mac OS. Like the rest of the world, I'm a little unclear on just how many versions of Windows there really are. ;-) I suspect we can get away with Win32 vs. Win64, but what about NT on Alpha -- is that relevant? Are there any major Unices that I'm missing here? As long as the os-release-machine triple is sensible, it's OK to leave them out of the switch on OS name up there, but I suspect most will need some special-case tweaking like the three that I'm familar with. And yes, I'm going to go dig up MAL's platform.py and see what it does. My informal rule is that, at least for POSIX-ish platforms, we should rely solely on os.uname(). It remains to be seen how foolishly optimistic that is. ;-) Greg -- Greg Ward gward@python.net http://starship.python.net/~gward/ War is Peace; Freedom is Slavery; Ignorance is Knowledge
Just a thought related to what you are doing here; I have had some experiences where the LOCATION mattered too. For example, a certain library was in /usr/local on one of our systems, and in someone's home directory on another, even though otherwise the systems were identical. Of course, I don't know how you could "detect" the location except as a possible configuration variable. Indeed, I did just that in one make system I wrote.
-----Original Message----- From: distutils-sig-admin@python.org [mailto:distutils-sig-admin@python.org]On Behalf Of Greg Ward Sent: Saturday, September 09, 2000 5:02 PM To: distutils-sig@python.org Subject: [Distutils] Rewritten 'get_platform()'
Hi all --
for months I have resisted the urge to turn the 'util.get_platform()' function into a miniaturized version of Marc-André's platform.py or the GNU script that spits out the old familar "os-vendor-hardware" triple.
Well, today I succumbed. The idea is to generate a string that does a better job of describing the current platform than sys.platform or os.name. This has (so far) two purposes in the distutils: naming the build directories where platform-specific files (.o, .so, etc.) go, and naming built distributions.
IMHO the exact information to include depends on the OS: eg. for Linux, the exact kernel version isn't very relevant, whereas for IRIX the version is crucial but the hardware isn't. Typically, though, OS, OS version, and hardware are all relevant. This information is, AFAIK, always available from the 'uname()' system call, exposed in Python as 'os.uname()'. However, it typically needs a bit of massaging to become something that we all know and recognize: eg. "SunOS 5.x" is really "Solaris 2.x".
So, here's my initial crack at a rewritten 'get_platform()'. Currently it only handles POSIX platforms; on Windows and Mac OS it'll just return sys.platform (as it has always done).
------------------------------------------------------------------------ def get_platform (): """Return a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by 'os.uname()'), although the exact information included depends on the OS; eg. for IRIX the architecture isn't particularly important (IRIX only runs on SGI hardware), but for Linux the kernel version isn't particularly important.
Examples of returned values: linux-i586 linux-alpha (?) solaris-2.6-sun4u irix-5.3 irix64-6.2
For non-POSIX platforms, currently just returns 'sys.platform'. """ if os.name != "posix": # XXX what about the architecture? NT is Intel or Alpha, # Mac OS is M68k or PPC, etc. return sys.platform
# Try to distinguish various flavours of Unix
(os, host, release, version, machine) = os.uname() os = string.lower(os) if os[:5] == "linux": # At least on Linux/Intel, 'machine' is the processor -- # i386, etc. # XXX what about Alpha, SPARC, etc? return "%s-%s" % (os, machine) elif os[:5] == "sunos": if release[0] >= "5": # SunOS 5 == Solaris 2 os = "solaris" release = "%d.%s" % (int(release[0]) - 3, release[2:]) # fall through to standard os-release-machine representation elif os[:4] == "irix": # could be "irix64"! return "%s-%s" % (os, release)
return "%s-%s-%s" % (os, release, machine) ------------------------------------------------------------------------
There are a heck of a lot of POSIX-ish platforms out there, and I'll be very happy if this function returns something sensible for the following: * Linux on any architecture * {Free,Net,Open}BSD on any architecture * Solaris on SPARC, Intel * IRIX * AIX * HP-UX
...plus of course Windows and Mac OS. Like the rest of the world, I'm a little unclear on just how many versions of Windows there really are. ;-) I suspect we can get away with Win32 vs. Win64, but what about NT on Alpha -- is that relevant? Are there any major Unices that I'm missing here? As long as the os-release-machine triple is sensible, it's OK to leave them out of the switch on OS name up there, but I suspect most will need some special-case tweaking like the three that I'm familar with.
And yes, I'm going to go dig up MAL's platform.py and see what it does. My informal rule is that, at least for POSIX-ish platforms, we should rely solely on os.uname(). It remains to be seen how foolishly optimistic that is. ;-)
Greg -- Greg Ward gward@python.net http://starship.python.net/~gward/ War is Peace; Freedom is Slavery; Ignorance is Knowledge
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://www.python.org/mailman/listinfo/distutils-sig
On 10 September 2000, Paul F. Dubois said:
Just a thought related to what you are doing here; I have had some experiences where the LOCATION mattered too. For example, a certain library was in /usr/local on one of our systems, and in someone's home directory on another, even though otherwise the systems were identical. Of course, I don't know how you could "detect" the location except as a possible configuration variable. Indeed, I did just that in one make system I wrote.
Umm, I'm not talking about auto-configuration -- I'm talking about generating a reasonable "platform ID" string on a variety of Unices. Requirements: * should establish enough binary compatibility for most situations (ie. the OS name, usually the OS release, and quite often the hardware architecture) * for a given OS, should be codable in a few lines of Python based entirely on information available from Python's os and sys modules (eg. os.uname()) In short, I'm looking for something more informative than sys.platform ("linux2" doesn't cut it), but less expensive than what MAL's platform.py computes. Regarding finding required libraries for auto-configuration (since you brought it up), I mostly agree with Bastian. I would add to that: take a stab at searching the prefix directory; if someone installs everything to prefix=/opt/funky/path, then you might just find that key library in /opt/funky/path/lib. Greg -- Greg Ward gward@python.net http://starship.python.net/~gward/
participants (3)
-
Bastian Kleineidam
-
Greg Ward
-
Paul F. Dubois