-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…235)
- Loading branch information
1 parent
557c0d6
commit 638f131
Showing
11 changed files
with
371 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""User setttings models and helper functions.""" | ||
from __future__ import annotations | ||
|
||
import os | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import yaml | ||
from platformdirs import user_config_path | ||
from pydantic import BaseModel, Field | ||
|
||
ENV_VAR = "COPIER_SETTINGS_PATH" | ||
|
||
|
||
class Settings(BaseModel): | ||
"""User settings model.""" | ||
|
||
defaults: dict[str, Any] = Field(default_factory=dict) | ||
|
||
@classmethod | ||
def from_file(cls, settings_path: Path | None = None) -> Settings: | ||
"""Load settings from a file.""" | ||
if settings_path is None: | ||
if env_path := os.getenv(ENV_VAR): | ||
settings_path = Path(env_path) | ||
else: | ||
settings_path = user_config_path("copier") / "settings.yml" | ||
if settings_path.is_file(): | ||
data = yaml.safe_load(settings_path.read_text()) | ||
return cls.model_validate(data) | ||
return cls() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: copier.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Settings | ||
|
||
Copier settings are stored in `<CONFIG_ROOT>/settings.yml` where `<CONFIG_ROOT>` is the | ||
standard configuration directory for your platform: | ||
|
||
- `$XDG_CONFIG_HOME/copier` (`~/.config/copier ` in most cases) on Linux as defined by | ||
[XDG Base Directory Specifications](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) | ||
- `~/Library/Application Support/copier` on macOS as defined by | ||
[Apple File System Basics](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html) | ||
- `%USERPROFILE%\AppData\Local\copier` on Windows as defined in | ||
[Known folders](https://docs.microsoft.com/en-us/windows/win32/shell/known-folders) | ||
|
||
This location can be overridden by setting the `COPIER_SETTINGS_PATH` environment | ||
variable. | ||
|
||
## User defaults | ||
|
||
Users may define some reusable default variables in the `defaults` section of the | ||
configuration file. | ||
|
||
```yaml title="$COPIER_HOME/settings.yml" | ||
defaults: | ||
user_name: "John Doe" | ||
user_email: [email protected] | ||
``` | ||
This user data will replace the default value of fields of the same name. | ||
### Well-known variables | ||
To ensure templates efficiently reuse user-defined variables, we invite template authors | ||
to use the following well-known variables: | ||
| Variable name | Type | Description | | ||
| ------------- | ----- | ---------------------- | | ||
| `user_name` | `str` | User's full name | | ||
| `user_email` | `str` | User's email address | | ||
| `github_user` | `str` | User's GitHub username | | ||
| `gitlab_user` | `str` | User's GitLab username | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.