Skip to content

Commit

Permalink
remove pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikiforov committed Jun 29, 2024
1 parent 5c12a99 commit 87b2b6a
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 55 deletions.
4 changes: 0 additions & 4 deletions .codeclimate.yml

This file was deleted.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ There are some requirements for pull requests:
* 100% test coverage also for new features is expected.
* After running `./scripts/test`, you will see the test coverage results in the output
* You can also open the HTML report at: `./htmlcov/index.html`
* Code is formatted with [autopep8](https://github.com/hhatto/autopep8). Run `./scripts/format`
* No [pylint](https://www.pylint.org/) errors. Run `./scripts/lint` (or `pylint icloudpd`)
* Code is formatted with [ruff](https://github.com/astral-sh/ruff). Run `./scripts/format`
* No lint errors. Run `./scripts/lint`
* If you've added or changed any command-line options,
please update the [Usage](README.md#usage) section in the README.md.
* Make sure your change is documented in the
Expand Down
1 change: 0 additions & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
set -euo pipefail
echo "Linting..."
# python3 -m pylint src --ignore-paths src/icloud,src/pyicloud_ipd,src/starters
ruff check --ignore "E402"
25 changes: 8 additions & 17 deletions src/icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ def file_match_policy_generator(
# a hacky way to get proper version because automatic detection does not
# work for some reason
@click.version_option(version="1.20.3")
# pylint: disable-msg=too-many-arguments,too-many-statements
# pylint: disable-msg=too-many-branches,too-many-locals
def main(
directory: Optional[str],
username: str,
Expand Down Expand Up @@ -491,7 +489,7 @@ def main(
log_level: str,
no_progress_bar: bool,
notification_script: Optional[str],
threads_num: int, # pylint: disable=W0613
threads_num: int,
delete_after_download: bool,
domain: str,
watch_with_interval: Optional[int],
Expand Down Expand Up @@ -607,10 +605,6 @@ def main(
)


# pylint: disable-msg=too-many-arguments,too-many-statements
# pylint: disable-msg=too-many-branches,too-many-locals


def download_builder(
logger: logging.Logger,
skip_videos: bool,
Expand Down Expand Up @@ -672,15 +666,13 @@ def download_photo_(counter: Counter, photo: PhotoAsset) -> bool:
except KeyError as ex:
print(f"KeyError: {ex} attribute was not found in the photo fields.")
with open(file="icloudpd-photo-error.json", mode="w", encoding="utf8") as outfile:
# pylint: disable=protected-access
json.dump(
{
"master_record": photo._master_record,
"asset_record": photo._asset_record,
},
outfile,
)
# pylint: enable=protected-access
print("icloudpd has saved the photo record to: " "./icloudpd-photo-error.json")
print(
"Please create a Gist with the contents of this file: "
Expand Down Expand Up @@ -832,7 +824,6 @@ def delete_photo(
"""Delete a photo from the iCloud account."""
clean_filename_local = photo.filename
logger.debug("Deleting %s in iCloud...", clean_filename_local)
# pylint: disable=W0212
url = (
f"{photo_service._service_endpoint}/records/modify?"
f"{urllib.parse.urlencode(photo_service.params)}"
Expand Down Expand Up @@ -884,7 +875,6 @@ def retrier(
while True:
try:
return func()
# pylint: disable-msg=broad-except
except Exception as ex:
attempts += 1
error_handler(ex, attempts)
Expand Down Expand Up @@ -943,10 +933,6 @@ def composed(ex: Exception, retries: int) -> None:
return composed


# pylint: disable-msg=too-many-arguments,too-many-statements
# pylint: disable-msg=too-many-branches,too-many-locals


def core(
downloader: Callable[[PyiCloudService], Callable[[Counter, PhotoAsset], bool]],
directory: Optional[str],
Expand Down Expand Up @@ -1150,8 +1136,13 @@ def should_break(counter: Counter) -> bool:
break
item = next(photos_iterator)
if download_photo(consecutive_files_found, item) and delete_after_download:

delete_local = partial(delete_photo_dry_run if dry_run else delete_photo, logger, icloud.photos, library_object, item)
delete_local = partial(
delete_photo_dry_run if dry_run else delete_photo,
logger,
icloud.photos,
library_object,
item,
)

retrier(delete_local, error_handler)

Expand Down
1 change: 0 additions & 1 deletion src/icloudpd/counter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Atomic counter"""

# pylint: skip-file
from multiprocessing import Lock, RawValue


Expand Down
5 changes: 1 addition & 4 deletions src/icloudpd/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyicloud_ipd.services.photos import PhotoAsset
from pyicloud_ipd.version_size import VersionSize
from requests import Response
from requests.exceptions import ConnectionError # pylint: disable=redefined-builtin
from requests.exceptions import ConnectionError
from tzlocal import get_localzone

# Import the constants object so that we can mock WAIT_SECONDS in tests
Expand Down Expand Up @@ -94,9 +94,6 @@ def download_response_to_path_dry_run(
return True


# pylint: disable-msg=too-many-arguments


def download_media(
logger: logging.Logger,
dry_run: bool,
Expand Down
2 changes: 0 additions & 2 deletions src/icloudpd/email_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import smtplib
from typing import Optional, cast

# pylint: disable-msg=too-many-arguments


def send_2sa_notification(
logger: logging.Logger,
Expand Down
2 changes: 1 addition & 1 deletion src/pyicloud_ipd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
try:
with open(self.session_path, encoding="utf-8") as session_f:
self.session_data = json.load(session_f)
except: # pylint: disable=bare-except
except:
LOGGER.info("Session file does not exist")
session_client_id: Optional[str] = self.session_data.get("client_id")
if session_client_id:
Expand Down
3 changes: 1 addition & 2 deletions src/pyicloud_ipd/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, service: Any):

@override
# type: ignore
# pylint: disable=arguments-differ
def request(self, method: str, url, **kwargs):

# Charge logging to the right service endpoint
Expand Down Expand Up @@ -132,7 +131,7 @@ def request(self, method: str, url, **kwargs):

try:
data = response.json() if response.status_code != 204 else {}
except: # pylint: disable=bare-except
except:
request_logger.warning("Failed to parse response with JSON mimetype")
return response

Expand Down
8 changes: 4 additions & 4 deletions tests/test_autodelete_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def mock_raise_response_error(
a1_: logging.Logger, a2_: PhotosService, a3_: PhotoLibrary, a4_: PhotoAsset
) -> None:
if not hasattr(self, f"already_raised_session_exception{inspect.stack()[0][3]}"):
setattr(self, f"already_raised_session_exception{inspect.stack()[0][3]}", True) # noqa: B010
setattr(self, f"already_raised_session_exception{inspect.stack()[0][3]}", True) # noqa: B010
raise PyiCloudAPIResponseException("Invalid global session", "100")

with mock.patch("time.sleep") as sleep_mock: # noqa: SIM117
Expand All @@ -382,7 +382,7 @@ def mock_raise_response_error(
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, f"already_authenticated{inspect.stack()[0][3]}"):
orig_authenticate(self)
setattr(self, f"already_authenticated{inspect.stack()[0][3]}", True) # noqa: B010
setattr(self, f"already_authenticated{inspect.stack()[0][3]}", True) # noqa: B010

with mock.patch.object(
PyiCloudService, "authenticate", new=mocked_authenticate
Expand Down Expand Up @@ -474,7 +474,7 @@ def mock_raise_response_error(
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, f"already_authenticated{inspect.stack()[0][3]}"):
orig_authenticate(self)
setattr(self, f"already_authenticated{inspect.stack()[0][3]}", True) # noqa: B010
setattr(self, f"already_authenticated{inspect.stack()[0][3]}", True) # noqa: B010

with mock.patch.object(
PyiCloudService, "authenticate", new=mocked_authenticate
Expand Down Expand Up @@ -558,7 +558,7 @@ def mock_raise_response_error(
a1_: logging.Logger, a2_: PhotosService, a3_: PhotoLibrary, a4_: PhotoAsset
) -> None:
if not hasattr(self, f"already_raised_session_exception{inspect.stack()[0][3]}"):
setattr(self, f"already_raised_session_exception{inspect.stack()[0][3]}", True) # noqa: B010
setattr(self, f"already_raised_session_exception{inspect.stack()[0][3]}", True) # noqa: B010
raise PyiCloudAPIResponseException("INTERNAL_ERROR", "INTERNAL_ERROR")

with mock.patch("time.sleep") as sleep_mock: # noqa: SIM117
Expand Down
16 changes: 8 additions & 8 deletions tests/test_download_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_download_photos_and_set_exif(self) -> None:
def mocked_download(pa: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(pa, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down Expand Up @@ -452,7 +452,7 @@ def mock_raise_response_error(_arg: Any) -> NoReturn:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
# Pass fixed client ID via environment variable
Expand Down Expand Up @@ -507,7 +507,7 @@ def mock_raise_response_error(_offset: int) -> NoReturn:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
# Pass fixed client ID via environment variable
Expand Down Expand Up @@ -561,7 +561,7 @@ def mock_raise_response_error(_arg: Any) -> NoReturn:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch("icloudpd.constants.WAIT_SECONDS", 0): # noqa: SIM117
with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
Expand Down Expand Up @@ -617,7 +617,7 @@ def mock_raise_response_error() -> None:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch("icloudpd.constants.WAIT_SECONDS", 0): # noqa: SIM117
with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def test_download_and_dedupe_existing_photos(self) -> None:
def mocked_download(self: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(self, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down Expand Up @@ -1197,7 +1197,7 @@ def test_download_one_recent_live_photo(self) -> None:
def mocked_download(pa: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(pa, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down Expand Up @@ -1252,7 +1252,7 @@ def test_download_one_recent_live_photo_chinese(self) -> None:
def mocked_download(pa: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(pa, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down
16 changes: 8 additions & 8 deletions tests/test_download_photos_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_download_photos_and_set_exif_name_id7(self) -> None:
def mocked_download(pa: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(pa, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down Expand Up @@ -453,7 +453,7 @@ def mock_raise_response_error(_arg: Any) -> NoReturn:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
# Pass fixed client ID via environment variable
Expand Down Expand Up @@ -508,7 +508,7 @@ def mock_raise_response_error(_offset: int) -> NoReturn:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
# Pass fixed client ID via environment variable
Expand Down Expand Up @@ -562,7 +562,7 @@ def mock_raise_response_error(_arg: Any) -> NoReturn:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch("icloudpd.constants.WAIT_SECONDS", 0): # noqa: SIM117
with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
Expand Down Expand Up @@ -618,7 +618,7 @@ def mock_raise_response_error() -> None:
def mocked_authenticate(self: PyiCloudService) -> None:
if not hasattr(self, "already_authenticated"):
orig_authenticate(self)
setattr(self, "already_authenticated", True) # noqa: B010
setattr(self, "already_authenticated", True) # noqa: B010

with mock.patch("icloudpd.constants.WAIT_SECONDS", 0): # noqa: SIM117
with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate):
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def test_download_and_dedupe_existing_photos_name_id7(self) -> None:
def mocked_download(self: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(self, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down Expand Up @@ -1185,7 +1185,7 @@ def test_download_one_recent_live_photo_name_id7(self) -> None:
def mocked_download(pa: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(pa, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down Expand Up @@ -1240,7 +1240,7 @@ def test_download_one_recent_live_photo_chinese_name_id7(self) -> None:
def mocked_download(pa: PhotoAsset, _url: str) -> Response:
if not hasattr(PhotoAsset, "already_downloaded"):
response = orig_download(pa, _url)
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
setattr(PhotoAsset, "already_downloaded", True) # noqa: B010
return response
return mock.MagicMock()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_listing_recent_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_listing_recent_photos_with_missing_downloadURL(self) -> None:
recreate_path(dir)

# Note - This test uses the same cassette as test_download_photos.py
with vcr.use_cassette( # noqa: SIM117
with vcr.use_cassette( # noqa: SIM117
os.path.join(self.vcr_path, "listing_photos_missing_downloadUrl.yml")
):
with mock.patch("icloudpd.base.open", create=True) as mock_open:
Expand Down

0 comments on commit 87b2b6a

Please sign in to comment.