Load settings from a file.
(cls, settings_path: Path | None = None)
| 91 | |
| 92 | @classmethod |
| 93 | def from_file(cls, settings_path: Path | None = None) -> SettingsModel: |
| 94 | """Load settings from a file.""" |
| 95 | env_path = os.getenv(_ENV_VAR) |
| 96 | if settings_path is None: |
| 97 | if env_path: |
| 98 | settings_path = Path(env_path) |
| 99 | else: |
| 100 | settings_path = cls._default_settings_path() |
| 101 | |
| 102 | # NOTE: Remove after a sufficiently long deprecation period. |
| 103 | if OS == "windows": |
| 104 | old_settings_path = user_config_path("copier") / "settings.yml" |
| 105 | if old_settings_path.is_file(): |
| 106 | warnings.warn( |
| 107 | f"Settings path {old_settings_path} is deprecated. " |
| 108 | f"Please migrate to {settings_path}.", |
| 109 | DeprecationWarning, |
| 110 | stacklevel=2, |
| 111 | ) |
| 112 | settings_path = old_settings_path |
| 113 | if settings_path.is_file(): |
| 114 | data = yaml.safe_load(settings_path.read_bytes()) |
| 115 | return cls.model_validate(data) |
| 116 | elif env_path: |
| 117 | warnings.warn( |
| 118 | f"Settings file not found at {env_path}", MissingSettingsWarning |
| 119 | ) |
| 120 | return cls() |
| 121 | |
| 122 | def is_trusted(self, repository: str) -> bool: |
| 123 | """Check if a repository is trusted.""" |