From e84d567081862e614bdfc56cd7486586fa44b11a Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Mon, 19 Dec 2022 19:31:15 +0900 Subject: [PATCH] extend pkg install check (#76) * extend pkg install check * add imports * fix package * pip uninstall all * chlog --- .github/workflows/check-package.yml | 121 ++++++++++++++++++----- .github/workflows/ci-testing.yml | 1 + .github/workflows/ci-use-checks.yml | 2 +- CHANGELOG.md | 9 ++ requirements/base.txt | 3 +- src/lightning_utilities/__init__.py | 13 +++ src/lightning_utilities/core/__init__.py | 12 +++ 7 files changed, 135 insertions(+), 26 deletions(-) diff --git a/.github/workflows/check-package.yml b/.github/workflows/check-package.yml index aa07d920..dbcb5166 100644 --- a/.github/workflows/check-package.yml +++ b/.github/workflows/check-package.yml @@ -3,15 +3,28 @@ name: Check package flow on: workflow_call: inputs: + artifact-name: + description: 'Unique name for collecting artifacts' + required: true + type: string import-name: description: 'Import name to test with after installation' required: true type: string - pypi-name: - description: 'PyPI name to install the package with' - required: true + install-flags: + description: 'Additional pip install flags' + required: false type: string - strategy-matrix: + default: "" + build-matrix: + description: 'what building configs in json format' + required: false + type: string + default: | + { + "os": ["ubuntu-latest"], + } + testing-matrix: description: 'what test configs to run in json format' required: false type: string @@ -23,26 +36,48 @@ on: "python-version": ["3.7", "3.9"] } +defaults: + run: + shell: bash + jobs: - pkg-check: + + init-store: + runs-on: ubuntu-20.04 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + - run: | + mkdir dist && touch dist/.placeholder + - name: Upload 📤 + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: dist + + pkg-build: + needs: init-store runs-on: ${{ matrix.os }} strategy: + max-parallel: 1 # run sequential to prevent download/upload collisions fail-fast: false - matrix: ${{ fromJSON(inputs.strategy-matrix) }} + matrix: ${{ fromJSON(inputs.build-matrix) }} steps: - - name: Checkout + - name: Checkout 🛎️ uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} + - name: Download 📥 previous packages + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: pypi + - name: Set up Python 🐍 uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: 3.8 - name: Check local package - run: | - # check package - python setup.py check --metadata --strict + run: python setup.py check --metadata --strict - name: Create package run: | @@ -52,20 +87,58 @@ jobs: - name: Check build package run: | - pip install -q -U twine + pip install -q -U twine>=4.0.1 # check package description twine check dist/* - - name: Install and uninstall package (archive) - working-directory: dist + - name: prepare for upload + run: cp dist/* pypi/ + - name: Upload 📤 to the share store + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: pypi + + pkg-check: + needs: pkg-build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(inputs.testing-matrix) }} + + steps: + - name: Download 📥 all packages + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: pypi + - name: show packages + working-directory: pypi + run: ls -lh + - name: Set up Python 🐍 ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install package (wheel) + working-directory: pypi + run: | + # TODO: reset env / conside add as conda + pip install *.whl ${{ inputs.install-flags }} + python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')" + pip list + + - name: Uninstall all run: | - pip install *.tar.gz - python -c "import ${{ inputs.import-name }}; print(${{ inputs.import-name }}.__version__)" - pip uninstall -y ${{ inputs.pypi-name }} + pip freeze > _reqs.txt + pip uninstall -y -r _reqs.txt - - name: Install and uninstall package (wheel) - working-directory: dist + - name: Install package (archive) + working-directory: pypi run: | - pip install *.whl - python -c "import ${{ inputs.import-name }}; print(${{ inputs.import-name }}.__version__)" - pip uninstall -y ${{ inputs.pypi-name }} + # TODO: reset env / conside add as conda + pip install *.tar.gz ${{ inputs.install-flags }} + python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')" + pip list + + # TODO: add run doctests diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 4bf27b80..baac4a44 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -27,6 +27,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Set oldest dependencies + # todo: this is strange to use itself :/ if: matrix.requires == 'oldest' run: | pip install -e '.[cli]' diff --git a/.github/workflows/ci-use-checks.yml b/.github/workflows/ci-use-checks.yml index b9fa5327..7aeb2adf 100644 --- a/.github/workflows/ci-use-checks.yml +++ b/.github/workflows/ci-use-checks.yml @@ -22,8 +22,8 @@ jobs: check-package: uses: ./.github/workflows/check-package.yml with: + artifact-name: dist-packages-${{ github.sha }} import-name: "lightning_utilities" - pypi-name: "lightning-utilities" # todo: seems it does not have effect if you set it wrong check-docs: uses: ./.github/workflows/check-docs.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index e96067cf..f497abf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `requires` wrapper ([#70](https://github.com/Lightning-AI/utilities/pull/70)) +- Added several functions/class common to package's `__all__` ([#76](https://github.com/Lightning-AI/utilities/pull/76)) + + ### Changed +- CI: extended package install check ([#76](https://github.com/Lightning-AI/utilities/pull/76)) + + ### Removed ### Deprecated @@ -26,6 +32,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed requirements parsing ([#69](https://github.com/Lightning-AI/utilities/pull/69)) +- Fixed missing `packaging` dependency ([#76](https://github.com/Lightning-AI/utilities/pull/76)) + + ## [0.4.2] - 2022-10-31 ### Fixed diff --git a/requirements/base.txt b/requirements/base.txt index 94a71356..0129c7f9 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1 +1,2 @@ -importlib-metadata>=4.0.0; python_version < '3.8' +importlib-metadata >=4.0.0; python_version < '3.8' +packaging >=20.0 diff --git a/src/lightning_utilities/__init__.py b/src/lightning_utilities/__init__.py index 971a499a..3b4ced87 100644 --- a/src/lightning_utilities/__init__.py +++ b/src/lightning_utilities/__init__.py @@ -3,6 +3,19 @@ import os from lightning_utilities.__about__ import * # noqa: F401, F403 +from lightning_utilities.core.enums import StrEnum +from lightning_utilities.core.imports import compare_version, module_available +from lightning_utilities.core.overrides import is_overridden +from lightning_utilities.core.rank_zero import WarningCache _PACKAGE_ROOT = os.path.dirname(__file__) _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT) + + +__all__ = [ + "StrEnum", + "module_available", + "compare_version", + "is_overridden", + "WarningCache", +] diff --git a/src/lightning_utilities/core/__init__.py b/src/lightning_utilities/core/__init__.py index e69de29b..bab4b995 100644 --- a/src/lightning_utilities/core/__init__.py +++ b/src/lightning_utilities/core/__init__.py @@ -0,0 +1,12 @@ +from lightning_utilities.core.enums import StrEnum +from lightning_utilities.core.imports import compare_version, module_available +from lightning_utilities.core.overrides import is_overridden +from lightning_utilities.core.rank_zero import WarningCache + +__all__ = [ + "StrEnum", + "module_available", + "compare_version", + "is_overridden", + "WarningCache", +]