-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and test loading project configuration
- Loading branch information
1 parent
8e75c7c
commit 41b9708
Showing
3 changed files
with
59 additions
and
2 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 |
---|---|---|
@@ -1,16 +1,47 @@ | ||
from os.path import exists, join | ||
|
||
import click | ||
import yaml | ||
|
||
CONFIG_FILE = '.changes' | ||
DEFAULTS = { | ||
'changelog': 'CHANGELOG.md', | ||
'readme': 'README.md', | ||
} | ||
|
||
|
||
class CLI(object): | ||
test_command = None | ||
pypi = None | ||
skip_changelog = None | ||
|
||
def __init__(self, module_name, dry_run, debug, no_input, requirements, new_version, current_version, repo_url, version_prefix): | ||
def __init__(self, module_name, dry_run, debug, no_input, requirements, | ||
new_version, current_version, repo_url, version_prefix): | ||
self.module_name = module_name | ||
self.dry_run = dry_run | ||
self.debug = debug | ||
self.no_input = no_input | ||
self.requirements = requirements | ||
self.new_version = version_prefix + new_version if version_prefix else new_version | ||
self.new_version = ( | ||
version_prefix + new_version | ||
if version_prefix | ||
else new_version | ||
) | ||
self.current_version = current_version | ||
self.repo_url = repo_url | ||
|
||
|
||
def project_config(context): | ||
config = {} | ||
config_path = join(context.module_name, CONFIG_FILE) | ||
|
||
# initialise config with defaults | ||
if not exists(config_path): | ||
config = DEFAULTS.copy() | ||
|
||
with click.open_file(config_path, 'w') as f: | ||
config_yaml = yaml.dump(config, default_flow_style=False) | ||
f.write(config_yaml) | ||
|
||
config = yaml.safe_load(click.open_file(config_path)) | ||
return config or {} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
PyYAML < 4.0.0 | ||
plumbum < 1.5.0 | ||
click < 2.6.0 | ||
path.py < 5.0.0 | ||
|
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,25 @@ | ||
from os.path import exists | ||
|
||
import click | ||
|
||
from changes import config | ||
from . import context, setup, teardown # noqa | ||
|
||
|
||
def test_no_config(): | ||
assert not exists('test_app/.changes') | ||
assert config.project_config(context) == config.DEFAULTS | ||
assert exists('test_app/.changes') | ||
|
||
|
||
def test_existing_config(): | ||
existing_config = 'foo: bar\nbaz: buzz\n' | ||
with click.open_file('test_app/.changes', 'w') as f: | ||
f.write(existing_config) | ||
assert config.project_config(context) == {'foo': 'bar', 'baz': 'buzz'} | ||
|
||
|
||
def test_malformed_config_returns_none(): | ||
with click.open_file('test_app/.changes', 'w') as f: | ||
f.write('something\n\n-another thing\n') | ||
assert config.project_config(context) == {} |