MCPcopy Create free account
hub / github.com/pytest-dev/pytest / determine_setup

Function determine_setup

src/_pytest/config/findpaths.py:170–213  ·  view source on GitHub ↗
(
    inifile: Optional[str],
    args: Sequence[str],
    rootdir_cmd_arg: Optional[str] = None,
    config: Optional["Config"] = None,
)

Source from the content-addressed store, hash-verified

168
169
170def determine_setup(
171 inifile: Optional[str],
172 args: Sequence[str],
173 rootdir_cmd_arg: Optional[str] = None,
174 config: Optional["Config"] = None,
175) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]:
176 rootdir = None
177 dirs = get_dirs_from_args(args)
178 if inifile:
179 inipath_ = absolutepath(inifile)
180 inipath: Optional[Path] = inipath_
181 inicfg = load_config_dict_from_file(inipath_) or {}
182 if rootdir_cmd_arg is None:
183 rootdir = inipath_.parent
184 else:
185 ancestor = get_common_ancestor(dirs)
186 rootdir, inipath, inicfg = locate_config([ancestor])
187 if rootdir is None and rootdir_cmd_arg is None:
188 for possible_rootdir in (ancestor, *ancestor.parents):
189 if (possible_rootdir / "setup.py").is_file():
190 rootdir = possible_rootdir
191 break
192 else:
193 if dirs != [ancestor]:
194 rootdir, inipath, inicfg = locate_config(dirs)
195 if rootdir is None:
196 if config is not None:
197 cwd = config.invocation_params.dir
198 else:
199 cwd = Path.cwd()
200 rootdir = get_common_ancestor([cwd, ancestor])
201 is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/"
202 if is_fs_root:
203 rootdir = ancestor
204 if rootdir_cmd_arg:
205 rootdir = absolutepath(os.path.expandvars(rootdir_cmd_arg))
206 if not rootdir.is_dir():
207 raise UsageError(
208 "Directory '{}' not found. Check your '--rootdir' option.".format(
209 rootdir
210 )
211 )
212 assert rootdir is not None
213 return rootdir, inipath, inicfg or {}

Calls 7

absolutepathFunction · 0.90
get_dirs_from_argsFunction · 0.85
get_common_ancestorFunction · 0.85
locate_configFunction · 0.85
UsageErrorClass · 0.85
formatMethod · 0.45