From f4b7570b530d7c8be6a611369ce088ec52db0cb0 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 30 Nov 2018 18:58:29 +0000 Subject: [PATCH 1/6] :sparkles: switch to ruemel.yaml and see. related to #37 --- .moban.cd/changelog.yml | 6 ++++++ .moban.cd/moban.yml | 6 +++--- CHANGELOG.rst | 9 +++++++++ docs/conf.py | 2 +- moban/_version.py | 2 +- moban/utils.py | 3 ++- requirements.txt | 2 +- setup.py | 4 ++-- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index be4c1ca7..80217dc1 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`: switch from pyyaml to ruamel.yaml" + date: 28-11-2018 + version: 0.3.5 - changes: - action: Updated details: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index b0e8d808..e1b2054a 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -3,8 +3,8 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.3.4.1 -current_version: 0.3.4.1 +version: 0.3.5 +current_version: 0.3.5 release: 0.3.4.1 branch: master command_line_interface: "moban" @@ -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..983759dc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.3.5 - 28-11-2018 +-------------------------------------------------------------------------------- + +Updated +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#37 `_: switch from pyyaml to + ruamel.yaml + 0.3.4.1 - 28-11-2018 -------------------------------------------------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index 94e49034..f9bd44e9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,7 @@ # The short X.Y version version = u'0.3.4.1' # 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/utils.py b/moban/utils.py index 09f0c5e9..f099f5be 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -5,7 +5,7 @@ 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 +37,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='safe') 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..556de564 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 = { @@ -46,7 +46,7 @@ ] INSTALL_REQUIRES = [ - 'pyyaml>=3.11', + 'ruamel.yaml', 'jinja2>=2.7.1', 'lml>=0.0.7', 'crayons', From d0540fd7b412cd74a933d8911eb5c8cb72a4d0d8 Mon Sep 17 00:00:00 2001 From: joshua1b Date: Sun, 2 Dec 2018 12:04:37 +0900 Subject: [PATCH 2/6] Report location where the value is empty in mobanfile If empty value is found in mobanfile, moban will report the line number of that and the name of the file. Closes https://github.com/moremoban/moban/issues/37 --- .moban.cd/changelog.yml | 1 + CHANGELOG.rst | 2 ++ moban/constants.py | 1 + moban/main.py | 23 +++++++++++++++++++++++ moban/utils.py | 4 ++-- tests/test_main.py | 37 ++++++++++++++++++++++++++++++++++++- 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 80217dc1..1cff95ee 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -5,6 +5,7 @@ releases: - action: Updated details: - "`#37`: switch from pyyaml to ruamel.yaml" + - "moban will report line number where the value is empty and the name of mobanfile" date: 28-11-2018 version: 0.3.5 - changes: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 983759dc..89dbf86d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,8 @@ Updated #. `#37 `_: switch from pyyaml to ruamel.yaml +#. moban will report line number where the value is empty and the name of + mobanfile 0.3.4.1 - 28-11-2018 -------------------------------------------------------------------------------- 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 f099f5be..3d804a72 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -5,10 +5,10 @@ import stat import errno -from ruamel.yaml import YAML import moban.reporter as reporter import moban.constants as constants import moban.exceptions as exceptions +from ruamel.yaml import YAML def merge(left, right): @@ -37,7 +37,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='safe') + yaml = YAML(typ="rt") data = yaml.load(data_yaml) if data is not None: parent_data = None 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( From 871aba6accaacd46b37ae7e1cefce31e9844bb99 Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 10 Dec 2018 07:12:44 +0000 Subject: [PATCH 3/6] :hammer: adjust ruamel.yaml to known first party. #139 --- .isort.cfg | 2 +- moban/utils.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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/utils.py b/moban/utils.py index 3d804a72..a36b1793 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -5,10 +5,11 @@ import stat import errno +from ruamel.yaml import YAML + import moban.reporter as reporter import moban.constants as constants import moban.exceptions as exceptions -from ruamel.yaml import YAML def merge(left, right): From dfcf4addeeeebc5553b61bcbc1afdd1e4cf5ace1 Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 10 Dec 2018 07:14:12 +0000 Subject: [PATCH 4/6] :books: update change log. #139 --- .moban.cd/changelog.yml | 5 ++--- CHANGELOG.rst | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 1cff95ee..c887e9f0 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -4,9 +4,8 @@ releases: - changes: - action: Updated details: - - "`#37`: switch from pyyaml to ruamel.yaml" - - "moban will report line number where the value is empty and the name of mobanfile" - date: 28-11-2018 + - "`#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 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 89dbf86d..8827534d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,16 +1,15 @@ Change log ================================================================================ -0.3.5 - 28-11-2018 +0.3.5 - 10-12-2018 -------------------------------------------------------------------------------- Updated ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -#. `#37 `_: switch from pyyaml to - ruamel.yaml -#. moban will report line number where the value is empty and the name of - mobanfile +#. `#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 -------------------------------------------------------------------------------- From c189f1ececde42d6027e6e142e2fbc95a67acd3f Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 10 Dec 2018 07:15:11 +0000 Subject: [PATCH 5/6] :egg: :ferris_wheel: release 0.3.5. better yaml error --- .moban.cd/moban.yml | 2 +- docs/conf.py | 2 +- setup.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index e1b2054a..d537e6cc 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -5,7 +5,7 @@ contact: wangc_2011@hotmail.com license: MIT version: 0.3.5 current_version: 0.3.5 -release: 0.3.4.1 +release: 0.3.5 branch: master command_line_interface: "moban" entry_point: "moban.main:main" diff --git a/docs/conf.py b/docs/conf.py index f9bd44e9..79766cbb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ 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.5' diff --git a/setup.py b/setup.py index 556de564..72553f21 100644 --- a/setup.py +++ b/setup.py @@ -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', @@ -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 = ( From 1dcd10cdd8fc9828072c4d363908ad0415f0f447 Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 10 Dec 2018 07:17:30 +0000 Subject: [PATCH 6/6] :books: update contributors --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- CONTRIBUTORS.rst | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) 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/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 `_