Repository: Lightning-AI/utilities (language: python)

Issue:
ci: allow install extras for check
<details>
  <summary><b>Before submitting</b></summary>

- [x] Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
- [ ] Did you read the [contributor guideline](https://github.com/Lightning-AI/lightning/blob/master/.github/CONTRIBUTING.md), Pull Request section?
- Did you make sure to update the docs?
- [ ] Did all existing and newly added tests pass locally?

</details>

## What does this PR do?

Allow deduplicate dependencies for lightning extension, which has to have `lightning` installed but can't have it listed in base requirements for circular dependency or option to select between lightning and PL

https://github.com/Lightning-AI/lightning-Habana/blob/4e374c270dbf6c6be383a6476a074e3064e7e2e1/.github/workflows/ci-checks.yml#L31

## PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

<!--
Did you have fun?

Make sure you had fun coding 🙃
-->



Discussion / hints:

Fix patch:
diff --git a/.github/actions/pkg-install/action.yml b/.github/actions/pkg-install/action.yml
index 02a7167a..49e6c784 100644
--- a/.github/actions/pkg-install/action.yml
+++ b/.github/actions/pkg-install/action.yml
@@ -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"
@@ -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
@@ -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
diff --git a/.github/workflows/check-package.yml b/.github/workflows/check-package.yml
index 191d96a9..ea6f2d0d 100644
--- a/.github/workflows/check-package.yml
+++ b/.github/workflows/check-package.yml
@@ -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
@@ -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
@@ -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
 
diff --git a/.github/workflows/ci-use-checks.yaml b/.github/workflows/ci-use-checks.yaml
index be81d43b..78f37c00 100644
--- a/.github/workflows/ci-use-checks.yaml
+++ b/.github/workflows/ci-use-checks.yaml
@@ -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"],
@@ -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:
diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml
index fee80026..6b34a0e6 100644
--- a/.github/workflows/deploy-docs.yml
+++ b/.github/workflows/deploy-docs.yml
@@ -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
 
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f0689f0..49f4d3ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/Makefile b/Makefile
index 2dd8edbe..428bcbb2 100644
--- a/Makefile
+++ b/Makefile
@@ -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_*
@@ -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:
diff --git a/requirements/dev-docs.txt b/requirements/_docs.txt
similarity index 100%
rename from requirements/dev-docs.txt
rename to requirements/_docs.txt
diff --git a/setup.py b/setup.py
index fc318c1e..4007d95e 100755
--- a/setup.py
+++ b/setup.py
@@ -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:
@@ -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,
@@ -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


Test patch:
diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml
index 35dc59b1..56320c49 100644
--- a/.github/workflows/ci-testing.yml
+++ b/.github/workflows/ci-testing.yml
@@ -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
diff --git a/requirements/dev-tests.txt b/requirements/_tests.txt
similarity index 100%
rename from requirements/dev-tests.txt
rename to requirements/_tests.txt