diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index afe339b9..7f8dd008 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,7 +13,9 @@ jobs: - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 + with: + python-version: 3.x - name: Install tox run: python -m pip install tox @@ -39,7 +41,7 @@ jobs: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} @@ -64,7 +66,7 @@ jobs: - uses: codecov/codecov-action@v3 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: 3.x diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 002905fc..ffbfe8dc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,7 +1,7 @@ name: "Deploy to PyPI" on: workflow_dispatch: - inputs: + inputs: tag: description: "Git tag to deploy to PyPI" required: true @@ -15,13 +15,13 @@ jobs: - uses: actions/checkout@v3 with: ref: ${{ github.event.inputs.tag }} - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: 3.x - shell: bash run: | python -m pip install --disable-pip-version-check -U pip - python -m pip install -U setuptools wheel twine - python setup.py sdist bdist_wheel + python -m pip install -U build twine + python -m build python -m twine check dist/* python -m twine upload --username=__token__ --password=${{ secrets.PYPI_TOKEN }} dist/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1a4b3294..9a2251ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,5 +19,4 @@ repos: args: ["--strict"] additional_dependencies: [ "pytest==6.2.5", - "types-setuptools==57.4.2", ] diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d854ae..75588d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## 1.8.0 (2022.10.10) + +BACKWARD COMPATIBILITY: +* Replace `setup.py` with `build` [[#342](https://github.com/python-distro/distro/pull/342)] + +ENHANCEMENTS: +* Lowered `LinuxDistribution._distro_release_info` method complexity [[#327](https://github.com/python-distro/distro/pull/327)] +* Added official support for Buildroot distribution [[#329](https://github.com/python-distro/distro/pull/329)] +* Added official support for Guix distribution [[#330](https://github.com/python-distro/distro/pull/330)] +* Added support for `/etc/debian_version` [[#333](https://github.com/python-distro/distro/pull/333)] & [[#349](https://github.com/python-distro/distro/pull/349)] +* Fixed a typography in CONTRIBUTING.md [[#340](https://github.com/python-distro/distro/pull/340)] +* Improved README.md "Usage" code block [[#343](https://github.com/python-distro/distro/pull/343)] + +RELEASE: +* Bumped black to v22.3.0 in pre-commit.ci configuration [[#331](https://github.com/python-distro/distro/pull/331)] +* Enabled GitHub Dependabot to keep GitHub Actions up to date [[#335](https://github.com/python-distro/distro/pull/335)] + ## 1.7.0 (2022.02.15) BACKWARD COMPATIBILITY: @@ -130,7 +147,7 @@ RELEASE: ## 1.0.4 (2017.04.01) BUG FIXES: -* Guess common *-release files if /etc not readable [[#175](https://github.com/python-distro/distro/issues/175)] +* Guess common \*-release files if /etc not readable [[#175](https://github.com/python-distro/distro/issues/175)] ## 1.0.3 (2017.03.19) @@ -213,4 +230,3 @@ TESTS: DOCS: * Documentation fixes - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4948ef24..262469ad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,6 +49,6 @@ def test_centos5_dist_release(self): self._test_outcome(desired_outcome, 'centos', '5') ``` -Where the name of the method is not indicative of the lookup folder but rather tha two last arguments in `_test_outcome`. +Where the name of the method is not indicative of the lookup folder but rather the two last arguments in `_test_outcome`. -A test case is mandatory under `TestOverall` for a PR to be complete. \ No newline at end of file +A test case is mandatory under `TestOverall` for a PR to be complete. diff --git a/Makefile b/Makefile index 585ca2ef..ad3ec566 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ clean: .PHONY: build build: - python setup.py sdist bdist_wheel + python -m build .PHONY: publish publish: @@ -72,12 +72,12 @@ dev: instdev test .PHONY: instdev instdev: pip install -r dev-requirements.txt - python setup.py develop + pip install -e . @echo "$@ done." .PHONY: install install: - python setup.py install + pip install . @echo "$@ done." .PHONY: clobber diff --git a/README.md b/README.md index e22ed1ee..de6f3c79 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,12 @@ $ distro -j $ python >>> import distro ->>> distro.linux_distribution(full_distribution_name=False) -('centos', '7.1.1503', 'Core') +>>> distro.name(pretty=True) +'CentOS Linux 8' +>>> distro.id() +'centos' +>>> distro.version(best=True) +'8.4.2105' ``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..fed528d4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py deleted file mode 100644 index 4ab6be28..00000000 --- a/setup.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2015-2020 Nir Cohen -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from setuptools import setup - -setup() diff --git a/src/distro/distro.py b/src/distro/distro.py old mode 100755 new mode 100644 index 1e7a3834..2cea1635 --- a/src/distro/distro.py +++ b/src/distro/distro.py @@ -56,7 +56,7 @@ # Python 3.7 TypedDict = dict -__version__ = "1.7.0" +__version__ = "1.8.0" class VersionDict(TypedDict): @@ -903,16 +903,7 @@ def version(self, pretty: bool = False, best: bool = False) -> str: versions.insert(0, self.oslevel_info()) elif self.id() == "debian" or "debian" in self.like().split(): # On Debian-like, add debian_version file content to candidates list. - try: - with open( - self.__resolve_chroot_symlink_as_needed( - os.path.join(self.etc_dir, "debian_version") - ), - encoding="ascii", - ) as fp: - versions.append(fp.readline().rstrip()) - except FileNotFoundError: - pass + versions.append(self._debian_version) version = "" if best: # This algorithm uses the last version in priority order that has @@ -1280,6 +1271,19 @@ def _oslevel_info(self) -> str: return "" return self._to_str(stdout).strip() + @cached_property + def _debian_version(self) -> str: + try: + with open( + self.__resolve_chroot_symlink_as_needed( + os.path.join(self.etc_dir, "debian_version") + ), + encoding="ascii", + ) as fp: + versions.append(fp.readline().rstrip()) + except FileNotFoundError: + pass + @staticmethod def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]: if not lines: diff --git a/tests/test_distro.py b/tests/test_distro.py index 2e6b60e4..4b49cd45 100644 --- a/tests/test_distro.py +++ b/tests/test_distro.py @@ -2297,6 +2297,6 @@ def test_repr(self) -> None: repr_str = repr(distro._distro) assert "LinuxDistribution" in repr_str for attr in MODULE_DISTRO.__dict__.keys(): - if attr in ("root_dir", "etc_dir", "usr_lib_dir"): + if attr in ("root_dir", "etc_dir", "usr_lib_dir", "_debian_version"): continue assert f"{attr}=" in repr_str diff --git a/tox.ini b/tox.ini index efa6ae6d..cc9dfc51 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ [tox] minversion = 1.9 envlist = lint, py{36,37,38,39,310,py3} +isolated_build = true skip_missing_interpreters = true [testenv]