diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5f335815..d29a3ddb 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -7,4 +7,5 @@ Before raising the PR, here is a check list: 5) do you think that you can understand your changes after 6 month? 5.1) can someone else understand your changes without your explanation? 6) are you pround of your code changes? - 6.1) do you have the feeling of achievement? \ No newline at end of file + 6.1) do you have the feeling of achievement? +7) please add your name and github link to contributors.rst in alphabetical order. \ No newline at end of file diff --git a/.isort.cfg b/.isort.cfg index 659ea21f..c9fa4652 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,6 +1,6 @@ [settings] line_length=79 -known_first_party=lml, jinja2 +known_first_party=lml, jinja2, ruamel.yaml indent=' ' multi_line_output=3 length_sort=1 diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index be4c1ca7..c887e9f0 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: +- changes: + - action: Updated + details: + - "`#37`: moban will report line number where the value is empty and the name of mobanfile. Switch from pyyaml to ruamel.yaml." + date: 10-12-2018 + version: 0.3.5 - changes: - action: Updated details: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index b0e8d808..d537e6cc 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -3,9 +3,9 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.3.4.1 -current_version: 0.3.4.1 -release: 0.3.4.1 +version: 0.3.5 +current_version: 0.3.5 +release: 0.3.5 branch: master command_line_interface: "moban" entry_point: "moban.main:main" @@ -15,7 +15,7 @@ keywords: - jinja2 - moban dependencies: - - pyyaml>=3.11 + - ruamel.yaml - jinja2>=2.7.1 - lml>=0.0.7 - crayons diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6a5a7052..8827534d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,16 @@ Change log ================================================================================ +0.3.5 - 10-12-2018 +-------------------------------------------------------------------------------- + +Updated +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#37 `_: moban will report line + number where the value is empty and the name of mobanfile. Switch from pyyaml + to ruamel.yaml. + 0.3.4.1 - 28-11-2018 -------------------------------------------------------------------------------- diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index b2a00887..7b29a48f 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -5,5 +5,6 @@ In alphabetical order: * `Charlie Liu `_ * `John Vandenberg `_ +* `Joshua Chung `_ * `PRAJWAL M `_ * `SerekKiri `_ diff --git a/docs/conf.py b/docs/conf.py index 94e49034..79766cbb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,9 +28,9 @@ author = u'C. W.' # The short X.Y version -version = u'0.3.4.1' +version = u'0.3.5' # The full version, including alpha/beta/rc tags -release = u'0.3.4.1' +release = u'0.3.5' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index 6dc988ea..a33da8fe 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.3.4.1" +__version__ = "0.3.5" __author__ = "C. W." diff --git a/moban/constants.py b/moban/constants.py index 8c2fa5fc..ae11d2f9 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -65,6 +65,7 @@ ERROR_INVALID_MOBAN_FILE = "%s is an invalid yaml file." ERROR_NO_TARGETS = "No targets in %s" ERROR_NO_TEMPLATE = "No template found" +ERROR_MALFORMED_YAML = "Empty value in %s at line %s" # Shell messages diff --git a/moban/main.py b/moban/main.py index 991d4b93..a453e19b 100644 --- a/moban/main.py +++ b/moban/main.py @@ -113,6 +113,7 @@ def handle_moban_file(moban_file, options): raise exceptions.MobanfileGrammarException( constants.ERROR_NO_TARGETS % moban_file ) + check_none(moban_file_configurations, moban_file) version = moban_file_configurations.get( constants.MOBAN_VERSION, constants.DEFAULT_MOBAN_VERSION ) @@ -125,6 +126,28 @@ def handle_moban_file(moban_file, options): HASH_STORE.save_hashes() +def check_none(data, moban_file): + """ + check whether the yaml data has empty value such as: + """ + if isinstance(data, dict): + for k, v in data.items(): + if check_none(v, moban_file) is None: + loc = data.lc.key(k) + raise exceptions.MobanfileGrammarException( + constants.ERROR_MALFORMED_YAML + % (moban_file, loc[0] + 1) # line number starts from 0 + ) + elif isinstance(data, list): + for i, x in enumerate(data): + if check_none(x, moban_file) is None: + loc = data.lc.item(i) + raise exceptions.MobanfileGrammarException( + constants.ERROR_MALFORMED_YAML % (moban_file, loc[0] + 1) + ) + return data + + def handle_command_line(options): """ act upon command options diff --git a/moban/utils.py b/moban/utils.py index 09f0c5e9..a36b1793 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -5,7 +5,8 @@ import stat import errno -import yaml +from ruamel.yaml import YAML + import moban.reporter as reporter import moban.constants as constants import moban.exceptions as exceptions @@ -37,6 +38,7 @@ def open_yaml(base_dir, file_name): """ the_yaml_file = search_file(base_dir, file_name) with open(the_yaml_file, "r") as data_yaml: + yaml = YAML(typ="rt") data = yaml.load(data_yaml) if data is not None: parent_data = None diff --git a/requirements.txt b/requirements.txt index cc7ce754..2be8834e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pyyaml>=3.11 +ruamel.yaml jinja2>=2.7.1 lml>=0.0.7 crayons diff --git a/setup.py b/setup.py index ca970f2d..72553f21 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ NAME = 'moban' AUTHOR = 'C. W.' -VERSION = '0.3.4.1' +VERSION = '0.3.5' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'MIT' ENTRY_POINTS = { @@ -25,7 +25,7 @@ 'Yet another jinja2 cli command for static text generation' ) URL = 'https://github.com/moremoban/moban' -DOWNLOAD_URL = '%s/archive/0.3.4.1.tar.gz' % URL +DOWNLOAD_URL = '%s/archive/0.3.5.tar.gz' % URL FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst'] KEYWORDS = [ 'python', @@ -46,7 +46,7 @@ ] INSTALL_REQUIRES = [ - 'pyyaml>=3.11', + 'ruamel.yaml', 'jinja2>=2.7.1', 'lml>=0.0.7', 'crayons', @@ -60,8 +60,8 @@ # You do not need to read beyond this line PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format( sys.executable) -GS_COMMAND = ('gs moban v0.3.4.1 ' + - "Find 0.3.4.1 in changelog for more details") +GS_COMMAND = ('gs moban v0.3.5 ' + + "Find 0.3.5 in changelog for more details") NO_GS_MESSAGE = ('Automatic github release is disabled. ' + 'Please install gease to enable it.') UPLOAD_FAILED_MSG = ( diff --git a/tests/test_main.py b/tests/test_main.py index 87e5aadd..9cbb0b9d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -4,7 +4,7 @@ import moban.exceptions as exceptions from mock import patch -from nose.tools import raises +from nose.tools import raises, assert_raises class TestException: @@ -30,6 +30,41 @@ def test_handle_moban_file(self): main.handle_moban_file(self.moban_file, {}) + def test_check_none(self): + import moban.main as main + from ruamel.yaml import YAML + + yaml = YAML() + + invalid_data = [ + """targets: + - output:""", + """configuration: + template_dir: + - cool-templates + -""", + ] + + valid_data = [ + """targets: + - output: template""", + """configuration: + template_dir: + - cool-templates + - custom-templates""", + ] + + for data in (yaml.load(d) for d in invalid_data): + assert_raises( + exceptions.MobanfileGrammarException, + main.check_none, + data, + ".moban.yaml", + ) + + for data in (yaml.load(d) for d in valid_data): + main.check_none(data, ".moban.yaml") + @raises(exceptions.MobanfileGrammarException) def test_version_1_is_recognized(self): copyfile(