From dc966403544b58cd16d1c3240a5bb449f40a10d3 Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+borda@users.noreply.github.com> Date: Tue, 13 Dec 2022 06:55:39 +0100 Subject: [PATCH] CI: clean install & share pkg build (#15986) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * abstract pkg build * share ci * syntax * Checkgroup * folders * whl 1st * doctest Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Carlos Mocholí (cherry picked from commit 18a463808cceb8346e7e411972425718dc7f9b83) --- .github/actions/pkg-check/action.yml | 1 - .github/actions/pkg-install/action.yml | 21 ++++-- .github/actions/pkg-publish/action.yml | 17 ++--- .github/checkgroup.yml | 3 + .github/workflows/_build-packages.yml | 65 +++++++++++++++++ .github/workflows/ci-app-examples.yml | 8 +- .github/workflows/ci-app-tests.yml | 9 ++- .github/workflows/ci-lite-tests.yml | 4 +- .github/workflows/ci-pkg-install.yml | 59 ++++++++++----- .github/workflows/ci-pytorch-tests.yml | 5 +- .github/workflows/docs-checks.yml | 4 +- .github/workflows/release-pypi.yml | 73 +++++-------------- src/lightning_app/components/python/popen.py | 3 +- src/lightning_app/components/python/tracer.py | 2 +- src/lightning_app/core/app.py | 2 +- src/lightning_app/core/flow.py | 2 +- src/lightning_app/structures/dict.py | 2 +- src/lightning_app/structures/list.py | 2 +- .../utilities/packaging/build_config.py | 2 +- .../core/mixins/hparams_mixin.py | 4 + src/pytorch_lightning/utilities/parsing.py | 2 +- 21 files changed, 182 insertions(+), 108 deletions(-) create mode 100644 .github/workflows/_build-packages.yml diff --git a/.github/actions/pkg-check/action.yml b/.github/actions/pkg-check/action.yml index 6680f945d589d..941429d30c3da 100644 --- a/.github/actions/pkg-check/action.yml +++ b/.github/actions/pkg-check/action.yml @@ -5,7 +5,6 @@ inputs: pkg-name: description: package name inside lightning.* required: true - default: "" nb-dirs: description: nb of packages in the wrap/distribution required: false diff --git a/.github/actions/pkg-install/action.yml b/.github/actions/pkg-install/action.yml index 0e0751c217a95..3698dd82c11df 100644 --- a/.github/actions/pkg-install/action.yml +++ b/.github/actions/pkg-install/action.yml @@ -2,6 +2,9 @@ name: Install and validate the package description: Install and validate the package inputs: + pkg-folder: + description: Define folder with packages + required: true pkg-name: description: Package name to import required: true @@ -14,22 +17,26 @@ runs: using: "composite" steps: - name: Choose package import + working-directory: ${{ inputs.pkg-folder }} run: | - python -c "print('PKG_IMPORT=' + {'app': 'lightning_app', 'lite': 'lightning_lite', 'pytorch': 'pytorch_lightning', 'lightning': 'lightning'}['${{matrix.pkg-name}}'])" >> $GITHUB_ENV + ls -l + python -c "print('PKG_IMPORT=' + {'app': 'lightning_app', 'lite': 'lightning_lite', 'pytorch': 'pytorch_lightning'}.get('${{matrix.pkg-name}}', 'lightning'))" >> $GITHUB_ENV + python -c "import glob ; ls = glob.glob('*.tar.gz') ; print('PKG_SOURCE=' + ls[0])" >> $GITHUB_ENV + python -c "import glob ; ls = glob.glob('*.whl') ; print('PKG_WHEEL=' + ls[0])" >> $GITHUB_ENV shell: bash - - name: Install package - archive - working-directory: ./dist + - name: Install package - wheel + working-directory: ${{ inputs.pkg-folder }} run: | - pip install *.tar.gz ${{ inputs.pip-flags }} + pip install ${PKG_WHEEL} ${{ inputs.pip-flags }} pip list | grep lightning python -c "import ${{ env.PKG_IMPORT }}; print(${{ env.PKG_IMPORT }}.__version__)" shell: bash - - name: Install package - wheel - working-directory: ./dist + - name: Install package - archive + working-directory: ${{ inputs.pkg-folder }} run: | - pip install *.whl ${{ inputs.pip-flags }} + pip install ${PKG_SOURCE} ${{ inputs.pip-flags }} pip list | grep lightning python -c "import ${{ env.PKG_IMPORT }}; print(${{ env.PKG_IMPORT }}.__version__)" shell: bash diff --git a/.github/actions/pkg-publish/action.yml b/.github/actions/pkg-publish/action.yml index beef2d34f7db9..5e02dc70388ec 100644 --- a/.github/actions/pkg-publish/action.yml +++ b/.github/actions/pkg-publish/action.yml @@ -2,8 +2,8 @@ name: Publish package description: publishing whl and src to PyPI inputs: - pkg-pattern: - description: what file pattern is searched in folder, so for example `*_app*` + pkg-folder: + description: define folder with packages required: true pypi-test-token: description: login token for PyPI @@ -18,10 +18,7 @@ runs: using: "composite" steps: - - name: filter packages - run: | - mv dist/${{ inputs.pkg-pattern }} pypi/ - ls -l pypi/ + - run: ls -lh ${{ inputs.pkg-folder }} shell: bash # We do this, since failures on test.pypi aren't that bad @@ -32,7 +29,7 @@ runs: user: __token__ password: ${{ inputs.pypi-test-token }} repository_url: https://test.pypi.org/legacy/ - packages_dir: pypi/ + packages_dir: ${{ inputs.pkg-folder }} verbose: true - name: Publish distribution 📦 to PyPI @@ -41,9 +38,5 @@ runs: with: user: __token__ password: ${{ inputs.pypi-token }} - packages_dir: pypi/ + packages_dir: ${{ inputs.pkg-folder }} verbose: true - - - name: filter packages - run: rm pypi/* - shell: bash diff --git a/.github/checkgroup.yml b/.github/checkgroup.yml index 5ba130d45ac1e..eeb707267184e 100644 --- a/.github/checkgroup.yml +++ b/.github/checkgroup.yml @@ -312,6 +312,9 @@ subprojects: - id: "install" paths: - ".actions/**" + - ".github/actions/pkg-check/*" + - ".github/actions/pkg-install/*" + - ".github/workflows/_build-packages.yml" - ".github/workflows/ci-pkg-install.yml" - "setup.py" - "src/**" diff --git a/.github/workflows/_build-packages.yml b/.github/workflows/_build-packages.yml new file mode 100644 index 0000000000000..f2fe8239821fb --- /dev/null +++ b/.github/workflows/_build-packages.yml @@ -0,0 +1,65 @@ +name: Building packages + +on: + workflow_call: + inputs: + artifact-name: + description: 'Unique name for collecting artifacts' + required: true + type: string + pkg-names: + description: 'list package names to be build in json format' + required: false + type: string + default: | + ["lightning", "app", "lite", "pytorch"] + +defaults: + run: + shell: bash + +jobs: + + init: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - run: | + mkdir dist && touch dist/.placeholder + - uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: dist + + + build-packages: + needs: init + runs-on: ubuntu-20.04 + strategy: + max-parallel: 1 # run sequential to prevent download/upload collisions + matrix: + pkg-name: ${{ fromJSON(inputs.pkg-names) }} + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: pypi + - uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - run: python -c "print('NB_DIRS=' + str(2 if '${{ matrix.pkg-name }}' == 'pytorch' else 1))" >> $GITHUB_ENV + - uses: ./.github/actions/pkg-check + with: + pkg-name: ${{ matrix.pkg-name }} + nb-dirs: ${{ env.NB_DIRS }} + + - run: | + mkdir pypi/${{ matrix.pkg-name }} + cp dist/* pypi/${{ matrix.pkg-name }}/ + + - uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: pypi diff --git a/.github/workflows/ci-app-examples.yml b/.github/workflows/ci-app-examples.yml index b1a79ea50d9bc..2046cd940aafb 100644 --- a/.github/workflows/ci-app-examples.yml +++ b/.github/workflows/ci-app-examples.yml @@ -93,12 +93,16 @@ jobs: - name: Adjust tests if: ${{ matrix.pkg-name == 'lightning' }} - run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_app" --target_import="lightning.app" + run: | + python .actions/assistant.py copy_replace_imports --source_dir="./tests" \ + --source_import="lightning_app" --target_import="lightning.app" - name: Adjust examples if: ${{ matrix.pkg-name != 'lightning' }} run: | - python .actions/assistant.py copy_replace_imports --source_dir="./examples" --source_import="lightning.app,lightning" --target_import="lightning_app,lightning_app" + python .actions/assistant.py copy_replace_imports --source_dir="./examples" \ + --source_import="lightning.app,lightning" \ + --target_import="lightning_app,lightning_app" - name: Switch coverage scope run: python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.pkg-name}}' == 'lightning' else 'lightning_app'))" >> $GITHUB_ENV diff --git a/.github/workflows/ci-app-tests.yml b/.github/workflows/ci-app-tests.yml index f53b3fa9803a3..1a082f69c0a1d 100644 --- a/.github/workflows/ci-app-tests.yml +++ b/.github/workflows/ci-app-tests.yml @@ -99,12 +99,17 @@ jobs: - name: Adjust tests if: ${{ matrix.pkg-name == 'lightning' }} - run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_app,lightning_lite,pytorch_lightning" --target_import="lightning.app,lightning.lite,lightning.pytorch" + run: | + python .actions/assistant.py copy_replace_imports --source_dir="./tests" \ + --source_import="lightning_app,lightning_lite,pytorch_lightning" \ + --target_import="lightning.app,lightning.lite,lightning.pytorch" - name: Adjust examples if: ${{ matrix.pkg-name != 'lightning' }} run: | - python .actions/assistant.py copy_replace_imports --source_dir="./examples" --source_import="lightning.app,lightning" --target_import="lightning_app,lightning_app" + python .actions/assistant.py copy_replace_imports --source_dir="./examples" \ + --source_import="lightning.app,lightning" \ + --target_import="lightning_app,lightning_app" - name: Switch coverage scope run: python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.pkg-name}}' == 'lightning' else 'lightning_app'))" >> $GITHUB_ENV diff --git a/.github/workflows/ci-lite-tests.yml b/.github/workflows/ci-lite-tests.yml index fb134b301b6e6..1db82fe8ba52c 100644 --- a/.github/workflows/ci-lite-tests.yml +++ b/.github/workflows/ci-lite-tests.yml @@ -114,7 +114,9 @@ jobs: - name: Adjust tests if: ${{ matrix.pkg-name == 'lightning' }} - run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_lite" --target_import="lightning.lite" + run: | + python .actions/assistant.py copy_replace_imports --source_dir="./tests" \ + --source_import="lightning_lite" --target_import="lightning.lite" - name: Testing Warnings # the stacklevel can only be set on >=3.7 diff --git a/.github/workflows/ci-pkg-install.yml b/.github/workflows/ci-pkg-install.yml index d9474edb98f8f..ca3a6d695a91e 100644 --- a/.github/workflows/ci-pkg-install.yml +++ b/.github/workflows/ci-pkg-install.yml @@ -9,6 +9,9 @@ on: types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped paths: - ".actions/**" + - ".github/actions/pkg-check/*" + - ".github/actions/pkg-install/*" + - ".github/workflows/_build-packages.yml" - ".github/workflows/ci-pkg-install.yml" - "setup.py" - "src/**" @@ -28,7 +31,13 @@ defaults: jobs: + build-packages: + uses: ./.github/workflows/_build-packages.yml + with: + artifact-name: dist-packages-${{ github.sha }} + install-pkg: + needs: build-packages runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -36,35 +45,51 @@ jobs: os: [ubuntu-22.04, macOS-12, windows-2022] pkg-name: ["app", "lite", "pytorch", "lightning"] python-version: ["3.7" , "3.10"] + # TODO: add also install from source steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - - name: DocTests actions - working-directory: .actions/ - run: | - pip install -q pytest - python -m pytest setup_tools.py - - - run: python -c "print('NB_DIRS=' + str(2 if '${{ matrix.pkg-name }}' == 'pytorch' else 1))" >> $GITHUB_ENV - - - uses: ./.github/actions/pkg-check + - uses: actions/download-artifact@v3 with: - pkg-name: ${{ matrix.pkg-name }} - nb-dirs: ${{ env.NB_DIRS }} + name: dist-packages-${{ github.sha }} + path: dist + - run: | + python -c "print('PKG_DIR=' + {'notset': 'lightning'}.get('${{matrix.pkg-name}}', '${{matrix.pkg-name}}'))" >> $GITHUB_ENV - uses: ./.github/actions/pkg-install with: + pkg-folder: dist/${{ env.PKG_DIR }} pkg-name: ${{ matrix.pkg-name }} - - name: Run CLI - # todo: add testing for `lightning_app` - if: ${{ matrix.pkg-name == 'lightning' }} + - name: Run CLI (via python) + if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'notset' }} run: python -m lightning --version + - name: Run CLI (direct bash) + if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'app' }} + run: lightning --version + - name: Adjust code for Lit + if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'notset' }} + run: | + pip install -q -r .actions/requirements.txt + python .actions/assistant.py copy_replace_imports --source_dir="./src" \ + --source_import="pytorch_lightning,lightning_lite,lightning_app" \ + --target_import="lightning.pytorch,lightning.lite,lightning.app" + rm -rf src/lightning + - name: Rename src folders + working-directory: src/ + run: | + mv pytorch_lightning pl + mv lightning_lite lit_lite + mv lightning_app lit_app + + - name: DocTests actions + working-directory: .actions/ + run: | + pip install -q pytest + python -m pytest setup_tools.py - name: DocTest package env: LIGHTING_TESTING: 1 # path for require wrapper @@ -72,5 +97,5 @@ jobs: run: | pip install -q "pytest-doctestplus>=0.9.0" pip list - PKG_NAME=$(python -c "print({'app': 'lightning_app', 'lite': 'lightning_lite', 'pytorch': 'pytorch_lightning', 'lightning': 'lightning'}['${{matrix.pkg-name}}'])") + PKG_NAME=$(python -c "print({'app': 'lit_app', 'lite': 'lit_lite', 'pytorch': 'pl'}.get('${{matrix.pkg-name}}', ''))") python -m pytest src/${PKG_NAME} --ignore-glob="**/cli/*-template/**" diff --git a/.github/workflows/ci-pytorch-tests.yml b/.github/workflows/ci-pytorch-tests.yml index b4e51ccddf5a0..34ef2b0834949 100644 --- a/.github/workflows/ci-pytorch-tests.yml +++ b/.github/workflows/ci-pytorch-tests.yml @@ -169,7 +169,10 @@ jobs: - name: Adjust tests if: ${{ matrix.pkg-name == 'lightning' }} - run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="pytorch_lightning,lightning_lite" --target_import="lightning.pytorch,lightning.lite" + run: | + python .actions/assistant.py copy_replace_imports --source_dir="./tests" \ + --source_import="pytorch_lightning,lightning_lite" \ + --target_import="lightning.pytorch,lightning.lite" - name: Testing Warnings # the stacklevel can only be set on >=3.7 diff --git a/.github/workflows/docs-checks.yml b/.github/workflows/docs-checks.yml index e51b76991397e..302e9836df55e 100644 --- a/.github/workflows/docs-checks.yml +++ b/.github/workflows/docs-checks.yml @@ -83,7 +83,9 @@ jobs: if: ${{ matrix.pkg-name == 'app' }} run: | pip install -q -r .actions/requirements.txt - python .actions/assistant.py copy_replace_imports --source_dir="./docs" --source_import="pytorch_lightning,lightning_lite" --target_import="lightning.pytorch,lightning.lite" + python .actions/assistant.py copy_replace_imports --source_dir="./docs" \ + --source_import="pytorch_lightning,lightning_lite" \ + --target_import="lightning.pytorch,lightning.lite" - name: Install this package env: diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index 67dc4af93e09e..9bd578334a7a3 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -13,47 +13,10 @@ defaults: jobs: - init: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - run: | - mkdir dist && touch dist/.placeholder - - uses: actions/upload-artifact@v3 - with: - name: dist-packages-${{ github.sha }} - path: dist - - build-packages: - needs: init - runs-on: ubuntu-20.04 - strategy: - fail-fast: true - max-parallel: 1 # run sequential to prevent download/upload collisions - matrix: - pkg-name: ["lightning", "app", "lite", "pytorch"] - steps: - - uses: actions/checkout@v3 - - uses: actions/download-artifact@v3 - with: - name: dist-packages-${{ github.sha }} - path: dist - - uses: actions/setup-python@v4 - with: - python-version: 3.9 - - name: Install dependencies - run: pip install -U setuptools wheel - - name: Build packages - env: - PACKAGE_NAME: ${{ matrix.pkg-name }} - run: | - python setup.py sdist bdist_wheel - ls -lh dist/ - - uses: actions/upload-artifact@v3 - with: - name: dist-packages-${{ github.sha }} - path: dist + uses: ./.github/workflows/_build-packages.yml + with: + artifact-name: dist-packages-${{ github.sha }} upload-packages: @@ -70,7 +33,7 @@ jobs: - name: Upload to release uses: AButler/upload-release-assets@v2.0 with: - files: 'dist/*' + files: 'dist/*/*' repo-token: ${{ secrets.GITHUB_TOKEN }} @@ -158,28 +121,28 @@ jobs: needs: build-packages if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' steps: - - uses: actions/checkout@v3 - uses: actions/download-artifact@v3 with: name: dist-packages-${{ github.sha }} path: dist - - run: ls -lh dist/ - - run: mkdir pypi/ + - run: | + sudo apt install -q -y tree + tree -L 2 -h dist/ - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*app*" + pkg-folder: dist/app pypi-test-token: ${{ secrets.PYPI_TEST_TOKEN_APP }} - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*lite*" + pkg-folder: dist/lite pypi-test-token: ${{ secrets.PYPI_TEST_TOKEN_LITE }} - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*pytorch*" + pkg-folder: dist/pytorch pypi-test-token: ${{ secrets.PYPI_TEST_TOKEN_PYTORCH }} - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*" + pkg-folder: dist/lightning pypi-test-token: ${{ secrets.PYPI_TEST_TOKEN_LAI }} @@ -188,28 +151,28 @@ jobs: needs: [build-packages, waiting] if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' steps: - - uses: actions/checkout@v3 - uses: actions/download-artifact@v3 with: name: dist-packages-${{ github.sha }} path: dist - - run: ls -lh dist/ - - run: mkdir pypi/ + - run: | + sudo apt install -q -y tree + tree -L 2 -h dist/ - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*app*" + pkg-folder: dist/app pypi-token: ${{ secrets.PYPI_TOKEN_APP }} - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*lite*" + pkg-folder: dist/lite pypi-token: ${{ secrets.PYPI_TOKEN_LITE }} - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*pytorch*" + pkg-folder: dist/pytorch pypi-token: ${{ secrets.PYPI_TOKEN_PYTORCH }} - uses: ./.github/actions/pkg-publish with: - pkg-pattern: "*" + pkg-folder: dist/lightning pypi-token: ${{ secrets.PYPI_TOKEN_LAI }} diff --git a/src/lightning_app/components/python/popen.py b/src/lightning_app/components/python/popen.py index 868ba45d26b7d..bb7980566cdc1 100644 --- a/src/lightning_app/components/python/popen.py +++ b/src/lightning_app/components/python/popen.py @@ -41,8 +41,7 @@ def __init__( Raises: FileNotFoundError: If the provided `script_path` doesn't exists. - .. doctest:: - + Example: >>> from lightning_app.components.python import PopenPythonScript >>> f = open("a.py", "w") diff --git a/src/lightning_app/components/python/tracer.py b/src/lightning_app/components/python/tracer.py index d10ca92252ed8..af1eb678d613e 100644 --- a/src/lightning_app/components/python/tracer.py +++ b/src/lightning_app/components/python/tracer.py @@ -70,7 +70,7 @@ def __init__( This method takes any python globals before executing the script, e.g., you can modify classes or function from the script. - .. doctest:: + Example: >>> from lightning_app.components.python import TracerPythonScript >>> f = open("a.py", "w") diff --git a/src/lightning_app/core/app.py b/src/lightning_app/core/app.py index 47055c70f7f4b..9c3aeeb650de0 100644 --- a/src/lightning_app/core/app.py +++ b/src/lightning_app/core/app.py @@ -87,7 +87,7 @@ def __init__( You can learn more about proxy `here `_. - .. doctest:: + Example: >>> from lightning_app import LightningFlow, LightningApp >>> from lightning_app.runners import MultiProcessRuntime diff --git a/src/lightning_app/core/flow.py b/src/lightning_app/core/flow.py index 5a82400066f05..67854b5555831 100644 --- a/src/lightning_app/core/flow.py +++ b/src/lightning_app/core/flow.py @@ -77,7 +77,7 @@ def __init__(self): can be distributed (each LightningWork will be run within its own process or different arrangements). - .. doctest:: + Example: >>> from lightning_app import LightningFlow >>> class RootFlow(LightningFlow): diff --git a/src/lightning_app/structures/dict.py b/src/lightning_app/structures/dict.py index 7bf102e19f180..0489bb7d0e986 100644 --- a/src/lightning_app/structures/dict.py +++ b/src/lightning_app/structures/dict.py @@ -19,7 +19,7 @@ def __init__(self, **kwargs: T): :class:`~lightning_app.core.work.LightningWork` or :class:`~lightning_app.core.flow.LightningFlow`. - .. doctest:: + Example: >>> from lightning_app import LightningFlow, LightningWork >>> from lightning_app.structures import Dict diff --git a/src/lightning_app/structures/list.py b/src/lightning_app/structures/list.py index 9f110c69b1388..940973d212cd9 100644 --- a/src/lightning_app/structures/list.py +++ b/src/lightning_app/structures/list.py @@ -19,7 +19,7 @@ def __init__(self, *items: T): :class:`~lightning_app.core.work.LightningWork` or :class:`~lightning_app.core.flow.LightningFlow`. - .. doctest:: + Example: >>> from lightning_app import LightningFlow, LightningWork >>> from lightning_app.structures import List diff --git a/src/lightning_app/utilities/packaging/build_config.py b/src/lightning_app/utilities/packaging/build_config.py index 7c20853bec157..51a610d213529 100644 --- a/src/lightning_app/utilities/packaging/build_config.py +++ b/src/lightning_app/utilities/packaging/build_config.py @@ -91,7 +91,7 @@ def build_commands(self) -> List[str]: .. note:: If you provide your own dockerfile, this would be ignored. - .. doctest:: + Example: from dataclasses import dataclass from lightning_app import BuildConfig diff --git a/src/pytorch_lightning/core/mixins/hparams_mixin.py b/src/pytorch_lightning/core/mixins/hparams_mixin.py index b5b4a9b312312..abbca184e8c35 100644 --- a/src/pytorch_lightning/core/mixins/hparams_mixin.py +++ b/src/pytorch_lightning/core/mixins/hparams_mixin.py @@ -47,6 +47,7 @@ class ``__init__`` to be ignored logger: Whether to send the hyperparameters to the logger. Default: True Example:: + >>> from pytorch_lightning.core.mixins import HyperparametersMixin >>> class ManuallyArgsModel(HyperparametersMixin): ... def __init__(self, arg1, arg2, arg3): ... super().__init__() @@ -59,6 +60,7 @@ class ``__init__`` to be ignored "arg1": 1 "arg3": 3.14 + >>> from pytorch_lightning.core.mixins import HyperparametersMixin >>> class AutomaticArgsModel(HyperparametersMixin): ... def __init__(self, arg1, arg2, arg3): ... super().__init__() @@ -72,6 +74,7 @@ class ``__init__`` to be ignored "arg2": abc "arg3": 3.14 + >>> from pytorch_lightning.core.mixins import HyperparametersMixin >>> class SingleArgModel(HyperparametersMixin): ... def __init__(self, params): ... super().__init__() @@ -85,6 +88,7 @@ class ``__init__`` to be ignored "p2": abc "p3": 3.14 + >>> from pytorch_lightning.core.mixins import HyperparametersMixin >>> class ManuallyArgsModel(HyperparametersMixin): ... def __init__(self, arg1, arg2, arg3): ... super().__init__() diff --git a/src/pytorch_lightning/utilities/parsing.py b/src/pytorch_lightning/utilities/parsing.py index eed889716f88f..ae969041da62a 100644 --- a/src/pytorch_lightning/utilities/parsing.py +++ b/src/pytorch_lightning/utilities/parsing.py @@ -185,7 +185,7 @@ def collect_init_args( path_args.append(local_args) return collect_init_args(frame.f_back, path_args, inside=True, classes=classes) if not inside: - return collect_init_args(frame.f_back, path_args, inside, classes=classes) + return collect_init_args(frame.f_back, path_args, inside=False, classes=classes) return path_args