Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: drop yesqa, covered with RUF100 #19532

Merged
merged 10 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ repos:
hooks:
- id: sphinx-lint

- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
name: Unused noqa
additional_dependencies:
#- pep8-naming
- flake8-pytest-style
- flake8-bandit
- flake8-simplify
- flake8-return

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.2.0"
hooks:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ lint.extend-select = [
"SIM", # see: https://pypi.org/project/flake8-simplify
"RET", # see: https://pypi.org/project/flake8-return
"PT", # see: https://pypi.org/project/flake8-pytest-style
"RUF100", # see: https://docs.astral.sh/ruff/rules/unused-noqa/
]
lint.ignore = [
"E731", # Do not assign a lambda expression, use a def
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/app/cli/lightning_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _run_app(
) -> None:
if not os.path.exists(file):
original_file = file
file = cmd_install.gallery_apps_and_components(file, True, "latest", overwrite=True) # type: ignore[assignment] # noqa E501
file = cmd_install.gallery_apps_and_components(file, True, "latest", overwrite=True) # type: ignore[assignment] # E501
if file is None:
click.echo(f"The provided entrypoint `{original_file}` doesn't exist.")
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/app/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_lightning_cloud_url() -> str:
ENABLE_UPLOAD_ENDPOINT = bool(int(os.getenv("ENABLE_UPLOAD_ENDPOINT", "1")))

# directory where system customization sync files stored
SYS_CUSTOMIZATIONS_SYNC_ROOT = "/tmp/sys-customizations-sync" # noqa: S108 # todo
SYS_CUSTOMIZATIONS_SYNC_ROOT = "/tmp/sys-customizations-sync" # todo
# directory where system customization sync files will be copied to be packed into app tarball
SYS_CUSTOMIZATIONS_SYNC_PATH = ".sys-customizations-sync"

Expand Down
2 changes: 1 addition & 1 deletion src/lightning/app/source_code/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _get_hash(files: List[str], algorithm: str = "blake2", chunk_num_blocks: int
if algorithm == "blake2":
h = hashlib.blake2b(digest_size=20)
elif algorithm == "md5":
h = hashlib.md5() # noqa: S324
h = hashlib.md5()
else:
raise ValueError(f"Algorithm {algorithm} not supported")

Expand Down
2 changes: 1 addition & 1 deletion src/lightning/app/storage/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def hash(self) -> Optional[str]:
if self._origin is None:
return None
contents = f"{self.origin_name}/{self}"
return hashlib.sha1(contents.encode("utf-8")).hexdigest() # noqa: S324
return hashlib.sha1(contents.encode("utf-8")).hexdigest()

@property
def parents(self) -> Sequence["Path"]:
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/app/storage/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def hash(self) -> Optional[str]:
if self._origin is None:
return None
contents = f"{self.origin_name}/{self.consumer_name}/{self.name}"
return hashlib.sha1(contents.encode("utf-8")).hexdigest() # noqa: S324
return hashlib.sha1(contents.encode("utf-8")).hexdigest()

@property
def origin_name(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/app/utilities/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def stop_server_once_request_is_done():

if not token:
logger.warn(
"Login Failed. This is most likely because you're using an older version of the CLI. \n" # noqa E501
"Login Failed. This is most likely because you're using an older version of the CLI. \n" # E501
"Please try to update the CLI or open an issue with this information \n" # E501
f"expected token in {request.query_params.items()}"
)
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/fabric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lightning_utilities.core.imports import package_available

if os.path.isfile(os.path.join(os.path.dirname(__file__), "__about__.py")):
from lightning.fabric.__about__ import * # noqa: F401, F403
from lightning.fabric.__about__ import * # noqa: F403
if os.path.isfile(os.path.join(os.path.dirname(__file__), "__version__.py")):
from lightning.fabric.__version__ import version as __version__
elif package_available("lightning"):
Expand Down
2 changes: 1 addition & 1 deletion src/lightning/pytorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lightning_utilities import module_available

if os.path.isfile(os.path.join(os.path.dirname(__file__), "__about__.py")):
from lightning.pytorch.__about__ import * # noqa: F401, F403
from lightning.pytorch.__about__ import * # noqa: F403
if "__version__" not in locals():
if os.path.isfile(os.path.join(os.path.dirname(__file__), "__version__.py")):
from lightning.pytorch.__version__ import version as __version__
Expand Down
6 changes: 3 additions & 3 deletions src/lightning/pytorch/loops/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ def _decorator(self: _Loop, *args: Any, **kwargs: Any) -> Any:
if not hasattr(self, "inference_mode"):
raise TypeError(f"`{type(self).__name__}.inference_mode` needs to be defined")
context_manager: Type[ContextManager]
if _distributed_is_initialized() and dist.get_backend() == "gloo": # noqa: SIM114
if _distributed_is_initialized() and dist.get_backend() == "gloo":
# gloo backend does not work properly.
# https://github.com/Lightning-AI/lightning/pull/12715/files#r854569110
# TODO: explore why and possibly open an issue in PyTorch repository
context_manager = torch.no_grad
elif isinstance(self.trainer.accelerator, XLAAccelerator): # noqa: SIM114
elif isinstance(self.trainer.accelerator, XLAAccelerator):
context_manager = torch.no_grad
elif isinstance(self.trainer.strategy, FSDPStrategy): # noqa: SIM114
elif isinstance(self.trainer.strategy, FSDPStrategy):
# https://github.com/pytorch/pytorch/issues/95957
context_manager = torch.no_grad
elif _TORCH_EQUAL_2_0 and self.trainer.lightning_module._compiler_ctx is not None:
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app/cli/test_cmd_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_list_all_apps_paginated(list_memberships: mock.MagicMock, list_instance
list_memberships.assert_called_once()
assert list_instances.mock_calls == [
mock.call(project_id="default-project", limit=100, phase_in=[]),
mock.call(project_id="default-project", page_token="page-2", limit=100, phase_in=[]), # noqa: S106
mock.call(project_id="default-project", page_token="page-2", limit=100, phase_in=[]),
]


Expand Down
1 change: 1 addition & 0 deletions tests/tests_app/cli/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def monkeypatch_connection(monkeypatch, tmpdir, ppid):
return connection_path


@pytest.mark.flaky(reruns=3, reruns_delay=2)
def test_connect_disconnect_local(tmpdir, monkeypatch):
disconnect_app()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_client_server():

secrets = [Secret(name="example", value="secret")]

general = _GeneralModel.from_obj(TestConfig(name="name", secrets=secrets), token="a") # noqa: S106
general = _GeneralModel.from_obj(TestConfig(name="name", secrets=secrets), token="a")
assert general.cls_name == "TestConfig"
assert general.data == '{"id": null, "name": "name", "secrets": [{"name": "example", "value": "secret"}]}'

Expand Down
1 change: 1 addition & 0 deletions tests/tests_app/core/test_lightning_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ def _dump_checkpoint(self):
raise SuccessException


@pytest.mark.flaky(reruns=3)
def test_snap_shotting():
with contextlib.suppress(SuccessException):
app = CheckpointLightningApp(FlowA())
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app/storage/test_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_lit_drive_transferring_files():
os.remove("a.txt")


@pytest.mark.flaky(reruns=3, reruns_delay=5) # todo: likely dead feature, fine to crash...
@pytest.mark.xfail(strict=False) # todo: likely dead feature, fine to crash...
def test_lit_drive():
with pytest.raises(Exception, match="Unknown protocol for the drive 'id' argument"):
Drive("invalid_drive_id")
Expand Down
6 changes: 2 additions & 4 deletions tests/tests_app/utilities/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,5 @@ def test_network_failure(
def test_with_api_key_only():
auth = login.Auth()
auth.save(user_id="7c8455e3-7c5f-4697-8a6d-105971d6b9bd", api_key="e63fae57-2b50-498b-bc46-d6204cbf330e")
assert (
auth.authenticate()
== "Basic N2M4NDU1ZTMtN2M1Zi00Njk3LThhNmQtMTA1OTcxZDZiOWJkOmU2M2ZhZTU3LTJiNTAtNDk4Yi1iYzQ2LWQ2MjA0Y2JmMzMwZQ==" # noqa E501
)
hash_ = "N2M4NDU1ZTMtN2M1Zi00Njk3LThhNmQtMTA1OTcxZDZiOWJkOmU2M2ZhZTU3LTJiNTAtNDk4Yi1iYzQ2LWQ2MjA0Y2JmMzMwZQ"
assert auth.authenticate() == f"Basic {hash_}==" # E501
2 changes: 1 addition & 1 deletion tests/tests_pytorch/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_model_checkpoint_options(tmpdir, save_top_k, save_last, expected_files)
"""Test ModelCheckpoint options."""

def mock_save_function(filepath, *args):
open(filepath, "a").close() # noqa: SIM115
open(filepath, "a").close()

# simulated losses
losses = [10, 9, 2.8, 5, 2.5]
Expand Down
Loading