Skip to content

Commit

Permalink
chore(ruff) Automated fixes for typing annotations
Browse files Browse the repository at this point in the history
Fixed 134 errors:
- conftest.py:
     1 × TC003 (typing-only-standard-library-import)
     1 × I002 (missing-required-import)
- docs/conf.py:
     2 × UP037 (quoted-annotation)
     1 × I002 (missing-required-import)
     1 × I001 (unsorted-imports)
     1 × UP007 (non-pep604-annotation)
- scripts/generate_gitlab.py:
     1 × I001 (unsorted-imports)
     1 × TC001 (typing-only-first-party-import)
     1 × I002 (missing-required-import)
- src/vcspull/__about__.py:
     1 × I002 (missing-required-import)
- src/vcspull/__init__.py:
     1 × I001 (unsorted-imports)
     1 × I002 (missing-required-import)
- src/vcspull/_internal/config_reader.py:
     8 × UP037 (quoted-annotation)
     1 × I001 (unsorted-imports)
     1 × I002 (missing-required-import)
- src/vcspull/cli/__init__.py:
     2 × UP007 (non-pep604-annotation)
     1 × I002 (missing-required-import)
- src/vcspull/cli/sync.py:
     3 × TC003 (typing-only-standard-library-import)
     2 × UP007 (non-pep604-annotation)
     2 × TC002 (typing-only-third-party-import)
     1 × I002 (missing-required-import)
     1 × I001 (unsorted-imports)
- src/vcspull/config.py:
    17 × UP007 (non-pep604-annotation)
     8 × UP037 (quoted-annotation)
     1 × I002 (missing-required-import)
     1 × TC003 (typing-only-standard-library-import)
     1 × I001 (unsorted-imports)
- src/vcspull/exc.py:
     1 × I002 (missing-required-import)
- src/vcspull/log.py:
     1 × UP007 (non-pep604-annotation)
     1 × I002 (missing-required-import)
- src/vcspull/types.py:
     3 × UP007 (non-pep604-annotation)
     3 × TC002 (typing-only-third-party-import)
     1 × TC003 (typing-only-standard-library-import)
     1 × I002 (missing-required-import)
     1 × I001 (unsorted-imports)
- src/vcspull/util.py:
     1 × I002 (missing-required-import)
- src/vcspull/validator.py:
     1 × I002 (missing-required-import)
     1 × UP037 (quoted-annotation)
- tests/__init__.py:
     1 × I002 (missing-required-import)
- tests/fixtures/example.py:
     1 × I002 (missing-required-import)
     1 × UP037 (quoted-annotation)
- tests/helpers.py:
     1 × UP037 (quoted-annotation)
     1 × TC003 (typing-only-standard-library-import)
     1 × I002 (missing-required-import)
     1 × I001 (unsorted-imports)
     1 × PYI034 (non-self-return-type)
- tests/test_cli.py:
    24 × UP037 (quoted-annotation)
     1 × TC003 (typing-only-standard-library-import)
     1 × I002 (missing-required-import)
     1 × TC002 (typing-only-third-party-import)
     1 × I001 (unsorted-imports)
- tests/test_config.py:
     2 × UP037 (quoted-annotation)
     1 × I002 (missing-required-import)
     1 × UP007 (non-pep604-annotation)
     1 × TC003 (typing-only-standard-library-import)
     1 × I001 (unsorted-imports)
- tests/test_config_file.py:
     1 × I002 (missing-required-import)
- tests/test_repo.py:
     1 × I001 (unsorted-imports)
     1 × TC003 (typing-only-standard-library-import)
     1 × I002 (missing-required-import)
- tests/test_sync.py:
     1 × I002 (missing-required-import)
     1 × TC003 (typing-only-standard-library-import)
     1 × TC002 (typing-only-third-party-import)
     1 × I001 (unsorted-imports)
- tests/test_utils.py:
     3 × I001 (unsorted-imports)
     1 × TC003 (typing-only-standard-library-import)
     1 × I002 (missing-required-import)
     1 × TC002 (typing-only-third-party-import)

Found 460 errors (134 fixed, 326 remaining).
20 files reformatted, 5 files left unchanged

uv run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; uv run ruff format .
  • Loading branch information
tony committed Jan 4, 2025
1 parent 7e6bafa commit 6ff3763
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 92 deletions.
6 changes: 5 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
https://docs.pytest.org/en/stable/deprecations.html
"""

import pathlib
from __future__ import annotations

import shutil
import typing as t

import pytest

if t.TYPE_CHECKING:
import pathlib


@pytest.fixture(autouse=True)
def add_doctest_fixtures(
Expand Down
8 changes: 5 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Sphinx configuration for vcspull documentation."""

# flake8: noqa: E501
from __future__ import annotations

import inspect
import pathlib
import sys
Expand Down Expand Up @@ -146,7 +148,7 @@
}


def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
def linkcode_resolve(domain: str, info: dict[str, str]) -> None | str:
"""
Determine the URL corresponding to Python object.
Expand Down Expand Up @@ -216,13 +218,13 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
)


def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:
def remove_tabs_js(app: Sphinx, exc: Exception) -> None:
"""Fix for sphinx-inline-tabs#18."""
if app.builder.format == "html" and not exc:
tabs_js = pathlib.Path(app.builder.outdir) / "_static" / "tabs.js"
tabs_js.unlink(missing_ok=True)


def setup(app: "Sphinx") -> None:
def setup(app: Sphinx) -> None:
"""Sphinx setup hook."""
app.connect("build-finished", remove_tabs_js)
7 changes: 6 additions & 1 deletion scripts/generate_gitlab.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/usr/bin/env python
"""Example script for export gitlab organization to vcspull config file."""

from __future__ import annotations

import argparse
import logging
import os
import pathlib
import sys
from typing import TYPE_CHECKING

import requests
import yaml
from libvcs.sync.git import GitRemote

from vcspull.cli.sync import CouldNotGuessVCSFromURL, guess_vcs
from vcspull.types import RawConfig

if TYPE_CHECKING:
from vcspull.types import RawConfig

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format="%(message)s")
Expand Down
2 changes: 2 additions & 0 deletions src/vcspull/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Metadata for vcspull."""

from __future__ import annotations

__title__ = "vcspull"
__package_name__ = "vcspull"
__description__ = "Manage and sync multiple git, mercurial, and svn repos"
Expand Down
2 changes: 2 additions & 0 deletions src/vcspull/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

# Set default logging handler to avoid "No handler found" warnings.
from __future__ import annotations

import logging
from logging import NullHandler

Expand Down
16 changes: 9 additions & 7 deletions src/vcspull/_internal/config_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import pathlib
import typing as t
Expand All @@ -22,11 +24,11 @@ class ConfigReader:
'{\n "session_name": "my session"\n}'
"""

def __init__(self, content: "RawConfigData") -> None:
def __init__(self, content: RawConfigData) -> None:
self.content = content

@staticmethod
def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]:
def _load(fmt: FormatLiteral, content: str) -> dict[str, t.Any]:
"""Load raw config data and directly return it.
>>> ConfigReader._load("json", '{ "session_name": "my session" }')
Expand All @@ -49,7 +51,7 @@ def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]:
raise NotImplementedError(msg)

@classmethod
def load(cls, fmt: "FormatLiteral", content: str) -> "ConfigReader":
def load(cls, fmt: FormatLiteral, content: str) -> ConfigReader:
"""Load raw config data into a ConfigReader instance (to dump later).
>>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
Expand Down Expand Up @@ -118,7 +120,7 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
)

@classmethod
def from_file(cls, path: pathlib.Path) -> "ConfigReader":
def from_file(cls, path: pathlib.Path) -> ConfigReader:
r"""Load data from file path.
**YAML file**
Expand Down Expand Up @@ -159,8 +161,8 @@ def from_file(cls, path: pathlib.Path) -> "ConfigReader":

@staticmethod
def _dump(
fmt: "FormatLiteral",
content: "RawConfigData",
fmt: FormatLiteral,
content: RawConfigData,
indent: int = 2,
**kwargs: t.Any,
) -> str:
Expand All @@ -187,7 +189,7 @@ def _dump(
msg = f"{fmt} not supported in config"
raise NotImplementedError(msg)

def dump(self, fmt: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
def dump(self, fmt: FormatLiteral, indent: int = 2, **kwargs: t.Any) -> str:
r"""Dump via ConfigReader instance.
>>> cfg = ConfigReader({ "session_name": "my session" })
Expand Down
6 changes: 4 additions & 2 deletions src/vcspull/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""CLI utilities for vcspull."""

from __future__ import annotations

import argparse
import logging
import textwrap
Expand Down Expand Up @@ -41,7 +43,7 @@ def create_parser(return_subparsers: t.Literal[False]) -> argparse.ArgumentParse

def create_parser(
return_subparsers: bool = False,
) -> t.Union[argparse.ArgumentParser, tuple[argparse.ArgumentParser, t.Any]]:
) -> argparse.ArgumentParser | tuple[argparse.ArgumentParser, t.Any]:
"""Create CLI argument parser for vcspull."""
parser = argparse.ArgumentParser(
prog="vcspull",
Expand Down Expand Up @@ -76,7 +78,7 @@ def create_parser(
return parser


def cli(_args: t.Optional[list[str]] = None) -> None:
def cli(_args: list[str] | None = None) -> None:
"""CLI entry point for vcspull."""
parser, sync_parser = create_parser(return_subparsers=True)
args = parser.parse_args(_args)
Expand Down
22 changes: 13 additions & 9 deletions src/vcspull/cli/sync.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
"""Synchronization functionality for vcspull."""

import argparse
from __future__ import annotations

import logging
import pathlib
import sys
import typing as t
from copy import deepcopy
from datetime import datetime

from libvcs._internal.shortcuts import create_project
from libvcs._internal.types import VCSLiteral
from libvcs.sync.git import GitSync
from libvcs.url import registry as url_tools

from vcspull import exc
from vcspull.config import filter_repos, find_config_files, load_configs

if t.TYPE_CHECKING:
import argparse
import pathlib
from datetime import datetime

from libvcs._internal.types import VCSLiteral
from libvcs.sync.git import GitSync

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -63,9 +68,8 @@ def sync(
repo_patterns: list[str],
config: pathlib.Path,
exit_on_error: bool,
parser: t.Optional[
argparse.ArgumentParser
] = None, # optional so sync can be unit tested
parser: argparse.ArgumentParser
| None = None, # optional so sync can be unit tested
) -> None:
"""Entry point for ``vcspull sync``."""
if isinstance(repo_patterns, list) and len(repo_patterns) == 0:
Expand Down Expand Up @@ -117,7 +121,7 @@ def progress_cb(output: str, timestamp: datetime) -> None:
sys.stdout.flush()


def guess_vcs(url: str) -> t.Optional[VCSLiteral]:
def guess_vcs(url: str) -> VCSLiteral | None:
"""Guess the VCS from a URL."""
vcs_matches = url_tools.registry.match(url=url, is_explicit=True)

Expand Down
51 changes: 27 additions & 24 deletions src/vcspull/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Configuration functionality for vcspull."""

from __future__ import annotations

import fnmatch
import logging
import os
import pathlib
import typing as t
from collections.abc import Callable

from libvcs.sync.git import GitRemote

Expand All @@ -18,14 +19,16 @@
log = logging.getLogger(__name__)

if t.TYPE_CHECKING:
from collections.abc import Callable

from typing_extensions import TypeGuard

from .types import ConfigDict, RawConfigDict


def expand_dir(
dir_: pathlib.Path,
cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd,
cwd: pathlib.Path | Callable[[], pathlib.Path] = pathlib.Path.cwd,
) -> pathlib.Path:
"""Return path with environmental variables and tilde ~ expanded.
Expand All @@ -52,9 +55,9 @@ def expand_dir(


def extract_repos(
config: "RawConfigDict",
cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd,
) -> list["ConfigDict"]:
config: RawConfigDict,
cwd: pathlib.Path | Callable[[], pathlib.Path] = pathlib.Path.cwd,
) -> list[ConfigDict]:
"""Return expanded configuration.
end-user configuration permit inline configuration shortcuts, expand to
Expand Down Expand Up @@ -130,7 +133,7 @@ def extract_repos(
**url,
)

def is_valid_config_dict(val: t.Any) -> "TypeGuard[ConfigDict]":
def is_valid_config_dict(val: t.Any) -> TypeGuard[ConfigDict]:
assert isinstance(val, dict)
return True

Expand All @@ -142,7 +145,7 @@ def is_valid_config_dict(val: t.Any) -> "TypeGuard[ConfigDict]":


def find_home_config_files(
filetype: t.Optional[list[str]] = None,
filetype: list[str] | None = None,
) -> list[pathlib.Path]:
"""Return configs of ``.vcspull.{yaml,json}`` in user's home directory."""
if filetype is None:
Expand Down Expand Up @@ -172,11 +175,11 @@ def find_home_config_files(


def find_config_files(
path: t.Optional[t.Union[list[pathlib.Path], pathlib.Path]] = None,
match: t.Optional[t.Union[list[str], str]] = None,
filetype: t.Optional[
t.Union[t.Literal["json", "yaml", "*"], list[t.Literal["json", "yaml", "*"]]]
] = None,
path: list[pathlib.Path] | pathlib.Path | None = None,
match: list[str] | str | None = None,
filetype: t.Literal["json", "yaml", "*"]
| list[t.Literal["json", "yaml", "*"]]
| None = None,
include_home: bool = False,
) -> list[pathlib.Path]:
"""Return repos from a directory and match. Not recursive.
Expand Down Expand Up @@ -234,8 +237,8 @@ def find_config_files(

def load_configs(
files: list[pathlib.Path],
cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd,
) -> list["ConfigDict"]:
cwd: pathlib.Path | Callable[[], pathlib.Path] = pathlib.Path.cwd,
) -> list[ConfigDict]:
"""Return repos from a list of files.
Parameters
Expand Down Expand Up @@ -284,8 +287,8 @@ def load_configs(


def detect_duplicate_repos(
config1: list["ConfigDict"],
config2: list["ConfigDict"],
config1: list[ConfigDict],
config2: list[ConfigDict],
) -> list[ConfigDictTuple]:
"""Return duplicate repos dict if repo_dir same and vcs different.
Expand Down Expand Up @@ -320,8 +323,8 @@ def detect_duplicate_repos(


def in_dir(
config_dir: t.Optional[pathlib.Path] = None,
extensions: t.Optional[list[str]] = None,
config_dir: pathlib.Path | None = None,
extensions: list[str] | None = None,
) -> list[str]:
"""Return a list of configs in ``config_dir``.
Expand Down Expand Up @@ -349,11 +352,11 @@ def in_dir(


def filter_repos(
config: list["ConfigDict"],
path: t.Union[pathlib.Path, t.Literal["*"], str, None] = None,
vcs_url: t.Union[str, None] = None,
name: t.Union[str, None] = None,
) -> list["ConfigDict"]:
config: list[ConfigDict],
path: pathlib.Path | t.Literal["*"] | str | None = None,
vcs_url: str | None = None,
name: str | None = None,
) -> list[ConfigDict]:
"""Return a :py:obj:`list` list of repos from (expanded) config file.
path, vcs_url and name all support fnmatch.
Expand Down Expand Up @@ -402,7 +405,7 @@ def filter_repos(

def is_config_file(
filename: str,
extensions: t.Optional[t.Union[list[str], str]] = None,
extensions: list[str] | str | None = None,
) -> bool:
"""Return True if file has a valid config file type.
Expand Down
2 changes: 2 additions & 0 deletions src/vcspull/exc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Exceptions for vcspull."""

from __future__ import annotations


class VCSPullException(Exception):
"""Standard exception raised by vcspull."""
Expand Down
4 changes: 3 additions & 1 deletion src/vcspull/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
provided.
"""

from __future__ import annotations

import logging
import time
import typing as t
Expand All @@ -23,7 +25,7 @@


def setup_logger(
log: t.Optional[logging.Logger] = None,
log: logging.Logger | None = None,
level: t.Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO",
) -> None:
"""Configure vcspull logger for CLI use.
Expand Down
Loading

0 comments on commit 6ff3763

Please sign in to comment.