From 84c2ce755c2c5325330e115a0d46f13ef15cfd2e Mon Sep 17 00:00:00 2001 From: Felix Dangel <48687646+f-dangel@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:47:33 -0400 Subject: [PATCH] [REF] Deprecate `pkg_resources`, use `importlib` & `packaging` (#121) * [REF] Switch version detection from `pkg_resources` to `importlib,packaging` * [REQ] Add `packaging` as dependency * [CI] Install `packaging` before installing package * [CI] Try installing with `python -m pip` * [FIX] Try CI with python 3.9 * [FIX] Try installing `packaging` with `apt-get` * [FIX] Call `pip show` * [FIX] Try with `python3.10` * [FIX] String around python version * [FIX] Try installing `wheel` * [FIX] Explicitly install `wheel` Magically seems to fix the import error of `packaging` * [FIX] Also explicitly install `packaging` * [FIX] Install `wheels` and `packaging` in RTD * [FIX] Different install command * [FIX] Another attempt * [FIX] Spelling error * [FIX] Try again * [FIX] Try with `post_build` option * [FIX] Use `post_install` * [FIX] Install `setuptools<=69` * [FIX] Pin `setuptools` --- .github/workflows/lint-black.yaml | 2 +- .github/workflows/lint-darglint.yaml | 2 +- .github/workflows/lint-flake8.yaml | 2 +- .github/workflows/lint-isort.yaml | 2 +- .github/workflows/lint-pydocstyle.yaml | 2 +- .github/workflows/python-publish.yml | 2 +- .github/workflows/test.yaml | 2 +- .readthedocs.yaml | 3 +++ setup.cfg | 1 - setup.py | 11 ++++++----- 10 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/lint-black.yaml b/.github/workflows/lint-black.yaml index 845479e9..35a03624 100644 --- a/.github/workflows/lint-black.yaml +++ b/.github/workflows/lint-black.yaml @@ -20,7 +20,7 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel packaging make install-lint - name: Run black run: | diff --git a/.github/workflows/lint-darglint.yaml b/.github/workflows/lint-darglint.yaml index 7465bf05..d40b256c 100644 --- a/.github/workflows/lint-darglint.yaml +++ b/.github/workflows/lint-darglint.yaml @@ -20,7 +20,7 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel packaging make install-lint - name: Run darglint run: | diff --git a/.github/workflows/lint-flake8.yaml b/.github/workflows/lint-flake8.yaml index c9fe10a6..c0f2bfde 100644 --- a/.github/workflows/lint-flake8.yaml +++ b/.github/workflows/lint-flake8.yaml @@ -19,7 +19,7 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel packaging make install-lint - name: Run flake8 run: | diff --git a/.github/workflows/lint-isort.yaml b/.github/workflows/lint-isort.yaml index cdde1386..543a374c 100644 --- a/.github/workflows/lint-isort.yaml +++ b/.github/workflows/lint-isort.yaml @@ -20,7 +20,7 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel packaging make install-lint - name: Run isort run: | diff --git a/.github/workflows/lint-pydocstyle.yaml b/.github/workflows/lint-pydocstyle.yaml index 5cd4baa2..f18e8753 100644 --- a/.github/workflows/lint-pydocstyle.yaml +++ b/.github/workflows/lint-pydocstyle.yaml @@ -21,7 +21,7 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel packaging make install-lint - name: Run pydocstyle run: | diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 0b1c9739..5389d3cf 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -20,7 +20,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + python -m pip install setuptools wheel twine packaging - name: Build and publish env: TWINE_USERNAME: __token__ diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5dc6c116..335126b7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -25,7 +25,7 @@ jobs: python-version: "${{ matrix.python-version }}" - name: Install Dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel packaging make install-test - name: Run test if: contains('refs/heads/master refs/heads/development', github.ref) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 3d33c3ec..6436f79b 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -10,6 +10,9 @@ build: os: ubuntu-22.04 tools: python: "3.8" + jobs: + post_install: + - pip install --upgrade pip packaging wheel setuptools==69.5.1 python: install: diff --git a/setup.cfg b/setup.cfg index 75924ff2..3527794b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -75,7 +75,6 @@ lint = # Dependencies needed to build/view the documentation (semicolon/line-separated) docs = - setuptools==69.5.1 # RTD fails with setuptools>=70, see https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/15863 transformers datasets matplotlib diff --git a/setup.py b/setup.py index 18aba9ef..5007a5ba 100644 --- a/setup.py +++ b/setup.py @@ -4,14 +4,15 @@ """ import sys +from importlib.metadata import version -from pkg_resources import VersionConflict, require +from packaging.version import Version from setuptools import setup -try: - require("setuptools>=38.3") -except VersionConflict: - print("Error: version of setuptools is too old (<38.3)!") +setuptools_version = Version(version("setuptools")) + +if setuptools_version < Version("38.3"): + print(f"Error: version of setuptools is too old (<38.3). Got {setuptools_version}.") sys.exit(1)