Skip to content

Commit ef6781b

Browse files
authored
✨ Override moban file in fs url format (#347)
* ✨ support override file url * 📚 update configuration * 👕 style conf.py * 🔬 initial unit tests * 👕 update coding style * 👕 update coding style * 🔬 fix test cases * 🥚 🎡 release 0.6.6
1 parent 4563c01 commit ef6781b

File tree

12 files changed

+45
-15
lines changed

12 files changed

+45
-15
lines changed

.moban.cd/moban.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contact: [email protected]
66
license: MIT
77
version: 0.6.6
88
current_version: 0.6.6
9-
release: 0.6.5
9+
release: 0.6.6
1010
branch: master
1111
master: index
1212
command_line_interface: "moban"

.moban.d/custom_conf.py.jj2

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
{% include "conf.py.jj2" %}
2-
3-
master_doc = "index"

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# The short X.Y version
2828
version = '0.6.6'
2929
# The full version, including alpha/beta/rc tags
30-
release = '0.6.5'
30+
release = '0.6.6'
3131

3232
# -- General configuration ---------------------------------------------------
3333

@@ -82,5 +82,4 @@
8282
]
8383
intersphinx_mapping.update({
8484
})
85-
8685
master_doc = "index"

moban/core/data_loader.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def get_data(self, file_name):
2828

2929

3030
def load_data(base_dir, file_name):
31+
3132
abs_file_path = search_file(base_dir, file_name)
3233
data = LOADER.get_data(abs_file_path)
3334
if data is not None:
@@ -38,7 +39,10 @@ def load_data(base_dir, file_name):
3839
overrides = [overrides]
3940
for parent_file in overrides:
4041
file_name, key = parent_file, None
41-
if ":" in parent_file:
42+
results = match_fs_url(parent_file)
43+
if results:
44+
file_name, key = results
45+
elif ":" in parent_file and "://" not in parent_file:
4246
file_name, key = parent_file.split(":")
4347
child_data = load_data(base_dir, file_name)
4448
if data:
@@ -93,3 +97,11 @@ def search_file(base_dir, file_name):
9397
else:
9498
raise IOError(constants.ERROR_DATA_FILE_ABSENT % the_file)
9599
return the_file
100+
101+
102+
def match_fs_url(file_name):
103+
import re
104+
105+
results = re.match("(.*://.*):(.*)", file_name)
106+
if results:
107+
return (results.group(1), results.group(2))

moban/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
import logging.config
1515
from collections import defaultdict
1616

17+
from ruamel.yaml import YAML
18+
1719
from moban import constants, exceptions
1820
from moban.core import ENGINES, plugins, hashstore, mobanfile, data_loader
1921
from moban._version import __version__
2022
from moban.externals import reporter, file_system
2123
from moban.program_options import OPTIONS
2224

25+
try:
26+
from cStringIO import StringIO
27+
except ImportError:
28+
from io import StringIO
29+
2330
LOG = logging.getLogger()
2431
LOG_LEVEL = [logging.WARNING, logging.INFO, logging.DEBUG]
2532

@@ -173,6 +180,10 @@ def handle_moban_file(moban_file, options):
173180
act upon default moban file
174181
"""
175182
moban_file_configurations = data_loader.load_data(None, moban_file)
183+
yaml = YAML(typ="rt")
184+
dumped_yaml = StringIO()
185+
yaml.dump(moban_file_configurations, dumped_yaml)
186+
LOG.info(dumped_yaml.getvalue())
176187
if moban_file_configurations is None:
177188
raise exceptions.MobanfileGrammarException(
178189
constants.ERROR_INVALID_MOBAN_FILE % moban_file

mobanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ targets:
77
- setup.py: moban_setup.py.jj2
88
- moban/__init__.py: __init__.py.jj2
99
- moban/_version.py: _version.py.jj2
10-
- docs/conf.py: custom_conf.py.jj2
10+
- docs/conf.py: conf.py.jj2
1111
- .travis.yml: moban_travis.yml.jj2
1212
- requirements.txt: requirements.txt.jj2
1313
- .gitignore: moban_gitignore.jj2

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Yet another jinja2 cli command for static text generation"
5151
)
5252
URL = "https://github.com/moremoban/moban"
53-
DOWNLOAD_URL = "%s/archive/0.6.5.tar.gz" % URL
53+
DOWNLOAD_URL = "%s/archive/0.6.6.tar.gz" % URL
5454
FILES = ["README.rst", "CONTRIBUTORS.rst", "CHANGELOG.rst"]
5555
KEYWORDS = [
5656
"python",
@@ -97,8 +97,8 @@
9797
}
9898
# You do not need to read beyond this line
9999
PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable)
100-
GS_COMMAND = ("gs moban v0.6.5 " +
101-
"Find 0.6.5 in changelog for more details")
100+
GS_COMMAND = ("gs moban v0.6.6 " +
101+
"Find 0.6.6 in changelog for more details")
102102
NO_GS_MESSAGE = ("Automatic github release is disabled. " +
103103
"Please install gease to enable it.")
104104
UPLOAD_FAILED_MSG = (

tests/data_loaders/__init__.py

Whitespace-only changes.

tests/data_loaders/test_json_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs.path
22
from nose.tools import eq_
33

4-
from moban.data_loaders.json_loader import open_json
4+
from moban.plugins.json_loader import open_json
55

66

77
def test_open_json():

tests/data_loaders/test_overrides.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from nose.tools import eq_
44

5-
from moban.data_loaders.manager import load_data
5+
from moban.main import load_engine_factory_and_engines
6+
from moban.core.data_loader import load_data
67

78

89
def test_overrides_a_list_of_config_files():
@@ -79,3 +80,10 @@ def test_overrides_nested_keys():
7980
}
8081

8182
eq_(dict(actual), expected)
83+
84+
85+
def test_overrides_fs_url():
86+
load_engine_factory_and_engines()
87+
base_dir = os.path.join("tests", "fixtures")
88+
actual = load_data(None, os.path.join(base_dir, "override_fs_url.yaml"))
89+
assert "requires" in actual

0 commit comments

Comments
 (0)