From 0bfc83f87b2029e9d4bee62454b7c53a81be7237 Mon Sep 17 00:00:00 2001 From: Md Nazrul Islam Date: Tue, 16 May 2017 19:42:29 +0200 Subject: [PATCH] Issue: #1 Added default folders option values, if not have existing file or file not contains folders options value Development status changes to Stable --- README.rst | 4 --- setup.cfg | 2 +- setup.py | 2 +- src/plone/recipe/sublimetext/recipes.py | 31 ++++++++++++++++++++-- src/plone/recipe/sublimetext/template.json | 27 ++++++------------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/README.rst b/README.rst index 1a8a4cb..dee156f 100644 --- a/README.rst +++ b/README.rst @@ -10,10 +10,6 @@ :target: https://coveralls.io/r/nazrulworld/plone.recipe.sublimetext :alt: Test Coverage -.. image:: https://img.shields.io/pypi/dm/plone.recipe.sublimetext.svg - :target: https://pypi.python.org/pypi/plone.recipe.sublimetext/ - :alt: Downloads - .. image:: https://img.shields.io/pypi/pyversions/plone.recipe.sublimetext.svg :target: https://pypi.python.org/pypi/plone.recipe.sublimetext/ :alt: Python Versions diff --git a/setup.cfg b/setup.cfg index 32b33bd..cfceb9a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,5 +8,5 @@ line_length = 200 not_skip = __init__.py [zest.releaser] -create-wheel = no +create-wheel = yes register = yes \ No newline at end of file diff --git a/setup.py b/setup.py index 08ee388..17202f3 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ def read(*rnames): # Get more from https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Environment :: Web Environment', - 'Development Status :: 3 - Alpha', + 'Development Status :: 5 - Production/Stable', 'Framework :: Plone', 'Framework :: Plone :: 4.3', 'Framework :: Plone :: 5.0', diff --git a/src/plone/recipe/sublimetext/recipes.py b/src/plone/recipe/sublimetext/recipes.py index eb6894a..4e16d5a 100644 --- a/src/plone/recipe/sublimetext/recipes.py +++ b/src/plone/recipe/sublimetext/recipes.py @@ -20,6 +20,12 @@ } json_load_params = {} +default_st3_folders_settings = [ + { + 'path': '.' + } + ] + if PY2: json_dump_params['encoding'] = 'utf-8' json_load_params['encoding'] = 'utf-8' @@ -194,9 +200,13 @@ def _write_project_file(self, project_file, settings, overwrite=False): # get comment cleaned (/* */) json string json_string = json_comment.sub('', f.read().strip()) existing_st3_settings = json.loads(json_string, **json_load_params) - existing_st3_settings.update(settings) - settings = existing_st3_settings.copy() + if existing_st3_settings: + self._merge_settings(settings, existing_st3_settings) + settings = existing_st3_settings.copy() + + if 'folders' not in settings: + settings['folders'] = default_st3_folders_settings with open(project_file, 'w') as f: json.dump(settings, f, **json_dump_params) @@ -205,6 +215,23 @@ def _write_project_file(self, project_file, settings, overwrite=False): # catching any json error raise UserError(str(exc)) + def _merge_settings(self, new_settings, existing_settings): + """ """ + + for key, value in new_settings.items(): + + try: + item = existing_settings[key] + if isinstance(value, dict) and (type(item) == type(value)): + self._merge_settings(value, item) + existing_settings[key] = item + else: + existing_settings[key] = value + + except KeyError: + # New Item + existing_settings[key] = value + def uninstall(name, options): """ """ diff --git a/src/plone/recipe/sublimetext/template.json b/src/plone/recipe/sublimetext/template.json index 8623c58..a3fa2d1 100644 --- a/src/plone/recipe/sublimetext/template.json +++ b/src/plone/recipe/sublimetext/template.json @@ -1,33 +1,22 @@ { "ST3_DEFAULTS": { - "show_line_endings": true, - "sublimelinter": false, - "tab_size": 4, - "translate_tabs_to_spaces": true, - "trim_automatic_white_space": true, - "trim_trailing_white_space_on_save": true + "sublimelinter": false }, + "ST3_FOLDER_OPTIONS": [ + { + "path": "." + } + ], "SUBLIMELINTER_DEFAULTS": { "@python": 3, "linters": {} }, "SUBLIMELINTER_FLAKE8_DEFAULTS": { - "@disable": false, - "args": [], - "builtins": "", - "excludes": [], - "ignore": "", - "jobs": "1", - "max-complexity": 15, - "max-line-length": 120, - "select": "", - "show-code": false + "@disable": false }, "SUBLIMELINTER_PYLINTER_DEFAULTS": { "@disable": false, - "args": [], - "paths": [], - "show-codes": false + "paths": [] }, "JEDI_DEFAULTS": { "python_interpreter": "$project_path/bin/python",