diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..beb46b80 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,128 @@ +## 1.3.0 (2018.05.09) + +ENHANCEMENTS: +* Added support for OpenBSD, FreeBSD, and NetBSD [[#207](https://github.com/nir0s/distro/issues/207)] + +TESTS: +* Add test for Kali Linux Rolling [[#214](https://github.com/nir0s/distro/issues/214)] + +DOCS: +* Update docs with regards to #207 [[#209](https://github.com/nir0s/distro/issues/209)] +* Add Ansible reference implementation and fix arch-linux link [[#213](https://github.com/nir0s/distro/issues/213)] +* Add facter reference implementation [[#213](https://github.com/nir0s/distro/issues/213)] + +## 1.2.0 (2017.12.24) + +BACKWARD COMPATIBILITY: +* Don't raise ImportError on non-linux platforms [[#202](https://github.com/nir0s/distro/issues/202)] + +ENHANCEMENTS: +* Lazily load the LinuxDistribution data [[#201](https://github.com/nir0s/distro/issues/201)] + +BUG FIXES: +* Stdout of shell should be decoded with sys.getfilesystemencoding() [[#203](https://github.com/nir0s/distro/issues/203)] + +TESTS: +* Explicitly set Python versions on Travis for flake [[#204](https://github.com/nir0s/distro/issues/204)] + + +## 1.1.0 (2017.11.28) + +BACKWARD COMPATIBILITY: +* Drop python3.3 support [[#199](https://github.com/nir0s/distro/issues/199)] +* Remove Official Python26 support [[#195](https://github.com/nir0s/distro/issues/195)] + +TESTS: +* Add MandrivaLinux test case [[#181](https://github.com/nir0s/distro/issues/181)] +* Add test cases for CloudLinux 5, 6, and 7 [[#180](https://github.com/nir0s/distro/issues/180)] + +RELEASE: +* Modify MANIFEST to include resources for tests and docs in source tarballs [[97c91a1](97c91a1)] + +## 1.0.4 (2017.04.01) + +BUG FIXES: +* Guess common *-release files if /etc not readable [[#175](https://github.com/nir0s/distro/issues/175)] + +## 1.0.3 (2017.03.19) + +ENHANCEMENTS: +* Show keys for empty values when running distro from the CLI [[#160](https://github.com/nir0s/distro/issues/160)] +* Add manual mapping for `redhatenterpriseserver` (previously only redhatenterpriseworkstation was mapped) [[#148](https://github.com/nir0s/distro/issues/148)] +* Race condition in `_parse_distro_release_file` [[#163](https://github.com/nir0s/distro/issues/163)] + +TESTS: +* Add RHEL5 test case [[#165](https://github.com/nir0s/distro/issues/165)] +* Add OpenELEC test case [[#166](https://github.com/nir0s/distro/issues/166)] +* Replace nose with pytest [[#158](https://github.com/nir0s/distro/issues/158)] + +RELEASE: +* Update classifiers +* Update supported Python versions (with py36) + +## 1.0.2 (2017.01.12) + +TESTS: +* Test on py33, py36 and py3 based flake8 + +RELEASE: +* Add MANIFEST file (which also includes the LICENSE as part of Issue [[#139](https://github.com/nir0s/distro/issues/139)]) +* Default to releasing using Twine [[#121](https://github.com/nir0s/distro/issues/121)] +* Add setup.cfg file [[#145](https://github.com/nir0s/distro/issues/145)] +* Update license in setup.py + +## 1.0.1 (2016-11-03) + +ENHANCEMENTS: +* Prettify distro -j's output and add more elaborate docs [[#147](https://github.com/nir0s/distro/issues/147)] +* Decode output of `lsb_release` as utf-8 [[#144](https://github.com/nir0s/distro/issues/144)] +* Logger now uses `message %s, string` form to not-evaulate log messages if unnecessary [[#145](https://github.com/nir0s/distro/issues/145)] + +TESTS: +* Increase code-coverage [[#146](https://github.com/nir0s/distro/issues/146)] +* Fix landscape code-quality warnings [[#145](https://github.com/nir0s/distro/issues/145)] + +RELEASE: +* Add CONTRIBUTING.md + +## 1.0.0 (2016-09-25) + +BACKWARD COMPATIBILITY: +* raise exception when importing on non-supported platforms [[#129](https://github.com/nir0s/distro/issues/129)] + +ENHANCEMENTS: +* Use `bytes` invariantly [[#135](https://github.com/nir0s/distro/issues/135)] +* Some minor code adjustments plus a CLI [[#134](https://github.com/nir0s/distro/issues/134)] +* Emit stderr if `lsb_release` fails + +BUG FIXES: +* Fix some encoding related issues + +TESTS: +* Add many test cases (e.g. Raspbian 8, CoreOS, Amazon Linux, Scientific Linux, Gentoo, Manjaro) +* Completely redo the testing framework to make it easier to add tests +* Test on pypy + +RELEASE: +* Remove six as a dependency + +## 0.6.0 (2016-04-21) + +This is the first release of `distro`. +All previous work was done on `ld` and therefore unmentioned here. See the release log in GitHub if you want the entire log. + +BACKWARD COMPATIBILITY: +* No longer a package. constants.py has been removed and distro is now a single module + +ENHANCEMENTS: +* distro.info() now receives best and pretty flags +* Removed get_ prefix from get_*_release_attr functions +* Codename is now passed in distro.info() + +TESTS: +* Added Linux Mint test case +* Now testing on Python 3.4 + +DOCS: +* Documentation fixes + diff --git a/CHANGES b/CHANGES deleted file mode 100644 index 39c463b1..00000000 --- a/CHANGES +++ /dev/null @@ -1,78 +0,0 @@ -**Unreleased** - -* Added support for OpenBSD, FreeBSD, and NetBSD - -**1.2.0 (2017.12.24)** - -* Lazily load parsers to speed up import time. -* Don't raise import error on non-linux os. -* Decode stdout of shell sys.getfilesystemencoding(). -* Explicitly set Python versions for flake8 tests. - - -**1.1.0 (2017.11.28)** - -Note: This version removes official support for Python 2.6. If you need a version that is tested on Python 2.6, please use `distro<=1.0.4`. - -In addition: - -* Add tests for MandrivaLinux, CloudLinux 5,6,7 -* Modify MANIFEST to include resources for tests and docs in source tarballs (https://github.com/nir0s/distro/pull/189/files#diff-97c91a104c431d0c365565d3ac03ac13) - - -**1.0.4 (2017.04.01)** - -* Fix not being able to read `/etc/` and yet able to read release files inside it. - -**1.0.3 (2017.03.19)** - -* Add manual mapping for `redhatenterpriseserver` (previously only redhatenterpriseworkstation was mapped) -* Return empty information when failing to read a seemingly version related file due to IO or OS errors. -* When using the CLI without providing the -j flag, printout keys even if their values are empty. -* Replace nose with pytest -* Add RHEL5 test case -* Add OpenELEC test case -* Update supported Python versions (with py36) -* Update classifiers - -**1.0.2 (2017.01.12)** - -* Add MANIFEST file (which also includes the LICENSE as part of Issue #139) -* Default to releasing using Twine (as per Issue #121) -* Update license in setup.py -* Test on py33, py36 and py3 based flake8 -* Add setup.cfg file - -**1.0.1 (2016-11-03)** - -* Prettify output when running `distro -j` -* Decode output of `lsb_release` as utf-8 -* Mend code coverage -* Logger now uses `message %s, string` form to not-evaulate log messages if unnecessary -* Add landscape.io code-quality monitoring -* Add CONTRIBUTING.md - -**1.0.0 (2016-09-25)** - -* Add a CLI and a `distro` entry point. For Python 2.6, argparse will be installed -* Add many test cases (e.g. Raspbian 8, CoreOS, Amazon Linux, Scientific Linux, Gentoo, Manjaro) -* Make distro non-importable on non-compatible platforms (e.g. Windows and tested via AppVeyor) -* Completely redo the testing framework to make it easier to add tests -* Remove six as a dependency -* Emit stderr if `lsb_release` fails -* Fix some encoding related issues -* We now use `bytes` invariantly -* Test on pypy - -**0.6.0 (2016-04-21)** - -* Introduces a new name (`distro`) -* No longer a package. constants.py has been removed and distro is now a single module -* Documentation fixes -* distro.info() now receives best and pretty flags -* Added Linux Mint test case -* Removed get_ prefix from get_*_release_attr functions -* Now testing on Python 3.4 -* Codename is now passed in distro.info() - -All previous work was done on `ld` and therefore unmentioned here. See the release log in GitHub if you want the entire log. diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 00000000..922f6533 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,13 @@ +Thanks! + +* https://github.com/andy-maier +* https://github.com/SethMichaelLarson +* https://github.com/asottile +* https://github.com/MartijnBraam +* https://github.com/funkyfuture +* https://github.com/adamjstewart +* https://github.com/xavfernandez +* https://github.com/xsuchy +* https://github.com/marcoceppi +* https://github.com/tgamblin +* https://github.com/sebix diff --git a/README.md b/README.md index f810c963..8d80f04c 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,17 @@ Distro - an OS platform information API [![Latest Github Release](https://readthedocs.org/projects/distro/badge/?version=stable)](http://distro.readthedocs.io/en/latest/) [![Join the chat at https://gitter.im/nir0s/distro](https://badges.gitter.im/nir0s/distro.svg)](https://gitter.im/nir0s/distro?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -`distro` (for: Linux Distribution) provides information about the -Linux distribution it runs on, such as a reliable machine-readable ID, or +`distro` provides information about the +OS distribution it runs on, such as a reliable machine-readable ID, or version information. -It is a renewed alternative implementation for Python's -original `platform.linux_distribution` function, but it also provides much more -functionality which isn't necessarily Python bound like a command-line interface. +It is the recommended replacement for Python's original +[`platform.linux_distribution`](https://docs.python.org/3.7/library/platform.html#platform.linux_distribution) +function (which will be removed in Python 3.8). +It also provides much more functionality which isn't necessarily Python bound, +like a command-line interface. +Distro currently supports Linux and BSD based systems but [Windows and OS X support](https://github.com/nir0s/distro/issues/177) is also planned. ## Installation @@ -73,26 +76,27 @@ API, see the [latest API documentation](http://distro.readthedocs.org/en/latest/ ## Background An alternative implementation became necessary because Python 3.5 deprecated -this function, and Python 3.7 is expected to remove it altogether. +this function, and Python 3.8 will remove it altogether. Its predecessor function `platform.dist` was already deprecated since -Python 2.6 and is also expected to be removed in Python 3.7. +Python 2.6 and will also be removed in Python 3.8. Still, there are many cases in which access to that information is needed. See [Python issue 1322](https://bugs.python.org/issue1322) for more information. The `distro` package implements a robust and inclusive way of retrieving the -information about a Linux distribution based on new standards and old methods, +information about a distribution based on new standards and old methods, namely from these data sources (from high to low precedence): * The os-release file `/etc/os-release`, if present. * The output of the `lsb_release` command, if available. * The distro release file (`/etc/*(-|_)(release|version)`), if present. +* The `uname` command for BSD based distrubtions. ## Python and Distribution Support `distro` is supported and tested on Python 2.7, 3.4+ and PyPy and on -any Linux distribution that provides one or more of the data sources +any distribution that provides one or more of the data sources covered. This package is tested with test data that mimics the exact behavior of the data sources of [a number of Linux distributions](https://github.com/nir0s/distro/tree/master/tests/resources/distros). @@ -120,11 +124,13 @@ formats can be found here: * https://github.com/saltstack/salt/blob/develop/salt/grains/core.py#L1172 * https://github.com/chef/ohai/blob/master/lib/ohai/plugins/linux/platform.rb +* https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/system/distribution.py +* https://github.com/puppetlabs/facter/blob/master/lib/src/facts/linux/os_linux.cc ## Package manager distributions -* https://admin.fedoraproject.org/pkgdb/package/rpms/python-distro/ -* https://aur.archlinux.org/packages/python-distro/ +* https://src.fedoraproject.org/rpms/python-distro +* https://www.archlinux.org/packages/community/any/python-distro/ * https://launchpad.net/ubuntu/+source/python-distro * https://packages.debian.org/sid/python-distro * https://packages.gentoo.org/packages/dev-python/distro diff --git a/README.rst b/README.rst deleted file mode 100644 index 7aac2660..00000000 --- a/README.rst +++ /dev/null @@ -1,4 +0,0 @@ -Distro - an OS platform information API -======================================= - -See `Official GitHub repo `_. diff --git a/distro.py b/distro.py index aa4defc3..80a90367 100755 --- a/distro.py +++ b/distro.py @@ -17,12 +17,12 @@ information about the Linux distribution it runs on, such as a reliable machine-readable distro ID, or version information. -It is a renewed alternative implementation for Python's original +It is the recommended replacement for Python's original :py:func:`platform.linux_distribution` function, but it provides much more functionality. An alternative implementation became necessary because Python -3.5 deprecated this function, and Python 3.7 is expected to remove it -altogether. Its predecessor function :py:func:`platform.dist` was already -deprecated since Python 2.6 and is also expected to be removed in Python 3.7. +3.5 deprecated this function, and Python 3.8 will remove it altogether. +Its predecessor function :py:func:`platform.dist` was already +deprecated since Python 2.6 and will also be removed in Python 3.8. Still, there are many cases in which access to OS distribution information is needed. See `Python issue 1322 `_ for more information. diff --git a/docs/index.rst b/docs/index.rst index 72d0fe4d..0584dc68 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -54,7 +54,7 @@ namely from these data sources: * The `distro release file`_, if present. -* The uname command output, if present. +* The `uname command output`_, if present. Access to the information @@ -114,7 +114,7 @@ distribution: A user-defined instance of the :class:`distro.LinuxDistribution` class allows specifying the path names of the os-release file and distro release file and whether the lsb_release command should be used or not. That is useful for - example when the Linux distribution information from a chrooted environment + example when the distribution information from a chrooted environment is to be retrieved, or when a distro has multiple distro release files and the default algorithm uses the wrong one. @@ -387,7 +387,7 @@ and where the first line within the file has the expected format. The algorithm to sort the files alphabetically is far from perfect, but the distro release file has the least priority as a data source, and it is expected -that Linux distributions provide one of the other data sources. +that distributions provide one of the other data sources. The distro release file is expected to be encoded in UTF-8. diff --git a/setup.py b/setup.py index d39ec926..92c957a0 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ # The following version is parsed by other parts of this package. # Don't change the format of the line, or the variable name. -package_version = "1.2.0" +package_version = "1.3.0" here = os.path.abspath(os.path.dirname(__file__)) @@ -37,7 +37,8 @@ def read(*parts): license='Apache License, Version 2.0', platforms='All', description='Distro - an OS platform information API', - long_description=read('README.rst'), + long_description=read('README.md'), + long_description_content_type='text/markdown', py_modules=['distro'], entry_points={ 'console_scripts': [ diff --git a/tests/resources/distros/kali/etc/os-release b/tests/resources/distros/kali/etc/os-release new file mode 100644 index 00000000..4436a0d3 --- /dev/null +++ b/tests/resources/distros/kali/etc/os-release @@ -0,0 +1,10 @@ +PRETTY_NAME="Kali GNU/Linux Rolling" +NAME="Kali GNU/Linux" +ID=kali +VERSION="2017.1" +VERSION_ID="2017.1" +ID_LIKE=debian +ANSI_COLOR="1;31" +HOME_URL="http://www.kali.org/" +SUPPORT_URL="http://forums.kali.org/" +BUG_REPORT_URL="http://bugs.kali.org/" diff --git a/tests/test_distro.py b/tests/test_distro.py index 0bfdbd2a..f5ac2b2b 100644 --- a/tests/test_distro.py +++ b/tests/test_distro.py @@ -139,6 +139,18 @@ def test_arch_os_release(self): } self._test_outcome(desired_outcome) + def test_kali_os_release(self): + desired_outcome = { + 'id': 'kali', + 'name': 'Kali GNU/Linux', + 'pretty_name': 'Kali GNU/Linux Rolling', + 'version': '2017.1', + 'pretty_version': '2017.1', + 'best_version': '2017.1', + 'like': 'debian' + } + self._test_outcome(desired_outcome) + def test_centos7_os_release(self): desired_outcome = { 'id': 'centos', @@ -584,12 +596,12 @@ def test_unknowndistro_release(self): 'minor_version': '0' } self._test_outcome(desired_outcome) - + def test_bad_uname(self): self._setup_for_distro(os.path.join(TESTDISTROS, 'distro', 'baduname')) self.distro = distro.LinuxDistribution() - + assert self.distro.uname_attr('id') == '' assert self.distro.uname_attr('name') == '' assert self.distro.uname_attr('release') == '' @@ -1530,7 +1542,7 @@ def setup_method(self, test_method): self._old_listdir = os.listdir os.listdir = _bad_os_listdir super(TestOverallWithEtcNotReadable, self).setup_method(test_method) - + def teardown_method(self, test_method): super(TestOverallWithEtcNotReadable, self).teardown_method(test_method) if os.listdir is _bad_os_listdir: @@ -1944,11 +1956,11 @@ def _test_consistency(function, kwargs=None): ] for key in distro_release_keys: _test_consistency('distro_release_attr', {'attribute': key}) - + uname_keys = [ 'id', 'name', - 'release' + 'release' ] for key in uname_keys: _test_consistency('uname_attr', {'attribute': key})