Skip to content

Commit

Permalink
ci: validate installing with extras & rename private req. (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda authored Oct 16, 2023
1 parent 57da130 commit f940b93
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 27 deletions.
32 changes: 26 additions & 6 deletions .github/actions/pkg-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: "additional pip install flags"
required: false
default: "-f https://download.pytorch.org/whl/cpu/torch_stable.html"
import-extras:
description: "additional import statement, need to be full python code"
required: false
default: ""

runs:
using: "composite"
Expand All @@ -33,18 +37,27 @@ runs:
ls -lh
echo "PKG_WHEEL=$(ls *.whl | head -n1)" >> $GITHUB_ENV
echo "PKG_SOURCE=$(ls *.tar.gz | head -n1)" >> $GITHUB_ENV
pip list
shell: bash

- name: Install package (wheel)
working-directory: pypi/
run: |
# TODO: reset env / consider add as conda
pip install "${{ env.PKG_WHEEL }}${{ inputs.pkg-extras }}" ${{ inputs.pip-flags }}
python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')"
set -ex
pip install '${{ env.PKG_WHEEL }}${{ inputs.pkg-extras }}' \
--force-reinstall ${{ inputs.pip-flags }}
pip list
shell: bash

- name: package check
run: |
set -ex
python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')"
python -c '${{ inputs.import-extras }}'
shell: bash

- name: Uninstall all
# TODO: reset env / consider add as conda
run: |
pip freeze > _reqs.txt
pip uninstall -y -r _reqs.txt
Expand All @@ -53,8 +66,15 @@ runs:
- name: Install package (archive)
working-directory: pypi/
run: |
# TODO: reset env / consider add as conda
pip install "${{ env.PKG_SOURCE }}${{ inputs.pkg-extras }}" ${{ inputs.pip-flags }}
python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')"
set -ex
pip install '${{ env.PKG_SOURCE }}${{ inputs.pkg-extras }}' \
--force-reinstall ${{ inputs.pip-flags }}
pip list
shell: bash

- name: package check
run: |
set -ex
python -c "import ${{ inputs.import-name }} as pkg; print(f'version: {pkg.__version__}')"
python -c '${{ inputs.import-extras }}'
shell: bash
16 changes: 11 additions & 5 deletions .github/workflows/check-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ on:
description: "Unique name for collecting artifacts"
required: true
type: string
import-name:
description: "Import name to test with after installation"
required: true
type: string
install-extras:
description: "optional extras which are needed to include also []"
required: false
Expand All @@ -25,6 +21,15 @@ on:
required: false
type: string
default: "-f https://download.pytorch.org/whl/cpu/torch_stable.html"
import-name:
description: "Import name to test with after installation"
required: true
type: string
import-extras:
description: "additional import statement, need to be full python code"
type: string
required: false
default: ""
build-matrix:
description: "what building configs in json format"
required: false
Expand Down Expand Up @@ -121,9 +126,10 @@ jobs:
uses: ./.cicd/.github/actions/pkg-install
with:
artifact-name: ${{ inputs.artifact-name }}
import-name: ${{ inputs.import-name }}
pkg-extras: ${{ inputs.install-extras }}
pip-flags: ${{ inputs.install-flags }}
import-name: ${{ inputs.import-name }}
import-extras: ${{ inputs.import-extras }}

# TODO: add run doctests

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Install dependencies
timeout-minutes: 20
run: |
pip install -e . -U -r requirements/dev-tests.txt \
pip install -e . -U -r requirements/_tests.txt \
-f https://download.pytorch.org/whl/cpu/torch_stable.html
pip --version
pip list
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci-use-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ jobs:
actions-ref: ${{ github.sha }} # use local version
artifact-name: dist-packages-${{ github.sha }}
import-name: "lightning_utilities"
install-extras: "[anything]"
install-extras: "[cli]"
# todo: when we have a module with depence on extra, replace it
# tried to import `lightning_utilities.cli.__main__` but told me it does not exits
import-extras: "import fire"
testing-matrix: |
{
"os": ["ubuntu-22.04", "macos-12", "windows-2022"],
Expand All @@ -63,7 +66,7 @@ jobs:
check-docs:
uses: ./.github/workflows/check-docs.yml
with:
requirements-file: "requirements/dev-docs.txt"
requirements-file: "requirements/_docs.txt"
install-tex: true

check-md-links-default:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
timeout-minutes: 20
run: |
pip --version
pip install -e . -U -q -r requirements/dev-docs.txt -f ${TORCH_URL}
pip install -e . -U -q -r requirements/_docs.txt -f ${TORCH_URL}
pip list
shell: bash

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- CI: added `install-extras` in install check allowing deduplication eventual cyrcular install dependency ([#184](https://github.com/Lightning-AI/utilities/pull/184))
- CI: added `install-extras` in install check allowing deduplication eventual cyrcular install dependency (
[#184](https://github.com/Lightning-AI/utilities/pull/184),
[#185](https://github.com/Lightning-AI/utilities/pull/185))


### Changed
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export SLURM_LOCALID=0
export SPHINX_MOCK_REQUIREMENTS=0

test:
pip install -q -r requirements/cli.txt
pip install -q -r requirements/dev-tests.txt
pip install -q -r requirements/cli.txt -r requirements/_tests.txt

# use this to run tests
rm -rf _ckpt_*
Expand All @@ -19,7 +18,7 @@ test:
# python -m coverage run --source src/lightning_utilities -m pytest --flake8 --durations=0 -v -k

docs: clean
pip install -e . -q -r requirements/dev-docs.txt
pip install -e . -q -r requirements/_docs.txt
cd docs && $(MAKE) html

clean:
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 17 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ def _load_py_module(fname: str, pkg: str = "lightning_utilities"):
with open(os.path.join(_PATH_REQUIRE, "base.txt")) as fp:
requirements = list(map(str, parse_requirements(fp.readlines())))


# make extras as automated loading
requirements_extra = {}
for fpath in glob.glob(os.path.join(_PATH_REQUIRE, "*.txt")):
if os.path.basename(fpath) in ("base.txt", "dev-docs.txt", "dev-tests.txt", "gha-schema.txt"):
continue
name, _ = os.path.splitext(os.path.basename(fpath))
with open(fpath) as fp:
requirements_extra[name] = list(map(str, parse_requirements(fp.readline())))
def _requirement_extras(path_req: str = _PATH_REQUIRE) -> dict:
extras = {}
for fpath in glob.glob(os.path.join(path_req, "*.txt")):
fname = os.path.basename(fpath)
if fname.startswith(("_", "gha-")):
continue
if fname in ("base.txt",):
continue
name, _ = os.path.splitext(fname)
with open(fpath) as fp:
reqs = parse_requirements(fp.readlines())
extras[name] = list(map(str, reqs))
return extras


# loading readme as description
with open(os.path.join(_PATH_ROOT, "README.md")) as fp:
Expand All @@ -46,6 +54,7 @@ def _load_py_module(fname: str, pkg: str = "lightning_utilities"):
url=about.__homepage__,
download_url="https://github.com/Lightning-AI/utilities",
license=about.__license__,
# fixme: somehow the `.cli` is missing in created package
packages=find_packages(where="src"),
package_dir={"": "src"},
long_description=readme,
Expand All @@ -56,7 +65,7 @@ def _load_py_module(fname: str, pkg: str = "lightning_utilities"):
python_requires=">=3.7",
setup_requires=[],
install_requires=requirements,
extras_require=requirements_extra,
extras_require=_requirement_extras(),
project_urls={
"Bug Tracker": "https://github.com/Lightning-AI/utilities/issues",
"Documentation": "https://dev-toolbox.rtfd.io/en/latest/", # TODO: Update domain
Expand Down

0 comments on commit f940b93

Please sign in to comment.