| 168 | |
| 169 | |
| 170 | def 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 {} |