11"""Configuration functionality for vcspull."""
22
3+ from __future__ import annotations
4+
35import fnmatch
46import logging
57import os
68import pathlib
79import typing as t
8- from collections .abc import Callable
910
1011from libvcs .sync .git import GitRemote
1112
1819log = logging .getLogger (__name__ )
1920
2021if t .TYPE_CHECKING :
22+ from collections .abc import Callable
23+
2124 from typing_extensions import TypeGuard
2225
2326 from .types import ConfigDict , RawConfigDict
2427
2528
2629def expand_dir (
2730 dir_ : pathlib .Path ,
28- cwd : t . Union [ pathlib .Path , Callable [[], pathlib .Path ] ] = pathlib .Path .cwd ,
31+ cwd : pathlib .Path | Callable [[], pathlib .Path ] = pathlib .Path .cwd ,
2932) -> pathlib .Path :
3033 """Return path with environmental variables and tilde ~ expanded.
3134
@@ -52,9 +55,9 @@ def expand_dir(
5255
5356
5457def extract_repos (
55- config : " RawConfigDict" ,
56- cwd : t . Union [ pathlib .Path , Callable [[], pathlib .Path ] ] = pathlib .Path .cwd ,
57- ) -> list [" ConfigDict" ]:
58+ config : RawConfigDict ,
59+ cwd : pathlib .Path | Callable [[], pathlib .Path ] = pathlib .Path .cwd ,
60+ ) -> list [ConfigDict ]:
5861 """Return expanded configuration.
5962
6063 end-user configuration permit inline configuration shortcuts, expand to
@@ -130,7 +133,7 @@ def extract_repos(
130133 ** url ,
131134 )
132135
133- def is_valid_config_dict (val : t .Any ) -> " TypeGuard[ConfigDict]" :
136+ def is_valid_config_dict (val : t .Any ) -> TypeGuard [ConfigDict ]:
134137 assert isinstance (val , dict )
135138 return True
136139
@@ -142,7 +145,7 @@ def is_valid_config_dict(val: t.Any) -> "TypeGuard[ConfigDict]":
142145
143146
144147def find_home_config_files (
145- filetype : t . Optional [ list [str ]] = None ,
148+ filetype : list [str ] | None = None ,
146149) -> list [pathlib .Path ]:
147150 """Return configs of ``.vcspull.{yaml,json}`` in user's home directory."""
148151 if filetype is None :
@@ -172,11 +175,11 @@ def find_home_config_files(
172175
173176
174177def find_config_files (
175- path : t . Optional [ t . Union [ list [pathlib .Path ], pathlib .Path ]] = None ,
176- match : t . Optional [ t . Union [ list [str ], str ]] = None ,
177- filetype : t .Optional [
178- t . Union [ t . Literal [ "json" , "yaml" , "*" ], list [t .Literal ["json" , "yaml" , "*" ] ]]
179- ] = None ,
178+ path : list [pathlib .Path ] | pathlib .Path | None = None ,
179+ match : list [str ] | str | None = None ,
180+ filetype : t .Literal [ "json" , "yaml" , "*" ]
181+ | list [t .Literal ["json" , "yaml" , "*" ]]
182+ | None = None ,
180183 include_home : bool = False ,
181184) -> list [pathlib .Path ]:
182185 """Return repos from a directory and match. Not recursive.
@@ -234,8 +237,8 @@ def find_config_files(
234237
235238def load_configs (
236239 files : list [pathlib .Path ],
237- cwd : t . Union [ pathlib .Path , Callable [[], pathlib .Path ] ] = pathlib .Path .cwd ,
238- ) -> list [" ConfigDict" ]:
240+ cwd : pathlib .Path | Callable [[], pathlib .Path ] = pathlib .Path .cwd ,
241+ ) -> list [ConfigDict ]:
239242 """Return repos from a list of files.
240243
241244 Parameters
@@ -284,8 +287,8 @@ def load_configs(
284287
285288
286289def detect_duplicate_repos (
287- config1 : list [" ConfigDict" ],
288- config2 : list [" ConfigDict" ],
290+ config1 : list [ConfigDict ],
291+ config2 : list [ConfigDict ],
289292) -> list [ConfigDictTuple ]:
290293 """Return duplicate repos dict if repo_dir same and vcs different.
291294
@@ -320,8 +323,8 @@ def detect_duplicate_repos(
320323
321324
322325def in_dir (
323- config_dir : t . Optional [ pathlib .Path ] = None ,
324- extensions : t . Optional [ list [str ]] = None ,
326+ config_dir : pathlib .Path | None = None ,
327+ extensions : list [str ] | None = None ,
325328) -> list [str ]:
326329 """Return a list of configs in ``config_dir``.
327330
@@ -349,11 +352,11 @@ def in_dir(
349352
350353
351354def filter_repos (
352- config : list [" ConfigDict" ],
353- path : t . Union [ pathlib .Path , t .Literal ["*" ], str , None ] = None ,
354- vcs_url : t . Union [ str , None ] = None ,
355- name : t . Union [ str , None ] = None ,
356- ) -> list [" ConfigDict" ]:
355+ config : list [ConfigDict ],
356+ path : pathlib .Path | t .Literal ["*" ] | str | None = None ,
357+ vcs_url : str | None = None ,
358+ name : str | None = None ,
359+ ) -> list [ConfigDict ]:
357360 """Return a :py:obj:`list` list of repos from (expanded) config file.
358361
359362 path, vcs_url and name all support fnmatch.
@@ -402,7 +405,7 @@ def filter_repos(
402405
403406def is_config_file (
404407 filename : str ,
405- extensions : t . Optional [ t . Union [ list [str ], str ]] = None ,
408+ extensions : list [str ] | str | None = None ,
406409) -> bool :
407410 """Return True if file has a valid config file type.
408411
0 commit comments