Skip to content

Instantly share code, notes, and snippets.

@sunsongxp
Forked from natefoo/00README.md
Created October 21, 2018 16:56
Show Gist options
  • Save sunsongxp/fa099e129d4ee8e00f7a13262a9b1874 to your computer and use it in GitHub Desktop.
Save sunsongxp/fa099e129d4ee8e00f7a13262a9b1874 to your computer and use it in GitHub Desktop.
Linux Distribution Detection

Distribution Detection

I am working on adding support for building and distributing (via PyPI) Python Wheels with C Extensions to the Python wheel and pip packages. The discussion on Distutils-SIG continues, but I believe it is fairly certain that some effort to correctly identify Linux distributions will need to be made. I've begun efforts to add this support to wheel.

How you can help

If you have a Linux distribution or version of a listed distribution not in this gist, I could use the following:

  • The contents of /etc/os-release, if it exists
  • Whether or not the lsb_release program is installed, and whether it's part of a "default" install
  • The output of lsb_release -a if installed
  • The contents of /etc/lsb-release, if it exists
  • The contents of any other /etc/*-release files
  • Any other reliable way to determine the flavor and version of your Linux distribution, especially if none of the above exist

And finally, you can test the platform detection on your platform by downloading and installing (e.g. in a virtualenv) my changes to wheel and running:

% python -c 'import wheel.pep425tags; print wheel.pep425tags.get_platforms()'

e.g.:

% pip install -e 'hg+https://bitbucket.org/natefoo/wheel#egg=wheel'
% python -c 'import wheel.pep425tags; print wheel.pep425tags.get_platforms()'
['linux_x86_64_ubuntu_14_04', 'linux_x86_64', 'any']

If lsb_release is optional on your system and especially if /etc/os-release does not exist, it'd be even more helpful to run the above prior to installing lsb_release, and again afterward.

Debian

Debian stretch

/etc/os-release

Doesn't include a version or version_id, so this results in reading the distro name from /etc/os-release but version detection falls through to the "legacy" method of reading from /etc/debian_version.

PRETTY_NAME="Debian GNU/Linux stretch/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support/"
BUG_REPORT_URL="https://bugs.debian.org/"

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux testing (stretch)
Release:	testing
Codename:	stretch

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

stretch/sid

get_platforms()

['linux_x86_64_debian_stretch_sid', 'linux_x86_64', 'any']

Debian 8 (jessie)

/etc/os-release

PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="https://bugs.debian.org/"

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux 8.1 (jessie)
Release:	8.1
Codename:	jessie

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

8.1

get_platforms()

['linux_x86_64_debian_8', 'linux_x86_64', 'any']

Debian 7 (wheezy)

/etc/os-release

PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux 7.8 (wheezy)
Release:	7.8
Codename:	wheezy

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

7.8

get_platforms()

['linux_x86_64_debian_7', 'linux_x86_64', 'any']

Debian 6 (squeeze)

/etc/os-release

Does not exist

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux 6.0.10 (squeeze)
Release:	6.0.10
Codename:	squeeze

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

6.0.10

get_platforms()

With lsb_release installed:

['linux_x86_64_debian_6_0_10', 'linux_x86_64_debian_6', 'linux_x86_64', 'any']

Without:

['linux_x86_64_debian_6_0_10', 'linux_x86_64_debian_6', 'linux_x86_64', 'any']

Ubuntu

Ubuntu 14.04 (trusty)

/etc/os-release

NAME="Ubuntu"
VERSION="14.04, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

lsb-release -a

lsb_release is installed as part of a base system, via the lsb-release package.

Distributor ID:	Ubuntu
Description:	Ubuntu 14.04 LTS
Release:	14.04
Codename:	trusty

/etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"

Distro-specific files

/etc/debian_version:

jessie/sid

get_platforms()

['linux_x86_64_ubuntu_14_04', 'linux_x86_64', 'any']

Ubuntu 12.04 (precise)

/etc/os-release

Does not exist

lsb-release -a

lsb_release is installed as part of a base system, via the lsb-release package.

Distributor ID:	Ubuntu
Description:	Ubuntu 12.04 LTS
Release:	12.04
Codename:	precise

/etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"

Distro-specific files

/etc/debian_version:

wheezy/sid

get_platforms()

['linux_x86_64_ubuntu_12_04', 'linux_x86_64', 'any']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment