From 082afc7cdeb4b05735630c791231e8c932bf577f Mon Sep 17 00:00:00 2001 From: Althea Denlinger <67075698+altheaden@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:17:32 -0600 Subject: [PATCH] Update pre-commit dependencies (#353) * Update pre-commit dependencies * Fix `flake8` errors (two typos in var names) * Fix `mypy` importing errors * Fix `mypy` code errors * Update `conda/dev.yml` --- .pre-commit-config.yaml | 18 ++++++++++++------ conda/dev.yml | 10 +++++----- zstash/create.py | 1 - zstash/extract.py | 14 ++++++-------- zstash/hpss_utils.py | 6 ++---- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e3f1c022..482e6413 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ fail_fast: true repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -12,19 +12,19 @@ repos: exclude: conda/meta.yaml - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort # Need to use flake8 GitHub mirror due to CentOS git issue with GitLab # https://github.com/pre-commit/pre-commit/issues/1206 - repo: https://github.com/pycqa/flake8 - rev: 3.8.4 + rev: 7.1.1 hooks: - id: flake8 args: ["--config=setup.cfg"] @@ -32,7 +32,13 @@ repos: exclude: analysis_data_preprocess - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.790 + rev: v1.11.2 hooks: - id: mypy - args: ["--config=setup.cfg"] + args: ["--config=setup.cfg", "--install-types", "--non-interactive"] + exclude: test* + +# https://pre-commit.ci/#configuration +ci: + autofix_prs: false + autoupdate_schedule: monthly diff --git a/conda/dev.yml b/conda/dev.yml index e4b59950..a70d6164 100644 --- a/conda/dev.yml +++ b/conda/dev.yml @@ -13,11 +13,11 @@ dependencies: # Developer Tools # ================= # If versions are updated, also update 'rev' in `.pre-commit.config.yaml` - - black=22.8.0 - - flake8=5.0.4 - - flake8-isort=4.2.0 - - mypy=0.982 - - pre-commit=2.20.0 + - black=24.10.0 + - flake8=7.1.1 + - flake8-isort=6.1.1 + - mypy=1.11.2 + - pre-commit=4.0.1 - tbump=6.9.0 # Documentation # ================= diff --git a/zstash/create.py b/zstash/create.py index e8ca0c48..e8819278 100644 --- a/zstash/create.py +++ b/zstash/create.py @@ -24,7 +24,6 @@ def create(): cache: str - exclude: str cache, args = setup_create() # Check config fields diff --git a/zstash/extract.py b/zstash/extract.py index 42a06dfb..a0446cde 100644 --- a/zstash/extract.py +++ b/zstash/extract.py @@ -254,7 +254,7 @@ def extract_database( # This is because we may have different versions of the # same file across many tars. insert_idx: int - iter_inx: int + iter_idx: int insert_idx, iter_idx = 0, 1 for iter_idx in range(1, len(matches)): # If the filenames are unique, just increment insert_idx. @@ -351,10 +351,10 @@ def multiprocess_extract( for db_row in matches: tar = db_row.tar workers_idx: int - for worker_idx in range(len(workers_to_tars)): - if tar in workers_to_tars[worker_idx]: + for workers_idx in range(len(workers_to_tars)): + if tar in workers_to_tars[workers_idx]: # This worker gets this db_row. - workers_to_matches[worker_idx].append(db_row) + workers_to_matches[workers_idx].append(db_row) tar_ordering: List[str] = sorted([tar for tar in tar_to_size]) monitor: parallel.PrintMonitor = parallel.PrintMonitor(tar_ordering) @@ -444,8 +444,7 @@ def extractFiles( # noqa: C901 if multiprocess_worker: # All messages to the logger will now be sent to # this queue, instead of sys.stdout. - # error: Argument 1 to "StreamHandler" has incompatible type "PrintQueue"; expected "Optional[IO[str]]" - sh = logging.StreamHandler(multiprocess_worker.print_queue) # type: ignore + sh = logging.StreamHandler(multiprocess_worker.print_queue) sh.setLevel(logging.DEBUG) formatter: logging.Formatter = logging.Formatter("%(levelname)s: %(message)s") sh.setFormatter(formatter) @@ -539,8 +538,7 @@ def extractFiles( # noqa: C901 # error: Name 'tarfile.ExFileObject' is not defined extracted_file: Optional[tarfile.ExFileObject] = tar.extractfile(tarinfo) # type: ignore if extracted_file: - # error: Name 'tarfile.ExFileObject' is not defined - fin: tarfile.ExFileObject = extracted_file # type: ignore + fin: tarfile.ExFileObject = extracted_file else: raise TypeError("Invalid extracted_file={}".format(extracted_file)) try: diff --git a/zstash/hpss_utils.py b/zstash/hpss_utils.py index 717cfc6a..456e6a52 100644 --- a/zstash/hpss_utils.py +++ b/zstash/hpss_utils.py @@ -176,8 +176,7 @@ def add_file( tar: tarfile.TarFile, file_name: str, follow_symlinks: bool ) -> Tuple[int, int, datetime, Optional[str]]: - # FIXME: error: "TarFile" has no attribute "offset" - offset: int = tar.offset # type: ignore + offset: int = tar.offset tarinfo: tarfile.TarInfo = tar.gettarinfo(file_name) # Change the size of any hardlinks from 0 to the size of the actual file if tarinfo.islnk(): @@ -215,8 +214,7 @@ def add_file( fileobj.write(null_bytes * (tarfile.BLOCKSIZE - remainder)) blocks += 1 # Increase the offset by the amount already saved to the tar - # FIXME: error: "TarFile" has no attribute "offset" - tar.offset += blocks * tarfile.BLOCKSIZE # type: ignore + tar.offset += blocks * tarfile.BLOCKSIZE break f.close() md5 = hash_md5.hexdigest()