From f867f15c10d8a5ef66507f2c6b9c808f18e185a3 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Tue, 12 Jul 2022 14:09:46 +0100 Subject: [PATCH 01/10] wip --- examples/app_argparse/app.py | 28 +++++++++++++++++++++++ src/lightning_app/cli/lightning_cli.py | 19 ++++++++------- src/lightning_app/testing/testing.py | 10 ++++++-- src/lightning_app/utilities/load_app.py | 16 ++++++++++++- tests/tests_app_examples/test_argparse.py | 15 ++++++++++++ 5 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 examples/app_argparse/app.py create mode 100644 tests/tests_app_examples/test_argparse.py diff --git a/examples/app_argparse/app.py b/examples/app_argparse/app.py new file mode 100644 index 0000000000000..361b305585768 --- /dev/null +++ b/examples/app_argparse/app.py @@ -0,0 +1,28 @@ +from argparse import ArgumentParser + +from lightning import CloudCompute, LightningApp, LightningFlow, LightningWork + + +class Work(LightningWork): + def __init__(self, cloud_compute): + super().__init__(cloud_compute=cloud_compute) + + def run(self): + pass + + +class Flow(LightningFlow): + def __init__(self, cloud_compute): + super().__init__() + self.work = Work(cloud_compute) + + def run(self): + assert self.work.cloud_compute.name == "gpu", self.work.cloud_compute.name + self._exit() + + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("--use_gpu", action="store_true", default=False, help="Whether to use GPU in the cloud") + hparams = parser.parse_args() + app = LightningApp(Flow(CloudCompute("gpu" if hparams.use_gpu else "cpu"))) diff --git a/src/lightning_app/cli/lightning_cli.py b/src/lightning_app/cli/lightning_cli.py index fb39f743ec3a2..696269c712ea9 100644 --- a/src/lightning_app/cli/lightning_cli.py +++ b/src/lightning_app/cli/lightning_cli.py @@ -1,7 +1,7 @@ import logging import os from pathlib import Path -from typing import Tuple, Union +from typing import List, Tuple, Union import click from requests.exceptions import ConnectionError @@ -109,8 +109,17 @@ def run(): @click.option("--blocking", "blocking", type=bool, default=False) @click.option("--open-ui", type=bool, default=True, help="Decide whether to launch the app UI in a web browser") @click.option("--env", type=str, default=[], multiple=True, help="Env variables to be set for the app.") +@click.option("--app_args", type=str, default=[], multiple=True, help="Collection of arguments for the app.") def run_app( - file: str, cloud: bool, without_server: bool, no_cache: bool, name: str, blocking: bool, open_ui: bool, env: tuple + file: str, + cloud: bool, + without_server: bool, + no_cache: bool, + name: str, + blocking: bool, + open_ui: bool, + env: tuple, + app_args: List[str], ): """Run an app from a file.""" _run_app(file, cloud, without_server, no_cache, name, blocking, open_ui, env) @@ -263,10 +272,4 @@ def _prepare_file(file: str) -> str: if exists: return file - if not exists and file == "quick_start.py": - from lightning_app.demo.quick_start import app - - logger.info(f"For demo purposes, Lightning will run the {app.__file__} file.") - return app.__file__ - raise FileNotFoundError(f"The provided file {file} hasn't been found.") diff --git a/src/lightning_app/testing/testing.py b/src/lightning_app/testing/testing.py index 7ae9bf6274e6c..e72c6d05ae4b0 100644 --- a/src/lightning_app/testing/testing.py +++ b/src/lightning_app/testing/testing.py @@ -76,14 +76,20 @@ def restart_work(self, work_name: str): @requires("click") -def application_testing(lightning_app_cls: Type[LightningTestApp], command_line: List[str] = []) -> Any: +def application_testing( + lightning_app_cls: Type[LightningTestApp] = LightningTestApp, command_line: List[str] = [] +) -> Any: from unittest import mock from click.testing import CliRunner with mock.patch("lightning.LightningApp", lightning_app_cls): + original = sys.argv + sys.argv = command_line runner = CliRunner() - return runner.invoke(run_app, command_line, catch_exceptions=False) + result = runner.invoke(run_app, command_line, catch_exceptions=False) + sys.argv = original + return result class SingleWorkFlow(LightningFlow): diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 3fef4e63f92bd..cd44a569bedb1 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -4,6 +4,7 @@ import sys import traceback import types +from argparse import ArgumentParser from typing import Dict, List, TYPE_CHECKING, Union from lightning_app.utilities.exceptions import MisconfigurationException @@ -26,7 +27,7 @@ def load_app_from_file(filepath: str) -> "LightningApp": code = _create_code(filepath) module = _create_fake_main_module(filepath) try: - exec(code, module.__dict__) + exec(code, _patch_argparse(module.__dict__)) except Exception: # we want to format the exception as if no frame was on top. exp, val, tb = sys.exc_info() @@ -113,6 +114,19 @@ def _create_fake_main_module(script_path): return module +def _patch_argparse(exec_globals): + """This function replaces parse_args by parse_known_args to avoid Argparse to fails due to lightning run + app.""" + cls = ArgumentParser + + def fn(*args, **kwargs): + return ArgumentParser.parse_known_args(*args, **kwargs)[0] + + cls.parse_args = fn + exec_globals["ArgumentParser"] = cls + return exec_globals + + def component_to_metadata(obj: Union["LightningWork", "LightningFlow"]) -> Dict: from lightning_app import LightningWork diff --git a/tests/tests_app_examples/test_argparse.py b/tests/tests_app_examples/test_argparse.py new file mode 100644 index 0000000000000..bc8bcfa2d0168 --- /dev/null +++ b/tests/tests_app_examples/test_argparse.py @@ -0,0 +1,15 @@ +import os + +from lightning_app import _PACKAGE_ROOT +from lightning_app.testing.testing import application_testing + + +def test_app_argparse_example(): + command_line = [ + os.path.join(os.path.dirname(os.path.dirname(_PACKAGE_ROOT)), "examples/app_argparse/app.py"), + "--app_args", + "--use_gpu", + "--without-server", + ] + result = application_testing(command_line=command_line) + assert result.exit_code == 0 From 3d8503863fcdb5ab44c337405ffb042262c556de Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Tue, 12 Jul 2022 15:14:58 +0100 Subject: [PATCH 02/10] wip --- examples/app_argparse/app.py | 4 +-- src/lightning_app/utilities/load_app.py | 33 +++++++++++++-------- tests/tests_app_examples/test_argparse.py | 35 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/examples/app_argparse/app.py b/examples/app_argparse/app.py index 361b305585768..56a8053ec7f31 100644 --- a/examples/app_argparse/app.py +++ b/examples/app_argparse/app.py @@ -1,4 +1,4 @@ -from argparse import ArgumentParser +import argparse from lightning import CloudCompute, LightningApp, LightningFlow, LightningWork @@ -22,7 +22,7 @@ def run(self): if __name__ == "__main__": - parser = ArgumentParser() + parser = argparse.ArgumentParser() parser.add_argument("--use_gpu", action="store_true", default=False, help="Whether to use GPU in the cloud") hparams = parser.parse_args() app = LightningApp(Flow(CloudCompute("gpu" if hparams.use_gpu else "cpu"))) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index cd44a569bedb1..fb2d855775e43 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -4,7 +4,7 @@ import sys import traceback import types -from argparse import ArgumentParser +from contextlib import contextmanager from typing import Dict, List, TYPE_CHECKING, Union from lightning_app.utilities.exceptions import MisconfigurationException @@ -27,7 +27,8 @@ def load_app_from_file(filepath: str) -> "LightningApp": code = _create_code(filepath) module = _create_fake_main_module(filepath) try: - exec(code, _patch_argparse(module.__dict__)) + with _patch_sys_argv(): + exec(code, module.__dict__) except Exception: # we want to format the exception as if no frame was on top. exp, val, tb = sys.exc_info() @@ -114,17 +115,25 @@ def _create_fake_main_module(script_path): return module -def _patch_argparse(exec_globals): - """This function replaces parse_args by parse_known_args to avoid Argparse to fails due to lightning run - app.""" - cls = ArgumentParser +@contextmanager +def _patch_sys_argv(): + from lightning_app.cli.lightning_cli import run_app - def fn(*args, **kwargs): - return ArgumentParser.parse_known_args(*args, **kwargs)[0] - - cls.parse_args = fn - exec_globals["ArgumentParser"] = cls - return exec_globals + original_argv = sys.argv + if "--app_args" not in sys.argv: + new_argv = [sys.executable] + sys.argv[3:4] + else: + options = [p.opts[0] for p in run_app.params[1:] if p.opts[0] != "--app_args"] + argv_slice = sys.argv[3:] + first_index = argv_slice.index("--app_args") + 1 + last_index = min( + [len(argv_slice)] + + [argv_slice.index(opt) for opt in options if opt in argv_slice and argv_slice.index(opt) > first_index] + ) + new_argv = [sys.executable] + [argv_slice[0]] + argv_slice[first_index:last_index] + sys.argv = new_argv + yield + sys.argv = original_argv def component_to_metadata(obj: Union["LightningWork", "LightningFlow"]) -> Dict: diff --git a/tests/tests_app_examples/test_argparse.py b/tests/tests_app_examples/test_argparse.py index bc8bcfa2d0168..9bf7d091654bb 100644 --- a/tests/tests_app_examples/test_argparse.py +++ b/tests/tests_app_examples/test_argparse.py @@ -1,7 +1,9 @@ import os +import sys from lightning_app import _PACKAGE_ROOT from lightning_app.testing.testing import application_testing +from lightning_app.utilities.load_app import _patch_sys_argv def test_app_argparse_example(): @@ -13,3 +15,36 @@ def test_app_argparse_example(): ] result = application_testing(command_line=command_line) assert result.exit_code == 0 + + +def test_patch_sys_argv(): + original_argv = sys.argv + + sys.argv = ["lightning", "run", "app", "app.py"] + with _patch_sys_argv(): + assert sys.argv == [sys.executable, "app.py"] + + sys.argv = ["lightning", "run", "app", "app.py", "--without-server", "--env", "name=something"] + with _patch_sys_argv(): + assert sys.argv == [sys.executable, "app.py"] + + sys.argv = ["lightning", "run", "app", "app.py", "--app_args"] + with _patch_sys_argv(): + assert sys.argv == [sys.executable, "app.py"] + + sys.argv = [ + "lightning", + "run", + "app", + "app.py", + "--without-server", + "--app_args", + "--use_gpu", + "--name=hello", + "--env", + "name=something", + ] + with _patch_sys_argv(): + assert sys.argv == [sys.executable, "app.py", "--use_gpu", "--name=hello"] + + sys.argv = original_argv From e0c99ce2ef3d7e803f4b3c731d566a27bc1ad86d Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Tue, 12 Jul 2022 15:43:26 +0100 Subject: [PATCH 03/10] wip --- src/lightning_app/utilities/load_app.py | 7 ++++--- tests/tests_app_examples/test_argparse.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index fb2d855775e43..0b22c23f425cb 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -120,17 +120,18 @@ def _patch_sys_argv(): from lightning_app.cli.lightning_cli import run_app original_argv = sys.argv + sys.argv = [v for v in sys.argv if v not in ("lightning", "run", "app")] if "--app_args" not in sys.argv: - new_argv = [sys.executable] + sys.argv[3:4] + new_argv = sys.argv[:1] else: options = [p.opts[0] for p in run_app.params[1:] if p.opts[0] != "--app_args"] - argv_slice = sys.argv[3:] + argv_slice = sys.argv first_index = argv_slice.index("--app_args") + 1 last_index = min( [len(argv_slice)] + [argv_slice.index(opt) for opt in options if opt in argv_slice and argv_slice.index(opt) > first_index] ) - new_argv = [sys.executable] + [argv_slice[0]] + argv_slice[first_index:last_index] + new_argv = [argv_slice[0]] + argv_slice[first_index:last_index] sys.argv = new_argv yield sys.argv = original_argv diff --git a/tests/tests_app_examples/test_argparse.py b/tests/tests_app_examples/test_argparse.py index 9bf7d091654bb..6b87fb3606204 100644 --- a/tests/tests_app_examples/test_argparse.py +++ b/tests/tests_app_examples/test_argparse.py @@ -14,7 +14,7 @@ def test_app_argparse_example(): "--without-server", ] result = application_testing(command_line=command_line) - assert result.exit_code == 0 + assert result.exit_code == 0, result.__dict__ def test_patch_sys_argv(): @@ -22,15 +22,15 @@ def test_patch_sys_argv(): sys.argv = ["lightning", "run", "app", "app.py"] with _patch_sys_argv(): - assert sys.argv == [sys.executable, "app.py"] + assert sys.argv == ["app.py"] sys.argv = ["lightning", "run", "app", "app.py", "--without-server", "--env", "name=something"] with _patch_sys_argv(): - assert sys.argv == [sys.executable, "app.py"] + assert sys.argv == ["app.py"] sys.argv = ["lightning", "run", "app", "app.py", "--app_args"] with _patch_sys_argv(): - assert sys.argv == [sys.executable, "app.py"] + assert sys.argv == ["app.py"] sys.argv = [ "lightning", @@ -45,6 +45,6 @@ def test_patch_sys_argv(): "name=something", ] with _patch_sys_argv(): - assert sys.argv == [sys.executable, "app.py", "--use_gpu", "--name=hello"] + assert sys.argv == ["app.py", "--use_gpu", "--name=hello"] sys.argv = original_argv From 0ba50bf0a1e99b1e446e55a0cf7a4b7ba686cca5 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Tue, 12 Jul 2022 16:08:35 +0100 Subject: [PATCH 04/10] update --- tests/tests_app_examples/test_argparse.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/tests_app_examples/test_argparse.py b/tests/tests_app_examples/test_argparse.py index 6b87fb3606204..5b04fd883f04b 100644 --- a/tests/tests_app_examples/test_argparse.py +++ b/tests/tests_app_examples/test_argparse.py @@ -7,6 +7,8 @@ def test_app_argparse_example(): + original_argv = sys.argv + command_line = [ os.path.join(os.path.dirname(os.path.dirname(_PACKAGE_ROOT)), "examples/app_argparse/app.py"), "--app_args", @@ -15,24 +17,31 @@ def test_app_argparse_example(): ] result = application_testing(command_line=command_line) assert result.exit_code == 0, result.__dict__ + assert sys.argv == original_argv def test_patch_sys_argv(): original_argv = sys.argv - sys.argv = ["lightning", "run", "app", "app.py"] + sys.argv = expected = ["lightning", "run", "app", "app.py"] with _patch_sys_argv(): assert sys.argv == ["app.py"] - sys.argv = ["lightning", "run", "app", "app.py", "--without-server", "--env", "name=something"] + assert sys.argv == expected + + sys.argv = expected = ["lightning", "run", "app", "app.py", "--without-server", "--env", "name=something"] with _patch_sys_argv(): assert sys.argv == ["app.py"] - sys.argv = ["lightning", "run", "app", "app.py", "--app_args"] + assert sys.argv == expected + + sys.argv = expected = ["lightning", "run", "app", "app.py", "--app_args"] with _patch_sys_argv(): assert sys.argv == ["app.py"] - sys.argv = [ + assert sys.argv == expected + + sys.argv = expected = [ "lightning", "run", "app", @@ -47,4 +56,6 @@ def test_patch_sys_argv(): with _patch_sys_argv(): assert sys.argv == ["app.py", "--use_gpu", "--name=hello"] + assert sys.argv == expected + sys.argv = original_argv From a6a34c34f989173614752dcd52b1dc80b6391f86 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Tue, 12 Jul 2022 16:39:59 +0100 Subject: [PATCH 05/10] Update examples/app_argparse/app.py Co-authored-by: Kushashwa Ravi Shrimali --- examples/app_argparse/app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/app_argparse/app.py b/examples/app_argparse/app.py index 56a8053ec7f31..98683d7ef3112 100644 --- a/examples/app_argparse/app.py +++ b/examples/app_argparse/app.py @@ -1,9 +1,9 @@ import argparse -from lightning import CloudCompute, LightningApp, LightningFlow, LightningWork +import lightning as L -class Work(LightningWork): +class Work(L.LightningWork): def __init__(self, cloud_compute): super().__init__(cloud_compute=cloud_compute) @@ -11,7 +11,7 @@ def run(self): pass -class Flow(LightningFlow): +class Flow(L.LightningFlow): def __init__(self, cloud_compute): super().__init__() self.work = Work(cloud_compute) @@ -25,4 +25,4 @@ def run(self): parser = argparse.ArgumentParser() parser.add_argument("--use_gpu", action="store_true", default=False, help="Whether to use GPU in the cloud") hparams = parser.parse_args() - app = LightningApp(Flow(CloudCompute("gpu" if hparams.use_gpu else "cpu"))) + app = L.LightningApp(Flow(L.CloudCompute("gpu" if hparams.use_gpu else "cpu"))) From 5c6927ffe1ea3b0912d6866d3c2a5091c09cd5a7 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Tue, 12 Jul 2022 16:44:43 +0100 Subject: [PATCH 06/10] update --- src/lightning_app/utilities/load_app.py | 11 +++++++---- tests/tests_app_examples/test_argparse.py | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index 0b22c23f425cb..b7492f11b8ad8 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -127,10 +127,13 @@ def _patch_sys_argv(): options = [p.opts[0] for p in run_app.params[1:] if p.opts[0] != "--app_args"] argv_slice = sys.argv first_index = argv_slice.index("--app_args") + 1 - last_index = min( - [len(argv_slice)] - + [argv_slice.index(opt) for opt in options if opt in argv_slice and argv_slice.index(opt) > first_index] - ) + matches = [ + argv_slice.index(opt) for opt in options if opt in argv_slice and argv_slice.index(opt) >= first_index + ] + if not matches: + last_index = len(argv_slice) + else: + last_index = min(matches) new_argv = [argv_slice[0]] + argv_slice[first_index:last_index] sys.argv = new_argv yield diff --git a/tests/tests_app_examples/test_argparse.py b/tests/tests_app_examples/test_argparse.py index 5b04fd883f04b..0c1e55b0d4498 100644 --- a/tests/tests_app_examples/test_argparse.py +++ b/tests/tests_app_examples/test_argparse.py @@ -41,6 +41,12 @@ def test_patch_sys_argv(): assert sys.argv == expected + sys.argv = expected = ["lightning", "run", "app", "app.py", "--app_args", "--env", "name=something"] + with _patch_sys_argv(): + assert sys.argv == ["app.py"] + + assert sys.argv == expected + sys.argv = expected = [ "lightning", "run", From 4d337f8ab43b6c8d18a17898319361ee46db6f25 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Wed, 13 Jul 2022 11:48:42 +0100 Subject: [PATCH 07/10] update --- .gitignore | 1 + examples/template_react_ui | 1 + src/lightning_app/utilities/load_app.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 160000 examples/template_react_ui diff --git a/.gitignore b/.gitignore index 47b9bfff92523..53ead6ee67bd9 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ cifar-10-batches-py # ctags tags .tags +*examples/template_react_ui* diff --git a/examples/template_react_ui b/examples/template_react_ui new file mode 160000 index 0000000000000..775cb9eea73ff --- /dev/null +++ b/examples/template_react_ui @@ -0,0 +1 @@ +Subproject commit 775cb9eea73ff7c5a4407648349d70d8224deb5f diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index b7492f11b8ad8..b265f248421a5 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -117,16 +117,28 @@ def _create_fake_main_module(script_path): @contextmanager def _patch_sys_argv(): + """This function modifies the ``sys.argv`` by extracting the arguments after ``--app_args`` and removed + everything else before executing the user app script. + + The command: ``lightning run app app.py --without-server --app_args --use_gpu --env ...`` will be converted into + ``app.py --use_gpu`` + """ from lightning_app.cli.lightning_cli import run_app original_argv = sys.argv + # 1: Remove the CLI command sys.argv = [v for v in sys.argv if v not in ("lightning", "run", "app")] + if "--app_args" not in sys.argv: + # 2: If app_args wasn't used, there is no arguments, so we assign the shorten arguments. new_argv = sys.argv[:1] else: + # 3: Collect all the arguments from the CLI options = [p.opts[0] for p in run_app.params[1:] if p.opts[0] != "--app_args"] argv_slice = sys.argv + # 4: Find the index of `app_args` first_index = argv_slice.index("--app_args") + 1 + # 5: Find the next argument from the CLI if any. matches = [ argv_slice.index(opt) for opt in options if opt in argv_slice and argv_slice.index(opt) >= first_index ] @@ -134,9 +146,13 @@ def _patch_sys_argv(): last_index = len(argv_slice) else: last_index = min(matches) + # 6: last_index is either the fully command or the latest match from the CLI options. new_argv = [argv_slice[0]] + argv_slice[first_index:last_index] + + # 7: Patch the command sys.argv = new_argv yield + # 8: Restore the command sys.argv = original_argv From 732ed783ad7012895bf3f579f96eb7c43d76cc88 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Wed, 13 Jul 2022 11:48:53 +0100 Subject: [PATCH 08/10] update --- examples/template_react_ui | 1 - 1 file changed, 1 deletion(-) delete mode 160000 examples/template_react_ui diff --git a/examples/template_react_ui b/examples/template_react_ui deleted file mode 160000 index 775cb9eea73ff..0000000000000 --- a/examples/template_react_ui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 775cb9eea73ff7c5a4407648349d70d8224deb5f From 6ac78026b38481e3e1548406f171fbe26c5d92be Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Wed, 13 Jul 2022 14:44:13 +0100 Subject: [PATCH 09/10] update --- MANIFEST.in | 6 ++++++ requirements/pytorch/docs.txt | 2 +- setup.py | 2 +- src/lightning_app/utilities/load_app.py | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index a8dbcff69b631..37c72c103b69c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,9 @@ exclude requirements.txt exclude __pycache__ include .actions/setup_tools.py include *.cff # citation info +recursive-include src *.md +recursive-include requirements *.txt +recursive-include src *.md +recursive-include requirements *.txt +recursive-include src *.md +recursive-include requirements *.txt diff --git a/requirements/pytorch/docs.txt b/requirements/pytorch/docs.txt index e6fbbe322b6bf..571a956aab524 100644 --- a/requirements/pytorch/docs.txt +++ b/requirements/pytorch/docs.txt @@ -14,4 +14,4 @@ sphinx-copybutton>=0.3 typing-extensions # already in `requirements.txt` but the docs CI job does not install it jinja2>=3.0.0,<3.1.0 --r ../../_notebooks/.actions/requirements.txt +# -r ../../_notebooks/.actions/requirements.txt diff --git a/setup.py b/setup.py index a542b3c1e0291..6d271cc40b0aa 100755 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ from setuptools import setup -_PACKAGE_NAME = os.environ.get("PACKAGE_NAME", "") +_PACKAGE_NAME = "" _PACKAGE_MAPPING = {"pytorch": "pytorch_lightning", "app": "lightning_app"} _REAL_PKG_NAME = _PACKAGE_MAPPING.get(_PACKAGE_NAME, _PACKAGE_NAME) # https://packaging.python.org/guides/single-sourcing-package-version/ diff --git a/src/lightning_app/utilities/load_app.py b/src/lightning_app/utilities/load_app.py index b265f248421a5..0fff863bc43de 100644 --- a/src/lightning_app/utilities/load_app.py +++ b/src/lightning_app/utilities/load_app.py @@ -127,7 +127,8 @@ def _patch_sys_argv(): original_argv = sys.argv # 1: Remove the CLI command - sys.argv = [v for v in sys.argv if v not in ("lightning", "run", "app")] + if sys.argv[:3] == ["lightning", "run", "app"]: + sys.argv = sys.argv[3:] if "--app_args" not in sys.argv: # 2: If app_args wasn't used, there is no arguments, so we assign the shorten arguments. From 6d134fcf04c6782aa00c236520530e7a3f1eaee5 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Wed, 13 Jul 2022 15:16:57 +0100 Subject: [PATCH 10/10] update --- MANIFEST.in | 6 ------ requirements/pytorch/docs.txt | 2 +- setup.py | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 37c72c103b69c..a8dbcff69b631 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,9 +3,3 @@ exclude requirements.txt exclude __pycache__ include .actions/setup_tools.py include *.cff # citation info -recursive-include src *.md -recursive-include requirements *.txt -recursive-include src *.md -recursive-include requirements *.txt -recursive-include src *.md -recursive-include requirements *.txt diff --git a/requirements/pytorch/docs.txt b/requirements/pytorch/docs.txt index 571a956aab524..e6fbbe322b6bf 100644 --- a/requirements/pytorch/docs.txt +++ b/requirements/pytorch/docs.txt @@ -14,4 +14,4 @@ sphinx-copybutton>=0.3 typing-extensions # already in `requirements.txt` but the docs CI job does not install it jinja2>=3.0.0,<3.1.0 -# -r ../../_notebooks/.actions/requirements.txt +-r ../../_notebooks/.actions/requirements.txt diff --git a/setup.py b/setup.py index 6d271cc40b0aa..a542b3c1e0291 100755 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ from setuptools import setup -_PACKAGE_NAME = "" +_PACKAGE_NAME = os.environ.get("PACKAGE_NAME", "") _PACKAGE_MAPPING = {"pytorch": "pytorch_lightning", "app": "lightning_app"} _REAL_PKG_NAME = _PACKAGE_MAPPING.get(_PACKAGE_NAME, _PACKAGE_NAME) # https://packaging.python.org/guides/single-sourcing-package-version/