mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-18 09:29:58 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,12 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import mimetypes
|
||||
import os
|
||||
import pathlib
|
||||
from typing import Callable, Iterable, Optional, Tuple
|
||||
from typing import Callable
|
||||
from typing import Iterable
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
from pip._internal.models.candidate import InstallationCandidate
|
||||
from pip._internal.models.link import Link
|
||||
from pip._internal.utils.urls import path_to_url, url_to_path
|
||||
from pip._internal.utils.urls import path_to_url
|
||||
from pip._internal.utils.urls import url_to_path
|
||||
from pip._internal.vcs import is_url
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -19,7 +25,7 @@ PageValidator = Callable[[Link], bool]
|
|||
|
||||
class LinkSource:
|
||||
@property
|
||||
def link(self) -> Optional[Link]:
|
||||
def link(self) -> Link | None:
|
||||
"""Returns the underlying link, if there's one."""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
@ -33,7 +39,7 @@ class LinkSource:
|
|||
|
||||
|
||||
def _is_html_file(file_url: str) -> bool:
|
||||
return mimetypes.guess_type(file_url, strict=False)[0] == "text/html"
|
||||
return mimetypes.guess_type(file_url, strict=False)[0] == 'text/html'
|
||||
|
||||
|
||||
class _FlatDirectorySource(LinkSource):
|
||||
|
|
@ -54,7 +60,7 @@ class _FlatDirectorySource(LinkSource):
|
|||
self._path = pathlib.Path(os.path.realpath(path))
|
||||
|
||||
@property
|
||||
def link(self) -> Optional[Link]:
|
||||
def link(self) -> Link | None:
|
||||
return None
|
||||
|
||||
def page_candidates(self) -> FoundCandidates:
|
||||
|
|
@ -91,7 +97,7 @@ class _LocalFileSource(LinkSource):
|
|||
self._link = link
|
||||
|
||||
@property
|
||||
def link(self) -> Optional[Link]:
|
||||
def link(self) -> Link | None:
|
||||
return self._link
|
||||
|
||||
def page_candidates(self) -> FoundCandidates:
|
||||
|
|
@ -125,7 +131,7 @@ class _RemoteFileSource(LinkSource):
|
|||
self._link = link
|
||||
|
||||
@property
|
||||
def link(self) -> Optional[Link]:
|
||||
def link(self) -> Link | None:
|
||||
return self._link
|
||||
|
||||
def page_candidates(self) -> FoundCandidates:
|
||||
|
|
@ -153,7 +159,7 @@ class _IndexDirectorySource(LinkSource):
|
|||
self._link = link
|
||||
|
||||
@property
|
||||
def link(self) -> Optional[Link]:
|
||||
def link(self) -> Link | None:
|
||||
return self._link
|
||||
|
||||
def page_candidates(self) -> FoundCandidates:
|
||||
|
|
@ -170,14 +176,14 @@ def build_source(
|
|||
page_validator: PageValidator,
|
||||
expand_dir: bool,
|
||||
cache_link_parsing: bool,
|
||||
) -> Tuple[Optional[str], Optional[LinkSource]]:
|
||||
) -> tuple[str | None, LinkSource | None]:
|
||||
|
||||
path: Optional[str] = None
|
||||
url: Optional[str] = None
|
||||
path: str | None = None
|
||||
url: str | None = None
|
||||
if os.path.exists(location): # Is a local path.
|
||||
url = path_to_url(location)
|
||||
path = location
|
||||
elif location.startswith("file:"): # A file: URL.
|
||||
elif location.startswith('file:'): # A file: URL.
|
||||
url = location
|
||||
path = url_to_path(location)
|
||||
elif is_url(location):
|
||||
|
|
@ -186,7 +192,7 @@ def build_source(
|
|||
if url is None:
|
||||
msg = (
|
||||
"Location '%s' is ignored: "
|
||||
"it is either a non-existing path or lacks a specific scheme."
|
||||
'it is either a non-existing path or lacks a specific scheme.'
|
||||
)
|
||||
logger.warning(msg, location)
|
||||
return (None, None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue