def apply_env_config(
        self,
        envfile: str | list[str] | None,
        config_env: Mapping[str, str | Mapping[str, str]] | None,
        config_dir: Path,
        config_working_dir: Path,
    ):
        """
        Used for including env vars from global or task config.
        If a value is provided as a mapping from `"default"` to `str` then it is only
        used if the associated key doesn't already have a value.
        """

        scoped_env = self.clone()
        scoped_env.set("POE_CONF_DIR", str(config_dir))

        if envfile:
            if isinstance(envfile, str):
                envfile = [envfile]
            for envfile_path in envfile:
                self.update(
                    self.envfiles.get(
                        config_working_dir.joinpath(
                            apply_envvars_to_template(
                                envfile_path, scoped_env, require_braces=True
                            )
                        )
                    )
                )

        scoped_env = self.clone()
        scoped_env.set("POE_CONF_DIR", str(config_dir))

        for key, value in (config_env or {}).items():
            if isinstance(value, str):
                value_str = value
            elif key not in scoped_env:
                value_str = value["default"]
            else:
                continue

            self._vars[key] = apply_envvars_to_template(
                value_str, scoped_env, require_braces=True
            )
            scoped_env.set(key, self._vars[key])

        Used for including env vars from global or task config.
        If a value is provided as a mapping from `"default"` to `str` then it is only
        used if the associated key doesn't already have a value.
        
poethepoet/env/manager.py