Determine the rootdir, inifile and ini configuration values from the command line arguments. :param inifile: The `--inifile` command line argument, if given. :param override_ini: The -o/--override-ini command line arguments, if given. :param args: The free co
(
*,
inifile: str | None,
override_ini: Sequence[str] | None,
args: Sequence[str],
rootdir_cmd_arg: str | None,
invocation_dir: Path,
)
| 276 | |
| 277 | |
| 278 | def determine_setup( |
| 279 | *, |
| 280 | inifile: str | None, |
| 281 | override_ini: Sequence[str] | None, |
| 282 | args: Sequence[str], |
| 283 | rootdir_cmd_arg: str | None, |
| 284 | invocation_dir: Path, |
| 285 | ) -> tuple[Path, Path | None, ConfigDict, Sequence[str]]: |
| 286 | """Determine the rootdir, inifile and ini configuration values from the |
| 287 | command line arguments. |
| 288 | |
| 289 | :param inifile: |
| 290 | The `--inifile` command line argument, if given. |
| 291 | :param override_ini: |
| 292 | The -o/--override-ini command line arguments, if given. |
| 293 | :param args: |
| 294 | The free command line arguments. |
| 295 | :param rootdir_cmd_arg: |
| 296 | The `--rootdir` command line argument, if given. |
| 297 | :param invocation_dir: |
| 298 | The working directory when pytest was invoked. |
| 299 | |
| 300 | :raises UsageError: |
| 301 | """ |
| 302 | rootdir = None |
| 303 | dirs = get_dirs_from_args(args) |
| 304 | ignored_config_files: Sequence[str] = [] |
| 305 | |
| 306 | if inifile: |
| 307 | inipath_ = absolutepath(inifile) |
| 308 | inipath: Path | None = inipath_ |
| 309 | inicfg = load_config_dict_from_file(inipath_) or {} |
| 310 | if rootdir_cmd_arg is None: |
| 311 | rootdir = inipath_.parent |
| 312 | else: |
| 313 | ancestor = get_common_ancestor(invocation_dir, dirs) |
| 314 | rootdir, inipath, inicfg, ignored_config_files = locate_config( |
| 315 | invocation_dir, [ancestor] |
| 316 | ) |
| 317 | if rootdir is None and rootdir_cmd_arg is None: |
| 318 | for possible_rootdir in (ancestor, *ancestor.parents): |
| 319 | if (possible_rootdir / "setup.py").is_file(): |
| 320 | rootdir = possible_rootdir |
| 321 | break |
| 322 | else: |
| 323 | if dirs != [ancestor]: |
| 324 | rootdir, inipath, inicfg, _ = locate_config(invocation_dir, dirs) |
| 325 | if rootdir is None: |
| 326 | rootdir = get_common_ancestor( |
| 327 | invocation_dir, [invocation_dir, ancestor] |
| 328 | ) |
| 329 | if is_fs_root(rootdir): |
| 330 | rootdir = ancestor |
| 331 | if rootdir_cmd_arg: |
| 332 | rootdir = absolutepath(os.path.expandvars(rootdir_cmd_arg)) |
| 333 | if not rootdir.is_dir(): |
| 334 | raise UsageError( |
| 335 | f"Directory '{rootdir}' not found. Check your '--rootdir' option." |