Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Add support for setup.cfg
Browse files Browse the repository at this point in the history
Merge pull request #2 from maukoquiroga/add-setup-config
  • Loading branch information
Mauko Quiroga authored Oct 27, 2021
2 parents bf99482 + 4db3c46 commit 46b0b29
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mantic"
version = "1.1.4"
version = "1.1.5"
description = "Command-line tools to facilitate se-mantic versioning."
license = "EUPL-1.2-or-later"
authors = ["Mauko Quiroga <[email protected]>"]
Expand Down
21 changes: 18 additions & 3 deletions src/mantic_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
"""Configuration options.
For now, configuration options will be read from any valid ``pyproject.toml``
file.
or ``setup.cfg`` file.
For example::
[tool.mantic]
exclude = [".editorconfig", ".gitignore", "tests"]
.. versionchanged:: 1.2.0
.. versionadded:: 1.0.0
"""

from typing import Any, MutableMapping, Sequence, Type

from configparser import ConfigParser
from pathlib import Path

import deal
import toml
import typic
Expand All @@ -35,9 +40,19 @@ class Config:
def build_config(config: Type[Config]) -> Config:
"""Builds the configuration."""

from_toml: MutableMapping[str, Any] = toml.load("pyproject.toml")
from_file: MutableMapping[str, Any]

if Path("pyproject.toml").exists():
from_file = toml.load("pyproject.toml")
return config.transmute(from_file["tool"]["mantic"])

if Path("setup.cfg").exists():
parser = ConfigParser()
parser.read("setup.cfg")
from_file = {"ignore": parser["tool:mantic"]["ignore"].split()}
return config.transmute(from_file)

return config.transmute(from_toml["tool"]["mantic"])
raise NotImplementedError


config = build_config(Config)

0 comments on commit 46b0b29

Please sign in to comment.