diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2019-10-21 19:59:01 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2019-10-21 19:59:01 -0400 |
| commit | eb59201397e15d6de33b4aa741d04ae27da3317d (patch) | |
| tree | b0b47fcd9f7818ca723f7cdaaec63d983948ee66 | |
| parent | d1e6c60414f99aab601342f77f312599ebd4cd53 (diff) | |
| download | setuptools-scm-feature/declarative-config.tar.gz | |
Illustrate how reading the config from a file might operate.feature/declarative-config
| -rw-r--r-- | setup.py | 1 | ||||
| -rw-r--r-- | src/setuptools_scm/config.py | 8 | ||||
| -rw-r--r-- | testing/test_config.py | 7 |
3 files changed, 14 insertions, 2 deletions
@@ -113,6 +113,7 @@ arguments = dict( "Topic :: System :: Software Distribution", "Topic :: Utilities", ], + install_requires=["toml"], python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", ) diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py index e69d8fe..20e97b3 100644 --- a/src/setuptools_scm/config.py +++ b/src/setuptools_scm/config.py @@ -107,8 +107,12 @@ class Configuration(object): self._tag_regex = _check_tag_regex(value) @classmethod - def from_file(cls): + def from_file(cls, name='pyproject.toml'): """ Read Configuration from pyproject.toml (or similar) """ - # stubbed + with open(name) as strm: + defn = __import__('toml').load(strm) + config = cls() + vars(config).update(defn.get('setuptools_scm', {})) + return config diff --git a/testing/test_config.py b/testing/test_config.py index eadbaf3..742605e 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -18,3 +18,10 @@ def test_tag_regex(tag, expected_version): match = config.tag_regex.match(tag) version = match.group("version") assert version == expected_version + + +def test_config_from_pyproject(tmpdir): + fn = tmpdir / 'pyproject.toml' + fn.write_text('[setuptools_scm]\nenabled = true\n', encoding='utf-8') + config = Configuration.from_file(str(fn)) + assert config.enabled |
