diff options
author | deshevoy <deshevoy@yandex-team.ru> | 2022-02-10 16:46:57 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:57 +0300 |
commit | 28148f76dbfcc644d96427d41c92f36cbf2fdc6e (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /contrib/python/pytest/py3/_pytest/config/findpaths.py | |
parent | e988f30484abe5fdeedcc7a5d3c226c01a21800c (diff) | |
download | ydb-28148f76dbfcc644d96427d41c92f36cbf2fdc6e.tar.gz |
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/config/findpaths.py')
-rw-r--r-- | contrib/python/pytest/py3/_pytest/config/findpaths.py | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/contrib/python/pytest/py3/_pytest/config/findpaths.py b/contrib/python/pytest/py3/_pytest/config/findpaths.py index 7eaa4e5c35..2edf54536b 100644 --- a/contrib/python/pytest/py3/_pytest/config/findpaths.py +++ b/contrib/python/pytest/py3/_pytest/config/findpaths.py @@ -1,4 +1,4 @@ -import os +import os from pathlib import Path from typing import Dict from typing import Iterable @@ -8,17 +8,17 @@ from typing import Sequence from typing import Tuple from typing import TYPE_CHECKING from typing import Union - + import iniconfig - -from .exceptions import UsageError + +from .exceptions import UsageError from _pytest.outcomes import fail from _pytest.pathlib import absolutepath from _pytest.pathlib import commonpath - + if TYPE_CHECKING: from . import Config - + def _parse_ini_config(path: Path) -> iniconfig.IniConfig: """Parse the given generic '.ini' file using legacy IniConfig parser, returning @@ -26,20 +26,20 @@ def _parse_ini_config(path: Path) -> iniconfig.IniConfig: Raise UsageError if the file cannot be parsed. """ - try: + try: return iniconfig.IniConfig(str(path)) except iniconfig.ParseError as exc: raise UsageError(str(exc)) from exc - - + + def load_config_dict_from_file( filepath: Path, ) -> Optional[Dict[str, Union[str, List[str]]]]: """Load pytest configuration from the given file path, if supported. Return None if the file does not contain valid pytest configuration. - """ - + """ + # Configuration from ini files are obtained from the [pytest] section, if present. if filepath.suffix == ".ini": iniconfig = _parse_ini_config(filepath) @@ -94,10 +94,10 @@ def locate_config( "tox.ini", "setup.cfg", ] - args = [x for x in args if not str(x).startswith("-")] - if not args: + args = [x for x in args if not str(x).startswith("-")] + if not args: args = [Path.cwd()] - for arg in args: + for arg in args: argpath = absolutepath(arg) for base in (argpath, *argpath.parents): for config_name in config_names: @@ -107,43 +107,43 @@ def locate_config( if ini_config is not None: return base, p, ini_config return None, None, {} - + def get_common_ancestor(paths: Iterable[Path]) -> Path: common_ancestor: Optional[Path] = None - for path in paths: - if not path.exists(): - continue - if common_ancestor is None: - common_ancestor = path - else: + for path in paths: + if not path.exists(): + continue + if common_ancestor is None: + common_ancestor = path + else: if common_ancestor in path.parents or path == common_ancestor: - continue + continue elif path in common_ancestor.parents: - common_ancestor = path - else: + common_ancestor = path + else: shared = commonpath(path, common_ancestor) - if shared is not None: - common_ancestor = shared - if common_ancestor is None: + if shared is not None: + common_ancestor = shared + if common_ancestor is None: common_ancestor = Path.cwd() elif common_ancestor.is_file(): common_ancestor = common_ancestor.parent - return common_ancestor - - + return common_ancestor + + def get_dirs_from_args(args: Iterable[str]) -> List[Path]: def is_option(x: str) -> bool: return x.startswith("-") - + def get_file_part_from_node_id(x: str) -> str: return x.split("::")[0] - + def get_dir_from_path(path: Path) -> Path: if path.is_dir(): - return path + return path return path.parent - + def safe_exists(path: Path) -> bool: # This can throw on paths that contain characters unrepresentable at the OS level, # or with invalid syntax on Windows (https://bugs.python.org/issue35306) @@ -152,16 +152,16 @@ def get_dirs_from_args(args: Iterable[str]) -> List[Path]: except OSError: return False - # These look like paths but may not exist - possible_paths = ( + # These look like paths but may not exist + possible_paths = ( absolutepath(get_file_part_from_node_id(arg)) - for arg in args - if not is_option(arg) - ) - + for arg in args + if not is_option(arg) + ) + return [get_dir_from_path(path) for path in possible_paths if safe_exists(path)] - - + + CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead." @@ -172,40 +172,40 @@ def determine_setup( config: Optional["Config"] = None, ) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]: rootdir = None - dirs = get_dirs_from_args(args) - if inifile: + dirs = get_dirs_from_args(args) + if inifile: inipath_ = absolutepath(inifile) inipath: Optional[Path] = inipath_ inicfg = load_config_dict_from_file(inipath_) or {} if rootdir_cmd_arg is None: rootdir = get_common_ancestor(dirs) - else: - ancestor = get_common_ancestor(dirs) + else: + ancestor = get_common_ancestor(dirs) rootdir, inipath, inicfg = locate_config([ancestor]) if rootdir is None and rootdir_cmd_arg is None: for possible_rootdir in (ancestor, *ancestor.parents): if (possible_rootdir / "setup.py").is_file(): rootdir = possible_rootdir - break - else: + break + else: if dirs != [ancestor]: rootdir, inipath, inicfg = locate_config(dirs) - if rootdir is None: + if rootdir is None: if config is not None: cwd = config.invocation_params.dir else: cwd = Path.cwd() rootdir = get_common_ancestor([cwd, ancestor]) - is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/" - if is_fs_root: - rootdir = ancestor - if rootdir_cmd_arg: + is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/" + if is_fs_root: + rootdir = ancestor + if rootdir_cmd_arg: rootdir = absolutepath(os.path.expandvars(rootdir_cmd_arg)) if not rootdir.is_dir(): - raise UsageError( - "Directory '{}' not found. Check your '--rootdir' option.".format( + raise UsageError( + "Directory '{}' not found. Check your '--rootdir' option.".format( rootdir - ) - ) + ) + ) assert rootdir is not None return rootdir, inipath, inicfg or {} |