-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add project specific configuration via local or remote `pyproject.tom…
…l` (#30) * Add rudimentary format configuration via pyproject.toml The idea is to have three sources of configuration, in order of priority: - Local TOML file specified with --config option - Remote pyproject.toml at the last given revision - Default configuration in _config.py * Move default configuration into TOML file * Add missing newline to intro_template * Add documentation to configuration options * Use scientific-python/changelist as example * Document configuration options in README and tweak or extend other sections accordingly. * List features in README and also hint that changelist is not intended to replace the human part in documenting a release.
- Loading branch information
Showing
6 changed files
with
244 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include src/changelist/*.toml |
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
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,49 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
from github import Github, UnknownObjectException | ||
|
||
try: | ||
import tomllib | ||
except ModuleNotFoundError: | ||
import tomli as tomllib | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
here = Path(__file__) | ||
|
||
|
||
DEFAULT_CONFIG_PATH = here.parent / "default_config.toml" | ||
|
||
|
||
def remote_config(gh: Github, org_repo: str, *, rev: str): | ||
repo = gh.get_repo(org_repo) | ||
try: | ||
file = repo.get_contents("pyproject.toml", ref=rev) | ||
logger.debug("found pyproject.toml in %s@%s", org_repo, rev) | ||
content = file.decoded_content.decode() | ||
except UnknownObjectException: | ||
content = "" | ||
config = tomllib.loads(content) | ||
config = config.get("tool", {}).get("changelist", {}) | ||
return config | ||
|
||
|
||
def local_config(path: Path) -> dict: | ||
with path.open("rb") as fp: | ||
config = tomllib.load(fp) | ||
config = config.get("tool", {}).get("changelist", {}) | ||
return config | ||
|
||
|
||
def add_config_defaults( | ||
config: dict, *, default_config_path: Path = DEFAULT_CONFIG_PATH | ||
) -> dict: | ||
with default_config_path.open("rb") as fp: | ||
defaults = tomllib.load(fp) | ||
defaults = defaults["tool"]["changelist"] | ||
for key, value in defaults.items(): | ||
if key not in config: | ||
config[key] = value | ||
logger.debug("using default config value for %s", key) | ||
return config |
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.