[LAI] Rename instances of "lightning_app" and "pytorch_lightning" (#15208)

* rename instances of lightning_app and pytorch_lightning
* solve failing azure tests
* wrong runif import
* lit_app

Co-authored-by: Jirka <jirka.borovec@seznam.cz>
This commit is contained in:
otaj 2022-10-20 12:56:44 +02:00 committed by GitHub
parent 741462f373
commit 2f5060963a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 47 additions and 50 deletions

View File

@ -79,12 +79,10 @@ def connect(app_name_or_id: str, yes: bool = False):
if not api_commands:
client = LightningClient()
project = _get_project(client)
lightningapps = client.lightningapp_instance_service_list_lightningapp_instances(
project_id=project.project_id
)
apps = client.lightningapp_instance_service_list_lightningapp_instances(project_id=project.project_id)
click.echo(
"We didn't find a matching App. Here are the available Apps that could be "
f"connected to {[app.name for app in lightningapps.lightningapps]}."
f"connected to {[app.name for app in apps.lightningapps]}."
)
return

View File

@ -41,9 +41,9 @@ logger = Logger(__name__)
def get_app_url(runtime_type: RuntimeType, *args: Any, need_credits: bool = False) -> str:
if runtime_type == RuntimeType.CLOUD:
lightning_app: Externalv1LightningappInstance = args[0]
lit_app: Externalv1LightningappInstance = args[0]
action = "?action=add_credits" if need_credits else ""
return f"{get_lightning_cloud_url()}/me/apps/{lightning_app.id}{action}"
return f"{get_lightning_cloud_url()}/me/apps/{lit_app.id}{action}"
else:
return "http://127.0.0.1:7501/view"

View File

@ -227,10 +227,10 @@ class CloudRuntime(Runtime):
)
if list_apps_resp.lightningapps:
# There can be only one app with unique project_id<>name pair
lightning_app = list_apps_resp.lightningapps[0]
lit_app = list_apps_resp.lightningapps[0]
else:
app_body = Body7(name=app_config.name, can_download_source_code=True)
lightning_app = self.backend.client.lightningapp_v2_service_create_lightningapp_v2(
lit_app = self.backend.client.lightningapp_v2_service_create_lightningapp_v2(
project_id=project.project_id, body=app_body
)
@ -264,7 +264,7 @@ class CloudRuntime(Runtime):
self._ensure_cluster_project_binding(project.project_id, cluster_id)
lightning_app_release = self.backend.client.lightningapp_v2_service_create_lightningapp_release(
project_id=project.project_id, app_id=lightning_app.id, body=release_body
project_id=project.project_id, app_id=lit_app.id, body=release_body
)
if cluster_id is not None:
@ -288,7 +288,7 @@ class CloudRuntime(Runtime):
# right now we only allow a single instance of the app
find_instances_resp = self.backend.client.lightningapp_instance_service_list_lightningapp_instances(
project_id=project.project_id, app_id=lightning_app.id
project_id=project.project_id, app_id=lit_app.id
)
queue_server_type = V1QueueServerType.REDIS if CLOUD_QUEUE_TYPE == "redis" else V1QueueServerType.HTTP
if find_instances_resp.lightningapps:
@ -335,12 +335,12 @@ class CloudRuntime(Runtime):
lightning_app_instance = (
self.backend.client.lightningapp_v2_service_create_lightningapp_release_instance(
project_id=project.project_id,
app_id=lightning_app.id,
app_id=lit_app.id,
id=lightning_app_release.id,
body=Body9(
cluster_id=cluster_id,
desired_state=app_release_desired_state,
name=lightning_app.name,
name=lit_app.name,
env=v1_env_vars,
queue_server_type=queue_server_type,
),

View File

@ -54,7 +54,7 @@ class RunIf:
def __new__(
self,
*args,
pytorch_lightning: bool = False,
pl: bool = False,
flash: bool = False,
min_python: Optional[str] = None,
skip_windows: bool = False,
@ -67,7 +67,7 @@ class RunIf:
"""
Args:
*args: Any :class:`pytest.mark.skipif` arguments.
pytorch_lightning: Requires that PyTorch Lightning is installed.
pl: Requires that PyTorch Lightning is installed.
flash: Requires that Flash is installed.
min_python: Require that Python is greater or equal than this version.
skip_windows: Skip for Windows platform.
@ -95,7 +95,7 @@ class RunIf:
conditions.append(sys.platform == "darwin")
reasons.append("unimplemented on MacOS")
if pytorch_lightning:
if pl:
conditions.append(not _is_pytorch_lightning_available())
reasons.append("PyTorch Lightning is required.")

View File

@ -358,7 +358,7 @@ def run_app_in_cloud(
client = LightningClient()
project = _get_project(client)
lightning_apps = [
lit_apps = [
app
for app in client.lightningapp_instance_service_list_lightningapp_instances(
project_id=project.project_id
@ -366,11 +366,11 @@ def run_app_in_cloud(
if app.name == name
]
if not lightning_apps:
if not lit_apps:
return True
assert len(lightning_apps) == 1
app_id = lightning_apps[0].id
assert len(lit_apps) == 1
app_id = lit_apps[0].id
if debug:
process = Process(target=print_logs, kwargs={"app_id": app_id})
@ -386,7 +386,7 @@ def run_app_in_cloud(
except (playwright._impl._api_types.Error, playwright._impl._api_types.TimeoutError):
pass
lightning_apps = [
lit_apps = [
app
for app in client.lightningapp_instance_service_list_lightningapp_instances(
project_id=project.project_id
@ -394,7 +394,7 @@ def run_app_in_cloud(
if app.name == name
]
app_url = lightning_apps[0].status.url
app_url = lit_apps[0].status.url
while True:
sleep(1)
@ -476,19 +476,19 @@ def delete_cloud_lightning_apps():
print(f"deleting apps for pr_number: {pr_number}, app_name: {app_name}")
project = _get_project(client)
list_lightningapps = client.lightningapp_instance_service_list_lightningapp_instances(project_id=project.project_id)
list_apps = client.lightningapp_instance_service_list_lightningapp_instances(project_id=project.project_id)
print([lightningapp.name for lightningapp in list_lightningapps.lightningapps])
print([lit_app.name for lit_app in list_apps.lightningapps])
for lightningapp in list_lightningapps.lightningapps:
if pr_number and app_name and not lightningapp.name.startswith(f"test-{pr_number}-{app_name}-"):
for lit_app in list_apps.lightningapps:
if pr_number and app_name and not lit_app.name.startswith(f"test-{pr_number}-{app_name}-"):
continue
print(f"Deleting {lightningapp.name}")
print(f"Deleting {lit_app.name}")
try:
res = client.lightningapp_instance_service_delete_lightningapp_instance(
project_id=project.project_id,
id=lightningapp.id,
id=lit_app.id,
)
assert res == {}
except ApiException as e:
print(f"Failed to delete {lightningapp.name}. Exception {e}")
print(f"Failed to delete {lit_app.name}. Exception {e}")

View File

@ -107,25 +107,23 @@ def _retrieve_application_url_and_available_commands(app_id_or_name_or_url: Opti
else:
client = LightningClient()
project = _get_project(client)
list_lightningapps = client.lightningapp_instance_service_list_lightningapp_instances(
project_id=project.project_id
)
list_apps = client.lightningapp_instance_service_list_lightningapp_instances(project_id=project.project_id)
lightningapp_names = [lightningapp.name for lightningapp in list_lightningapps.lightningapps]
app_names = [lightningapp.name for lightningapp in list_apps.lightningapps]
if not app_id_or_name_or_url:
raise Exception(f"Provide an application name, id or url with --app_id=X. Found {lightningapp_names}")
raise Exception(f"Provide an application name, id or url with --app_id=X. Found {app_names}")
for lightningapp in list_lightningapps.lightningapps:
if lightningapp.id == app_id_or_name_or_url or lightningapp.name == app_id_or_name_or_url:
if lightningapp.status.url == "":
for app in list_apps.lightningapps:
if app.id == app_id_or_name_or_url or app.name == app_id_or_name_or_url:
if app.status.url == "":
raise Exception("The application is starting. Try in a few moments.")
resp = requests.get(lightningapp.status.url + "/openapi.json")
resp = requests.get(app.status.url + "/openapi.json")
if resp.status_code != 200:
raise Exception(
"The server didn't process the request properly. " "Try once your application is ready."
)
return lightningapp.status.url, _extract_command_from_openapi(resp.json()), lightningapp.id
return app.status.url, _extract_command_from_openapi(resp.json()), app.id
return None, None, None

View File

@ -27,7 +27,7 @@ def test_build_config_requirements_provided():
assert spec.requirements == [
"dask",
"pandas",
"pytorch_lightning==1.5.9",
"pytorch_" + "lightning==1.5.9", # ugly hack due to replacing `pytorch_lightning string`
"git+https://github.com/mit-han-lab/torchsparse.git@v1.4.0",
]
assert spec == BuildConfig.from_dict(spec.to_dict())
@ -47,13 +47,15 @@ def test_build_config_invalid_requirements():
def test_build_config_dockerfile_provided():
spec = BuildConfig(dockerfile="./projects/Dockerfile.cpu")
assert not spec.requirements
assert "pytorchlightning/pytorch_lightning" in spec.dockerfile[0]
# ugly hack due to replacing `pytorch_lightning string
assert "pytorchlightning/pytorch_" + "lightning" in spec.dockerfile[0]
class DockerfileLightningTestApp(LightningTestApp):
def on_after_run_once(self):
print(self.root.work.local_build_config.dockerfile)
assert "pytorchlightning/pytorch_lightning" in self.root.work.local_build_config.dockerfile[0]
# ugly hack due to replacing `pytorch_lightning string
assert "pytorchlightning/pytorch_" + "lightning" in self.root.work.local_build_config.dockerfile[0]
return super().on_after_run_once()
@ -68,7 +70,7 @@ class RequirementsLightningTestApp(LightningTestApp):
assert self.root.work.local_build_config.requirements == [
"git+https://github.com/mit-han-lab/torchsparse.git@v1.4.0",
"pandas",
"pytorch_lightning==1.5.9",
"pytorch_" + "lightning==1.5.9", # ugly hack due to replacing `pytorch_lightning string
]
return super().on_after_run_once()

View File

@ -1,9 +1,8 @@
import os
from numbers import Rational
import pytest
from lightning_app import LightningApp, LightningFlow
from lightning_app.testing.helpers import RunIf
from lightning_app.utilities.imports import _is_pytorch_lightning_available
from lightning_app.utilities.introspection import Scanner
@ -26,7 +25,7 @@ def test_introspection():
assert not scanner.has_class(LightningFlow)
@pytest.mark.skipif(not _is_pytorch_lightning_available(), reason="pytorch_lightning isn't installed.")
@RunIf(pl=True)
def test_introspection_lightning():
"""This test validates the scanner can find some PyTorch Lightning class within the provided files."""
scanner = Scanner(str(os.path.join(_PROJECT_ROOT, "tests/tests_app/core/scripts/lightning_cli.py")))
@ -38,7 +37,7 @@ def test_introspection_lightning():
assert not scanner.has_class(LightningCLI)
@pytest.mark.skipif(not _is_pytorch_lightning_available(), reason="pytorch_lightning isn't installed.")
@RunIf(pl=True)
def test_introspection_lightning_overrides():
"""This test validates the scanner can find all the subclasses from primitives classes from PyTorch Lightning
in the provided files."""

View File

@ -7,7 +7,7 @@ from lightning_app.testing.helpers import RunIf
from lightning_app.utilities.tracer import Tracer
@RunIf(pytorch_lightning=True)
@RunIf(pl=True)
def test_tracer():
from pytorch_lightning import Trainer

View File

@ -8,7 +8,7 @@ from lightning_app.cli.lightning_cli import run_app
from lightning_app.testing.helpers import run_script, RunIf
@RunIf(pytorch_lightning=True)
@RunIf(pl=True)
@pytest.mark.parametrize(
"file",
[
@ -21,7 +21,7 @@ def test_scripts(file):
@pytest.mark.skip(reason="causing some issues with CI, not sure if the test is actually needed")
@RunIf(pytorch_lightning=True)
@RunIf(pl=True)
def test_components_app_example():
runner = CliRunner()

View File

@ -26,7 +26,7 @@ class QuickStartApp(LightningApp):
# TODO: Investigate why it doesn't work
@pytest.mark.skipif(True, reason="test is skipped because CI was blocking all the PRs.")
@RunIf(pytorch_lightning=True, skip_windows=True, skip_linux=True)
@RunIf(pl=True, skip_windows=True, skip_linux=True)
def test_quick_start_example(caplog, monkeypatch):
"""This test ensures the Quick Start example properly train and serve PyTorch Lightning."""