From 00ffe2ad8f88673d01441be874bc012e32004649 Mon Sep 17 00:00:00 2001 From: MrTango Date: Mon, 21 Oct 2019 14:54:55 +0200 Subject: [PATCH 1/2] Add restapi_serializer --- bobtemplates/plone/restapi_serializer.py | 142 ++++++++++ .../plone/restapi_serializer/.mrbob.ini | 19 ++ .../plone/restapi_serializer/api/__init__.py | 0 .../api/configure.zcml.example.bob | 10 + .../+serializer_class_name_normalized+.py.bob | 24 ++ ...serializer_class_name_normalized+.zcml.bob | 7 + .../api/serializers/__init__.py | 0 .../serializers/configure.zcml.example.bob | 10 + package_tests/test_restapi_serializer.py | 264 ++++++++++++++++++ 9 files changed, 476 insertions(+) create mode 100644 bobtemplates/plone/restapi_serializer.py create mode 100644 bobtemplates/plone/restapi_serializer/.mrbob.ini create mode 100644 bobtemplates/plone/restapi_serializer/api/__init__.py create mode 100644 bobtemplates/plone/restapi_serializer/api/configure.zcml.example.bob create mode 100644 bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.py.bob create mode 100644 bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.zcml.bob create mode 100644 bobtemplates/plone/restapi_serializer/api/serializers/__init__.py create mode 100644 bobtemplates/plone/restapi_serializer/api/serializers/configure.zcml.example.bob create mode 100644 package_tests/test_restapi_serializer.py diff --git a/bobtemplates/plone/restapi_serializer.py b/bobtemplates/plone/restapi_serializer.py new file mode 100644 index 000000000..0e5da7439 --- /dev/null +++ b/bobtemplates/plone/restapi_serializer.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- + +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import remove_unwanted_files +from bobtemplates.plone.base import update_configure_zcml +from lxml import etree + +import case_conversion as cc + + +def _update_package_configure_zcml(configurator): + path = "{0}".format(configurator.variables["package_folder"]) + file_name = u"configure.zcml" + match_xpath = "include[@package='.api']" + match_str = "-*- extra stuff goes here -*-" + insert_str = """ + +""" + update_configure_zcml( + configurator, + path, + file_name=file_name, + match_xpath=match_xpath, + match_str=match_str, + insert_str=insert_str, + ) + + +def _update_api_configure_zcml(configurator): + path = "{0}/api".format(configurator.variables["package_folder"]) + file_name = u"configure.zcml" + example_file_name = "{0}.example".format(file_name) + match_xpath = "zope:include[@package='.serializers']" + match_str = "-*- extra stuff goes here -*-" + insert_str = """ + +""" + update_configure_zcml( + configurator, + path, + file_name=file_name, + example_file_name=example_file_name, + match_xpath=match_xpath, + match_str=match_str, + insert_str=insert_str, + ) + + +def _update_serializers_configure_zcml(configurator): + path = "{0}/api/serializers".format(configurator.variables["package_folder"]) + file_name = u"configure.zcml" + example_file_name = "{0}.example".format(file_name) + match_xpath = "zope:include[@package='.{0}']".format( + configurator.variables["serializer_class_name_normalized"] + ) + match_str = "-*- extra stuff goes here -*-" + insert_str = '\n'.format( + configurator.variables["serializer_class_name_normalized"] + ) + update_configure_zcml( + configurator, + path, + file_name=file_name, + example_file_name=example_file_name, + match_xpath=match_xpath, + match_str=match_str, + insert_str=insert_str, + ) + + +def _update_metadata_xml(configurator): + """ Add plone.restapi dependency metadata.xml in + Generic Setup profiles. + """ + metadata_file_name = u"metadata.xml" + metadata_file_dir = u"profiles/default" + metadata_file_path = ( + configurator.variables["package_folder"] + + "/" + + metadata_file_dir + + "/" + + metadata_file_name + ) + + with open(metadata_file_path, "r") as xml_file: + parser = etree.XMLParser(remove_blank_text=True) + tree = etree.parse(xml_file, parser) + dependencies = tree.xpath("/metadata/dependencies")[0] + dep = "profile-plone.restapi:default" + dep_exists = False + for e in dependencies.iter("dependency"): + dep_name = e.text + if dep_name == dep: + dep_exists = True + + if dep_exists: + print("{dep} already in metadata.xml, skip adding!".format(dep=dep)) + return + dep_element = etree.Element("dependency") + dep_element.text = dep + dependencies.append(dep_element) + + with open(metadata_file_path, "wb") as xml_file: + tree.write(xml_file, pretty_print=True, xml_declaration=True, encoding="utf-8") + + +def _remove_unwanted_files(configurator): + file_paths = [] + rel_file_paths = [ + "/api/configure.zcml.example", + "/api/serializers/configure.zcml.example", + ] + base_path = configurator.variables["package_folder"] + for rel_file_path in rel_file_paths: + file_paths.append("{0}{1}".format(base_path, rel_file_path)) + remove_unwanted_files(file_paths) + + +def pre_renderer(configurator): + """Pre rendering.""" + configurator = base_prepare_renderer(configurator) + configurator.variables["template_id"] = "restapi_serializer" + class_name = configurator.variables["serializer_class_name"].strip("_") + configurator.variables["serializer_class_name"] = cc.pascalcase(class_name) + configurator.variables["serializer_class_name_normalized"] = cc.snakecase( + class_name + ) + configurator.target_directory = configurator.variables["package_folder"] + + +def post_renderer(configurator): + """Post rendering.""" + _update_package_configure_zcml(configurator) + _update_api_configure_zcml(configurator) + _update_serializers_configure_zcml(configurator) + _update_metadata_xml(configurator) + _remove_unwanted_files(configurator) + git_commit( + configurator, + "Add restapi_serializer: {0}".format(configurator.variables["serializer_class_name"]), + ) diff --git a/bobtemplates/plone/restapi_serializer/.mrbob.ini b/bobtemplates/plone/restapi_serializer/.mrbob.ini new file mode 100644 index 000000000..fae37ba91 --- /dev/null +++ b/bobtemplates/plone/restapi_serializer/.mrbob.ini @@ -0,0 +1,19 @@ +[questions] +subtemplate_warning.question = Please commit your changes, before using a sub-template! Continue anyway? (y/n) +subtemplate_warning.required = True +subtemplate_warning.default = n +subtemplate_warning.pre_ask_question = bobtemplates.plone.base:git_clean_state_check +subtemplate_warning.post_ask_question = mrbob.hooks:validate_choices bobtemplates.plone.base:subtemplate_warning_post_question +subtemplate_warning.choices = y|n +subtemplate_warning.choices_delimiter = | + +serializer_class_name.question = Serializer class name +serializer_class_name.help = Should be something like 'SpecialFieldSerializer' (PascalCase) +serializer_class_name.required = True +serializer_class_name.default = +serializer_class_name.post_ask_question = bobtemplates.plone.base:check_klass_name + +[template] +pre_render = bobtemplates.plone.restapi_serializer:pre_renderer +post_render = bobtemplates.plone.restapi_serializer:post_renderer +post_ask = bobtemplates.plone.base:set_global_vars diff --git a/bobtemplates/plone/restapi_serializer/api/__init__.py b/bobtemplates/plone/restapi_serializer/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/bobtemplates/plone/restapi_serializer/api/configure.zcml.example.bob b/bobtemplates/plone/restapi_serializer/api/configure.zcml.example.bob new file mode 100644 index 000000000..5841c5f68 --- /dev/null +++ b/bobtemplates/plone/restapi_serializer/api/configure.zcml.example.bob @@ -0,0 +1,10 @@ + + + -*- extra stuff goes here -*- + + + diff --git a/bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.py.bob b/bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.py.bob new file mode 100644 index 000000000..ecf3a6396 --- /dev/null +++ b/bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.py.bob @@ -0,0 +1,24 @@ + +# -*- coding: utf-8 -*- + +from plone.customfield.interfaces import ICustomField +from plone.dexterity.interfaces import IDexterityContent +from plone.restapi.interfaces import IFieldSerializer +from plone.restapi.serializer.converters import json_compatible +from plone.restapi.serializer.dxfields import DefaultFieldSerializer +from zope.component import adapter +from zope.interface import implementer +from zope.interface import Interface + + +@adapter(ICustomField, IDexterityContent, Interface) +@implementer(IFieldSerializer) +class {{{ serializer_class_name }}}(DefaultFieldSerializer): + + def __call__(self): + value = self.get_value() + if value is not None: + # Do custom serializing here, e.g.: + value = value.output() + + return json_compatible(value) diff --git a/bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.zcml.bob b/bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.zcml.bob new file mode 100644 index 000000000..b0faf5694 --- /dev/null +++ b/bobtemplates/plone/restapi_serializer/api/serializers/+serializer_class_name_normalized+.zcml.bob @@ -0,0 +1,7 @@ + + + + + diff --git a/bobtemplates/plone/restapi_serializer/api/serializers/__init__.py b/bobtemplates/plone/restapi_serializer/api/serializers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/bobtemplates/plone/restapi_serializer/api/serializers/configure.zcml.example.bob b/bobtemplates/plone/restapi_serializer/api/serializers/configure.zcml.example.bob new file mode 100644 index 000000000..5841c5f68 --- /dev/null +++ b/bobtemplates/plone/restapi_serializer/api/serializers/configure.zcml.example.bob @@ -0,0 +1,10 @@ + + + -*- extra stuff goes here -*- + + + diff --git a/package_tests/test_restapi_serializer.py b/package_tests/test_restapi_serializer.py new file mode 100644 index 000000000..4212fbbc6 --- /dev/null +++ b/package_tests/test_restapi_serializer.py @@ -0,0 +1,264 @@ +# -*- coding: utf-8 -*- + +from bobtemplates.plone import base +from bobtemplates.plone import restapi_service +from mrbob.configurator import Configurator + +import os + + +def test_pre_renderer(tmpdir): + target_path = tmpdir.strpath + '/collective.todo' + package_path = target_path + '/src/collective/todo' + os.makedirs(target_path) + os.makedirs(package_path) + template = """ +[main] +version=5.1 +""" + with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + f.write(template) + + template = """ + dummy + '-*- Extra requirements: -*-' +""" + with open(os.path.join(target_path + '/setup.py'), 'w') as f: + f.write(template) + + configurator = Configurator( + template='bobtemplates.plone:restapi_service', + target_directory=target_path, + variables={ + 'service_class_name': 'SomeRelatedThings', + 'service_name': 'some-related-things', + 'package_folder': package_path, + }, + ) + restapi_service.pre_renderer(configurator) + + +def test_post_renderer(tmpdir): + target_path = tmpdir.strpath + '/collective.todo' + package_path = target_path + '/src/collective/todo' + profiles_path = package_path + '/profiles/default' + os.makedirs(target_path) + os.makedirs(package_path) + os.makedirs(profiles_path) + + template = """ + + 1000 + + + + +""" + with open(os.path.join(profiles_path + '/metadata.xml'), 'w') as f: + f.write(template) + + template = """ +[main] +version=5.1 +""" + with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + f.write(template) + + template = """ + dummy + '-*- Extra requirements: -*-' +""" + with open(os.path.join(target_path + '/setup.py'), 'w') as f: + f.write(template) + + template = """ + + + + + +""" + with open(os.path.join(package_path + '/configure.zcml'), 'w') as f: + f.write(template) + + configurator = Configurator( + template='bobtemplates.plone:restapi_service', + target_directory=package_path, + bobconfig={ + 'non_interactive': True, + }, + variables={ + 'package_folder': package_path, + 'plone.version': '5.1', + 'service_class_name': 'SomeRelatedThings', + 'service_name': 'some-related-things', + }, + ) + assert configurator + os.chdir(package_path) + base.set_global_vars(configurator) + restapi_service.pre_renderer(configurator) + configurator.render() + restapi_service.post_renderer(configurator) + + +def test_remove_unwanted_files(tmpdir): + files_to_remove = [ + '/api/configure.zcml.example', + '/api/services/configure.zcml.example', + ] + target_path = tmpdir.strpath + '/collective.todo' + package_path = target_path + '/src/collective/todo' + os.makedirs(package_path + '/api/services/') + configurator = Configurator( + template='bobtemplates.plone:restapi_service', + target_directory=tmpdir.strpath, + variables={ + 'package_folder': package_path, + }, + ) + for file_to_remove in files_to_remove: + with open( + os.path.join( + package_path + file_to_remove, + ), + 'w', + ) as f: + f.write(u'dummy') + restapi_service._remove_unwanted_files(configurator) + + for file_to_remove in files_to_remove: + assert not os.path.isfile( + os.path.join(package_path + file_to_remove), + ) + + +def test_update_api_configure_zcml(tmpdir): + """ + """ + target_path = tmpdir.strpath + '/collective.todo' + package_path = target_path + '/src/collective/todo' + os.makedirs(package_path + '/api/') + + template = """ +[main] +version=5.1 +""" + with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + f.write(template) + + template = """ + dummy + '-*- Extra requirements: -*-' +""" + with open(os.path.join(target_path + '/setup.py'), 'w') as f: + f.write(template) + + template = """ + + + + + +""" + with open(os.path.join(package_path + '/configure.zcml'), 'w') as f: + f.write(template) + with open(os.path.join(package_path + '/api/configure.zcml'), 'w') as f: + f.write(template) + configurator = Configurator( + template='bobtemplates.plone:restapi_service', + target_directory=package_path, + bobconfig={ + 'non_interactive': True, + }, + variables={ + 'package_folder': package_path, + 'plone.version': '5.1', + 'service_class_name': 'SomeRelatedThings', + 'service_name': 'some-related-things', + }, + ) + restapi_service._update_api_configure_zcml(configurator) + + with open( + os.path.join( + package_path + '/api/configure.zcml', + ), + 'r', + ) as f: + content = f.read() + assert content != template, u'configure.zcml was not updated!' + + +def test_update_services_configure_zcml(tmpdir): + """ + """ + target_path = tmpdir.strpath + '/collective.todo' + package_path = target_path + '/src/collective/todo' + os.makedirs(package_path + '/api/services/') + + template = """ +[main] +version=5.1 +""" + with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + f.write(template) + + template = """ + dummy + '-*- Extra requirements: -*-' +""" + with open(os.path.join(target_path + '/setup.py'), 'w') as f: + f.write(template) + + template = """ + + + + + +""" + with open(os.path.join(package_path + '/configure.zcml'), 'w') as f: + f.write(template) + with open(os.path.join(package_path + '/api/configure.zcml'), 'w') as f: + f.write(template) + with open( + os.path.join(package_path + '/api/services/configure.zcml'), 'w', + ) as f: + f.write(template) + configurator = Configurator( + template='bobtemplates.plone:restapi_service', + target_directory=package_path, + bobconfig={ + 'non_interactive': True, + }, + variables={ + 'package_folder': package_path, + 'plone.version': '5.1', + 'service_class_name': 'SomeRelatedThings', + 'service_class_name_normalized': 'some_related_things', + 'service_name': 'some-related-things', + }, + ) + restapi_service._update_services_configure_zcml(configurator) + + with open( + os.path.join( + package_path + '/api/services/configure.zcml', + ), + 'r', + ) as f: + content = f.read() + assert content != template, u'configure.zcml was not updated!' From afb49c9474d72d9d2055379ac9890bd3e88ab6db Mon Sep 17 00:00:00 2001 From: MrTango Date: Fri, 7 Oct 2022 10:42:22 +0300 Subject: [PATCH 2/2] linting --- bobtemplates/plone/addon.py | 9 +- .../plone/addon/constraints_plone60.txt | 2 +- bobtemplates/plone/base.py | 22 +-- bobtemplates/plone/behavior.py | 13 +- bobtemplates/plone/bobregistry.py | 8 ++ bobtemplates/plone/content_type.py | 25 ++-- bobtemplates/plone/controlpanel.py | 18 ++- bobtemplates/plone/indexer.py | 15 +- bobtemplates/plone/mockup_pattern.py | 10 +- bobtemplates/plone/portlet.py | 24 ++-- bobtemplates/plone/restapi_serializer.py | 18 +-- bobtemplates/plone/restapi_service.py | 15 +- bobtemplates/plone/subscriber.py | 15 +- bobtemplates/plone/svelte_app.py | 13 +- bobtemplates/plone/theme.py | 23 ++- bobtemplates/plone/theme_barceloneta.py | 17 +-- bobtemplates/plone/theme_basic.py | 17 +-- bobtemplates/plone/upgrade_step.py | 11 +- bobtemplates/plone/utils.py | 7 +- bobtemplates/plone/view.py | 25 ++-- bobtemplates/plone/viewlet.py | 18 ++- bobtemplates/plone/vocabulary.py | 20 ++- constraints.txt | 2 +- package_tests/test_addon.py | 6 +- package_tests/test_base.py | 7 +- package_tests/test_behavior.py | 6 +- package_tests/test_buildout.py | 3 +- package_tests/test_content_type.py | 11 +- package_tests/test_indexer.py | 11 +- package_tests/test_mockup_pattern.py | 11 +- package_tests/test_portlet.py | 8 +- package_tests/test_restapi_serializer.py | 135 +++++++++--------- package_tests/test_restapi_service.py | 6 +- package_tests/test_subscriber.py | 9 +- package_tests/test_svelte_app.py | 14 +- package_tests/test_theme.py | 14 +- package_tests/test_theme_barceloneta.py | 14 +- package_tests/test_theme_basic.py | 14 +- package_tests/test_upgrade_step.py | 9 +- package_tests/test_view.py | 15 +- package_tests/test_viewlet.py | 12 +- package_tests/test_vocabulary.py | 6 +- setup.cfg | 2 +- setup.py | 5 +- skeleton-tests/base.py | 3 +- skeleton-tests/conftest.py | 1 - skeleton-tests/test_addon.py | 5 +- skeleton-tests/test_addon_all.py | 6 +- skeleton-tests/test_addon_mockup_pattern.py | 8 +- .../test_addon_theme_barceloneta.py | 6 +- 50 files changed, 352 insertions(+), 342 deletions(-) diff --git a/bobtemplates/plone/addon.py b/bobtemplates/plone/addon.py index 7adbed8ec..1452de63c 100644 --- a/bobtemplates/plone/addon.py +++ b/bobtemplates/plone/addon.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import git_init +from bobtemplates.plone.base import make_path +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort + import os import shutil -from bobtemplates.plone.base import git_commit, git_init, make_path -from bobtemplates.plone.utils import run_black, run_isort - def pre_render(configurator): """Some variables to make templating easier.""" diff --git a/bobtemplates/plone/addon/constraints_plone60.txt b/bobtemplates/plone/addon/constraints_plone60.txt index 71616a7e1..68534bec5 100644 --- a/bobtemplates/plone/addon/constraints_plone60.txt +++ b/bobtemplates/plone/addon/constraints_plone60.txt @@ -12,5 +12,5 @@ #certifi ; platform_system == 'Windows' isort>=5 -black==22.8.0 +black==22.10.0 flake8>=5.0.4 diff --git a/bobtemplates/plone/base.py b/bobtemplates/plone/base.py index 3ffbe44e1..8a8344b9e 100644 --- a/bobtemplates/plone/base.py +++ b/bobtemplates/plone/base.py @@ -1,21 +1,25 @@ # -*- coding: utf-8 -*- +from colorama import Fore +from colorama import Style +from datetime import date +from lxml import etree +from mrbob import hooks +from mrbob.bobexceptions import MrBobError +from mrbob.bobexceptions import SkipQuestion +from mrbob.bobexceptions import ValidationError +from mrbob.rendering import jinja2_env +from six.moves import input + +import case_conversion as cc import codecs import keyword import os import re +import six import string import subprocess import sys -from datetime import date -import case_conversion as cc -import six -from colorama import Fore, Style -from lxml import etree -from mrbob import hooks -from mrbob.bobexceptions import MrBobError, SkipQuestion, ValidationError -from mrbob.rendering import jinja2_env -from six.moves import input try: from ConfigParser import ConfigParser diff --git a/bobtemplates/plone/behavior.py b/bobtemplates/plone/behavior.py index 4ac2eee9b..e29dd167c 100644 --- a/bobtemplates/plone/behavior.py +++ b/bobtemplates/plone/behavior.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -import os - -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort from lxml import etree -from bobtemplates.plone.base import base_prepare_renderer, echo, git_commit, update_file -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc +import os def _update_package_configure_zcml(configurator): diff --git a/bobtemplates/plone/bobregistry.py b/bobtemplates/plone/bobregistry.py index a89fa963d..412e346de 100644 --- a/bobtemplates/plone/bobregistry.py +++ b/bobtemplates/plone/bobregistry.py @@ -104,6 +104,14 @@ def plone_restapi_service(): return reg +def plone_restapi_serializer(): + reg = RegEntry() + reg.template = "bobtemplates.plone:restapi_serializer" + reg.plonecli_alias = "restapi_serializer" + reg.depend_on = "plone_addon" + return reg + + def plone_svelte_app(): reg = RegEntry() reg.template = "bobtemplates.plone:svelte_app" diff --git a/bobtemplates/plone/content_type.py b/bobtemplates/plone/content_type.py index 30a8dfb53..f6b84ae15 100644 --- a/bobtemplates/plone/content_type.py +++ b/bobtemplates/plone/content_type.py @@ -1,23 +1,22 @@ # -*- coding: utf-8 -*- """Generate content type.""" +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import get_normalized_classname +from bobtemplates.plone.base import get_normalized_dxtypename +from bobtemplates.plone.base import get_normalized_ftiname +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort +from lxml import etree +from mrbob.bobexceptions import SkipQuestion +from mrbob.bobexceptions import ValidationError + import keyword import os import re -from lxml import etree -from mrbob.bobexceptions import SkipQuestion, ValidationError - -from bobtemplates.plone.base import ( - base_prepare_renderer, - get_normalized_classname, - get_normalized_dxtypename, - get_normalized_ftiname, - git_commit, - update_file, -) -from bobtemplates.plone.utils import run_black, run_isort - def is_container(configurator, question): """Test if base class is a container.""" diff --git a/bobtemplates/plone/controlpanel.py b/bobtemplates/plone/controlpanel.py index 9ef53615c..54e29ad91 100644 --- a/bobtemplates/plone/controlpanel.py +++ b/bobtemplates/plone/controlpanel.py @@ -1,17 +1,15 @@ # -*- coding: utf-8 -*- -import os - -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import ZCML_NAMESPACES +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort from lxml import etree -from bobtemplates.plone.base import ( - ZCML_NAMESPACES, - base_prepare_renderer, - git_commit, - update_file, -) -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc +import os def _update_package_configure_zcml(configurator): diff --git a/bobtemplates/plone/indexer.py b/bobtemplates/plone/indexer.py index 6d6a2af47..493303c42 100644 --- a/bobtemplates/plone/indexer.py +++ b/bobtemplates/plone/indexer.py @@ -1,14 +1,13 @@ # -*- coding: utf-8 -*- -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import remove_unwanted_files +from bobtemplates.plone.base import update_configure_zcml +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort -from bobtemplates.plone.base import ( - base_prepare_renderer, - git_commit, - remove_unwanted_files, - update_configure_zcml, -) -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc def _update_package_configure_zcml(configurator): diff --git a/bobtemplates/plone/mockup_pattern.py b/bobtemplates/plone/mockup_pattern.py index 878305162..91c955a7f 100644 --- a/bobtemplates/plone/mockup_pattern.py +++ b/bobtemplates/plone/mockup_pattern.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- -import os -import re - +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import git_init from mrbob.bobexceptions import ValidationError -from bobtemplates.plone.base import base_prepare_renderer, echo, git_commit, git_init +import os +import re def pre_render(configurator): diff --git a/bobtemplates/plone/portlet.py b/bobtemplates/plone/portlet.py index 86169aaa4..36626186e 100644 --- a/bobtemplates/plone/portlet.py +++ b/bobtemplates/plone/portlet.py @@ -1,20 +1,20 @@ # -*- coding: utf-8 -*- """Generate portlet.""" -from __future__ import absolute_import, print_function - -import os - -import case_conversion as cc +from __future__ import absolute_import +from __future__ import print_function + +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import ZCML_NAMESPACES +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort +from bobtemplates.plone.utils import slugify from lxml import etree -from bobtemplates.plone.base import ( - ZCML_NAMESPACES, - base_prepare_renderer, - git_commit, - update_file, -) -from bobtemplates.plone.utils import run_black, run_isort, slugify +import case_conversion as cc +import os def _update_portlets_configure_zcml(configurator): diff --git a/bobtemplates/plone/restapi_serializer.py b/bobtemplates/plone/restapi_serializer.py index 0e5da7439..6722cfa47 100644 --- a/bobtemplates/plone/restapi_serializer.py +++ b/bobtemplates/plone/restapi_serializer.py @@ -11,7 +11,7 @@ def _update_package_configure_zcml(configurator): path = "{0}".format(configurator.variables["package_folder"]) - file_name = u"configure.zcml" + file_name = "configure.zcml" match_xpath = "include[@package='.api']" match_str = "-*- extra stuff goes here -*-" insert_str = """ @@ -29,7 +29,7 @@ def _update_package_configure_zcml(configurator): def _update_api_configure_zcml(configurator): path = "{0}/api".format(configurator.variables["package_folder"]) - file_name = u"configure.zcml" + file_name = "configure.zcml" example_file_name = "{0}.example".format(file_name) match_xpath = "zope:include[@package='.serializers']" match_str = "-*- extra stuff goes here -*-" @@ -49,7 +49,7 @@ def _update_api_configure_zcml(configurator): def _update_serializers_configure_zcml(configurator): path = "{0}/api/serializers".format(configurator.variables["package_folder"]) - file_name = u"configure.zcml" + file_name = "configure.zcml" example_file_name = "{0}.example".format(file_name) match_xpath = "zope:include[@package='.{0}']".format( configurator.variables["serializer_class_name_normalized"] @@ -70,11 +70,11 @@ def _update_serializers_configure_zcml(configurator): def _update_metadata_xml(configurator): - """ Add plone.restapi dependency metadata.xml in - Generic Setup profiles. + """Add plone.restapi dependency metadata.xml in + Generic Setup profiles. """ - metadata_file_name = u"metadata.xml" - metadata_file_dir = u"profiles/default" + metadata_file_name = "metadata.xml" + metadata_file_dir = "profiles/default" metadata_file_path = ( configurator.variables["package_folder"] + "/" @@ -138,5 +138,7 @@ def post_renderer(configurator): _remove_unwanted_files(configurator) git_commit( configurator, - "Add restapi_serializer: {0}".format(configurator.variables["serializer_class_name"]), + "Add restapi_serializer: {0}".format( + configurator.variables["serializer_class_name"] + ), ) diff --git a/bobtemplates/plone/restapi_service.py b/bobtemplates/plone/restapi_service.py index 08b464761..ff7cfc612 100644 --- a/bobtemplates/plone/restapi_service.py +++ b/bobtemplates/plone/restapi_service.py @@ -1,15 +1,14 @@ # -*- coding: utf-8 -*- -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import remove_unwanted_files +from bobtemplates.plone.base import update_configure_zcml +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort from lxml import etree -from bobtemplates.plone.base import ( - base_prepare_renderer, - git_commit, - remove_unwanted_files, - update_configure_zcml, -) -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc def get_service_name_from_python_class(configurator, question): diff --git a/bobtemplates/plone/subscriber.py b/bobtemplates/plone/subscriber.py index 830f49a9d..e55ef0dbc 100644 --- a/bobtemplates/plone/subscriber.py +++ b/bobtemplates/plone/subscriber.py @@ -1,14 +1,13 @@ # -*- coding: utf-8 -*- -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import remove_unwanted_files +from bobtemplates.plone.base import update_configure_zcml +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort -from bobtemplates.plone.base import ( - base_prepare_renderer, - git_commit, - remove_unwanted_files, - update_configure_zcml, -) -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc def _update_package_configure_zcml(configurator): diff --git a/bobtemplates/plone/svelte_app.py b/bobtemplates/plone/svelte_app.py index e13c03c37..9b72c742e 100644 --- a/bobtemplates/plone/svelte_app.py +++ b/bobtemplates/plone/svelte_app.py @@ -1,13 +1,16 @@ # -*- coding: utf-8 -*- -import re - -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort from lxml import etree from mrbob.bobexceptions import ValidationError -from bobtemplates.plone.base import base_prepare_renderer, echo, git_commit, update_file -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc +import re def check_name(configurator, question, answer): diff --git a/bobtemplates/plone/theme.py b/bobtemplates/plone/theme.py index 1647b1211..018a14ab3 100644 --- a/bobtemplates/plone/theme.py +++ b/bobtemplates/plone/theme.py @@ -1,21 +1,18 @@ # -*- coding: utf-8 -*- -import os -import re - +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import get_normalized_themename +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import is_string_in_file +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import validate_packagename +from bobtemplates.plone.base import ZCML_NAMESPACES from lxml import etree from mrbob.bobexceptions import ValidationError -from bobtemplates.plone.base import ( - ZCML_NAMESPACES, - base_prepare_renderer, - echo, - get_normalized_themename, - git_commit, - is_string_in_file, - update_file, - validate_packagename, -) +import os +import re def pre_theme_name(configurator, question): diff --git a/bobtemplates/plone/theme_barceloneta.py b/bobtemplates/plone/theme_barceloneta.py index 753c15f95..e6d18f29f 100644 --- a/bobtemplates/plone/theme_barceloneta.py +++ b/bobtemplates/plone/theme_barceloneta.py @@ -1,18 +1,15 @@ # -*- coding: utf-8 -*- -import os -import re - +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import validate_packagename from lxml import etree from mrbob.bobexceptions import ValidationError -from bobtemplates.plone.base import ( - base_prepare_renderer, - echo, - git_commit, - update_file, - validate_packagename, -) +import os +import re def pre_theme_name(configurator, question): diff --git a/bobtemplates/plone/theme_basic.py b/bobtemplates/plone/theme_basic.py index 6050f4f94..8905a8276 100644 --- a/bobtemplates/plone/theme_basic.py +++ b/bobtemplates/plone/theme_basic.py @@ -1,18 +1,15 @@ # -*- coding: utf-8 -*- -import os -import re - +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import validate_packagename from lxml import etree from mrbob.bobexceptions import ValidationError -from bobtemplates.plone.base import ( - base_prepare_renderer, - echo, - git_commit, - update_file, - validate_packagename, -) +import os +import re def pre_theme_name(configurator, question): diff --git a/bobtemplates/plone/upgrade_step.py b/bobtemplates/plone/upgrade_step.py index 3786f02f4..8373282d0 100644 --- a/bobtemplates/plone/upgrade_step.py +++ b/bobtemplates/plone/upgrade_step.py @@ -1,14 +1,11 @@ # -*- coding: utf-8 -*- +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import remove_unwanted_files +from bobtemplates.plone.base import update_configure_zcml from lxml import etree -from bobtemplates.plone.base import ( - base_prepare_renderer, - git_commit, - remove_unwanted_files, - update_configure_zcml, -) - def _update_package_configure_zcml(configurator): path = "{0}".format( diff --git a/bobtemplates/plone/utils.py b/bobtemplates/plone/utils.py index 287ce516c..d27977bb6 100644 --- a/bobtemplates/plone/utils.py +++ b/bobtemplates/plone/utils.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- +from bobtemplates.plone.base import _get_package_root_folder + import re +import six import subprocess import unicodedata -import six - -from bobtemplates.plone.base import _get_package_root_folder - def safe_unicode(value, encoding="utf-8"): """Converts a value to unicode, even it is already a unicode string.""" diff --git a/bobtemplates/plone/view.py b/bobtemplates/plone/view.py index c15b2bbfa..6d418a5e6 100644 --- a/bobtemplates/plone/view.py +++ b/bobtemplates/plone/view.py @@ -1,22 +1,21 @@ # -*- coding: utf-8 -*- """Generate view.""" -import os +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import CONTENT_TYPE_INTERFACES +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import ZCML_NAMESPACES +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort +from lxml import etree +from mrbob.bobexceptions import SkipQuestion +from mrbob.bobexceptions import ValidationError import case_conversion as cc +import os import six -from lxml import etree -from mrbob.bobexceptions import SkipQuestion, ValidationError - -from bobtemplates.plone.base import ( - CONTENT_TYPE_INTERFACES, - ZCML_NAMESPACES, - base_prepare_renderer, - echo, - git_commit, - update_file, -) -from bobtemplates.plone.utils import run_black, run_isort def get_view_name_from_python_class(configurator, question): diff --git a/bobtemplates/plone/viewlet.py b/bobtemplates/plone/viewlet.py index 68bd35627..c10c8f858 100644 --- a/bobtemplates/plone/viewlet.py +++ b/bobtemplates/plone/viewlet.py @@ -1,19 +1,17 @@ # -*- coding: utf-8 -*- """Generate view.""" -import os - -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import ZCML_NAMESPACES +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort from lxml import etree from mrbob.bobexceptions import SkipQuestion -from bobtemplates.plone.base import ( - ZCML_NAMESPACES, - base_prepare_renderer, - git_commit, - update_file, -) -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc +import os def get_view_name_from_python_class(configurator, question): diff --git a/bobtemplates/plone/vocabulary.py b/bobtemplates/plone/vocabulary.py index 7c4ffd24d..b2b176409 100644 --- a/bobtemplates/plone/vocabulary.py +++ b/bobtemplates/plone/vocabulary.py @@ -1,18 +1,16 @@ # -*- coding: utf-8 -*- -import os - -import case_conversion as cc +from bobtemplates.plone.base import base_prepare_renderer +from bobtemplates.plone.base import echo +from bobtemplates.plone.base import git_commit +from bobtemplates.plone.base import update_file +from bobtemplates.plone.base import ZCML_NAMESPACES +from bobtemplates.plone.utils import run_black +from bobtemplates.plone.utils import run_isort from lxml import etree -from bobtemplates.plone.base import ( - ZCML_NAMESPACES, - base_prepare_renderer, - echo, - git_commit, - update_file, -) -from bobtemplates.plone.utils import run_black, run_isort +import case_conversion as cc +import os def _update_package_configure_zcml(configurator): diff --git a/constraints.txt b/constraints.txt index fe69544cc..434758afb 100644 --- a/constraints.txt +++ b/constraints.txt @@ -5,6 +5,6 @@ setuptools==57.0.0 tox>=3.6 isort>=5 flake8>=5.0.4 -black==22.8.0 +black==22.10.0 pytest>=4.3.0 coverage>=5.2.0 diff --git a/package_tests/test_addon.py b/package_tests/test_addon.py index 0e23459e7..6158b7d59 100644 --- a/package_tests/test_addon.py +++ b/package_tests/test_addon.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -import os - +from bobtemplates.plone import addon +from bobtemplates.plone import base from mrbob.configurator import Configurator -from bobtemplates.plone import addon, base +import os def test_pre_render(tmpdir): diff --git a/package_tests/test_base.py b/package_tests/test_base.py index 712328282..6f6c4f56d 100644 --- a/package_tests/test_base.py +++ b/package_tests/test_base.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -import os - -import pytest +from bobtemplates.plone import base from mrbob.bobexceptions import ValidationError from mrbob.configurator import Configurator -from bobtemplates.plone import base +import os +import pytest def test_to_boolean(): diff --git a/package_tests/test_behavior.py b/package_tests/test_behavior.py index 16fb7df87..1f4ecc4e8 100644 --- a/package_tests/test_behavior.py +++ b/package_tests/test_behavior.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -import os - +from bobtemplates.plone import base +from bobtemplates.plone import behavior from mrbob.configurator import Configurator -from bobtemplates.plone import base, behavior +import os def test_prepare_renderer(): diff --git a/package_tests/test_buildout.py b/package_tests/test_buildout.py index 2fa161906..34bf4e79b 100644 --- a/package_tests/test_buildout.py +++ b/package_tests/test_buildout.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- -from mrbob.configurator import Configurator - from bobtemplates.plone import buildout +from mrbob.configurator import Configurator def test_prepare_renderer(): diff --git a/package_tests/test_content_type.py b/package_tests/test_content_type.py index 111069eed..3ab56e2f7 100644 --- a/package_tests/test_content_type.py +++ b/package_tests/test_content_type.py @@ -2,13 +2,14 @@ """Test dexterity content type generation.""" -import os - -import pytest -from mrbob.bobexceptions import SkipQuestion, ValidationError +from bobtemplates.plone import base +from bobtemplates.plone import content_type +from mrbob.bobexceptions import SkipQuestion +from mrbob.bobexceptions import ValidationError from mrbob.configurator import Configurator -from bobtemplates.plone import base, content_type +import os +import pytest def test_post_dexterity_type_name(): diff --git a/package_tests/test_indexer.py b/package_tests/test_indexer.py index 9541c611b..6d909b33e 100644 --- a/package_tests/test_indexer.py +++ b/package_tests/test_indexer.py @@ -2,15 +2,14 @@ """Test view generation.""" -import os - -import pytest +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import indexer from mrbob.bobexceptions import ValidationError from mrbob.configurator import Configurator -from bobtemplates.plone import base, indexer - -from .base import init_package_base_structure +import os +import pytest def test_update_indexers_configure_zcml(tmpdir): diff --git a/package_tests/test_mockup_pattern.py b/package_tests/test_mockup_pattern.py index 5bae83d9f..a430bc99d 100644 --- a/package_tests/test_mockup_pattern.py +++ b/package_tests/test_mockup_pattern.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- -import os - -import pytest +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import mockup_pattern from mrbob.bobexceptions import ValidationError from mrbob.configurator import Configurator -from bobtemplates.plone import base, mockup_pattern - -from .base import init_package_base_structure +import os +import pytest def test_pre_render(tmpdir): diff --git a/package_tests/test_portlet.py b/package_tests/test_portlet.py index d72ef0c47..29e101f3d 100644 --- a/package_tests/test_portlet.py +++ b/package_tests/test_portlet.py @@ -2,13 +2,13 @@ """Test view generation.""" -import os - -import pytest +from bobtemplates.plone import base +from bobtemplates.plone import portlet from mrbob.bobexceptions import ValidationError from mrbob.configurator import Configurator -from bobtemplates.plone import base, portlet +import os +import pytest def test_pre_renderer(): diff --git a/package_tests/test_restapi_serializer.py b/package_tests/test_restapi_serializer.py index 4212fbbc6..648801f5e 100644 --- a/package_tests/test_restapi_serializer.py +++ b/package_tests/test_restapi_serializer.py @@ -8,40 +8,40 @@ def test_pre_renderer(tmpdir): - target_path = tmpdir.strpath + '/collective.todo' - package_path = target_path + '/src/collective/todo' + target_path = tmpdir.strpath + "/collective.todo" + package_path = target_path + "/src/collective/todo" os.makedirs(target_path) os.makedirs(package_path) template = """ [main] version=5.1 """ - with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + with open(os.path.join(target_path + "/bobtemplate.cfg"), "w") as f: f.write(template) template = """ dummy '-*- Extra requirements: -*-' """ - with open(os.path.join(target_path + '/setup.py'), 'w') as f: + with open(os.path.join(target_path + "/setup.py"), "w") as f: f.write(template) configurator = Configurator( - template='bobtemplates.plone:restapi_service', + template="bobtemplates.plone:restapi_service", target_directory=target_path, variables={ - 'service_class_name': 'SomeRelatedThings', - 'service_name': 'some-related-things', - 'package_folder': package_path, + "service_class_name": "SomeRelatedThings", + "service_name": "some-related-things", + "package_folder": package_path, }, ) restapi_service.pre_renderer(configurator) def test_post_renderer(tmpdir): - target_path = tmpdir.strpath + '/collective.todo' - package_path = target_path + '/src/collective/todo' - profiles_path = package_path + '/profiles/default' + target_path = tmpdir.strpath + "/collective.todo" + package_path = target_path + "/src/collective/todo" + profiles_path = package_path + "/profiles/default" os.makedirs(target_path) os.makedirs(package_path) os.makedirs(profiles_path) @@ -54,21 +54,21 @@ def test_post_renderer(tmpdir): """ - with open(os.path.join(profiles_path + '/metadata.xml'), 'w') as f: + with open(os.path.join(profiles_path + "/metadata.xml"), "w") as f: f.write(template) template = """ [main] version=5.1 """ - with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + with open(os.path.join(target_path + "/bobtemplate.cfg"), "w") as f: f.write(template) template = """ dummy '-*- Extra requirements: -*-' """ - with open(os.path.join(target_path + '/setup.py'), 'w') as f: + with open(os.path.join(target_path + "/setup.py"), "w") as f: f.write(template) template = """ @@ -82,20 +82,20 @@ def test_post_renderer(tmpdir): """ - with open(os.path.join(package_path + '/configure.zcml'), 'w') as f: + with open(os.path.join(package_path + "/configure.zcml"), "w") as f: f.write(template) configurator = Configurator( - template='bobtemplates.plone:restapi_service', + template="bobtemplates.plone:restapi_service", target_directory=package_path, bobconfig={ - 'non_interactive': True, + "non_interactive": True, }, variables={ - 'package_folder': package_path, - 'plone.version': '5.1', - 'service_class_name': 'SomeRelatedThings', - 'service_name': 'some-related-things', + "package_folder": package_path, + "plone.version": "5.1", + "service_class_name": "SomeRelatedThings", + "service_name": "some-related-things", }, ) assert configurator @@ -108,17 +108,17 @@ def test_post_renderer(tmpdir): def test_remove_unwanted_files(tmpdir): files_to_remove = [ - '/api/configure.zcml.example', - '/api/services/configure.zcml.example', + "/api/configure.zcml.example", + "/api/services/configure.zcml.example", ] - target_path = tmpdir.strpath + '/collective.todo' - package_path = target_path + '/src/collective/todo' - os.makedirs(package_path + '/api/services/') + target_path = tmpdir.strpath + "/collective.todo" + package_path = target_path + "/src/collective/todo" + os.makedirs(package_path + "/api/services/") configurator = Configurator( - template='bobtemplates.plone:restapi_service', + template="bobtemplates.plone:restapi_service", target_directory=tmpdir.strpath, variables={ - 'package_folder': package_path, + "package_folder": package_path, }, ) for file_to_remove in files_to_remove: @@ -126,9 +126,9 @@ def test_remove_unwanted_files(tmpdir): os.path.join( package_path + file_to_remove, ), - 'w', + "w", ) as f: - f.write(u'dummy') + f.write("dummy") restapi_service._remove_unwanted_files(configurator) for file_to_remove in files_to_remove: @@ -138,24 +138,23 @@ def test_remove_unwanted_files(tmpdir): def test_update_api_configure_zcml(tmpdir): - """ - """ - target_path = tmpdir.strpath + '/collective.todo' - package_path = target_path + '/src/collective/todo' - os.makedirs(package_path + '/api/') + """ """ + target_path = tmpdir.strpath + "/collective.todo" + package_path = target_path + "/src/collective/todo" + os.makedirs(package_path + "/api/") template = """ [main] version=5.1 """ - with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + with open(os.path.join(target_path + "/bobtemplate.cfg"), "w") as f: f.write(template) template = """ dummy '-*- Extra requirements: -*-' """ - with open(os.path.join(target_path + '/setup.py'), 'w') as f: + with open(os.path.join(target_path + "/setup.py"), "w") as f: f.write(template) template = """ @@ -169,54 +168,53 @@ def test_update_api_configure_zcml(tmpdir): """ - with open(os.path.join(package_path + '/configure.zcml'), 'w') as f: + with open(os.path.join(package_path + "/configure.zcml"), "w") as f: f.write(template) - with open(os.path.join(package_path + '/api/configure.zcml'), 'w') as f: + with open(os.path.join(package_path + "/api/configure.zcml"), "w") as f: f.write(template) configurator = Configurator( - template='bobtemplates.plone:restapi_service', + template="bobtemplates.plone:restapi_service", target_directory=package_path, bobconfig={ - 'non_interactive': True, + "non_interactive": True, }, variables={ - 'package_folder': package_path, - 'plone.version': '5.1', - 'service_class_name': 'SomeRelatedThings', - 'service_name': 'some-related-things', + "package_folder": package_path, + "plone.version": "5.1", + "service_class_name": "SomeRelatedThings", + "service_name": "some-related-things", }, ) restapi_service._update_api_configure_zcml(configurator) with open( os.path.join( - package_path + '/api/configure.zcml', + package_path + "/api/configure.zcml", ), - 'r', + "r", ) as f: content = f.read() - assert content != template, u'configure.zcml was not updated!' + assert content != template, "configure.zcml was not updated!" def test_update_services_configure_zcml(tmpdir): - """ - """ - target_path = tmpdir.strpath + '/collective.todo' - package_path = target_path + '/src/collective/todo' - os.makedirs(package_path + '/api/services/') + """ """ + target_path = tmpdir.strpath + "/collective.todo" + package_path = target_path + "/src/collective/todo" + os.makedirs(package_path + "/api/services/") template = """ [main] version=5.1 """ - with open(os.path.join(target_path + '/bobtemplate.cfg'), 'w') as f: + with open(os.path.join(target_path + "/bobtemplate.cfg"), "w") as f: f.write(template) template = """ dummy '-*- Extra requirements: -*-' """ - with open(os.path.join(target_path + '/setup.py'), 'w') as f: + with open(os.path.join(target_path + "/setup.py"), "w") as f: f.write(template) template = """ @@ -230,35 +228,36 @@ def test_update_services_configure_zcml(tmpdir): """ - with open(os.path.join(package_path + '/configure.zcml'), 'w') as f: + with open(os.path.join(package_path + "/configure.zcml"), "w") as f: f.write(template) - with open(os.path.join(package_path + '/api/configure.zcml'), 'w') as f: + with open(os.path.join(package_path + "/api/configure.zcml"), "w") as f: f.write(template) with open( - os.path.join(package_path + '/api/services/configure.zcml'), 'w', + os.path.join(package_path + "/api/services/configure.zcml"), + "w", ) as f: f.write(template) configurator = Configurator( - template='bobtemplates.plone:restapi_service', + template="bobtemplates.plone:restapi_service", target_directory=package_path, bobconfig={ - 'non_interactive': True, + "non_interactive": True, }, variables={ - 'package_folder': package_path, - 'plone.version': '5.1', - 'service_class_name': 'SomeRelatedThings', - 'service_class_name_normalized': 'some_related_things', - 'service_name': 'some-related-things', + "package_folder": package_path, + "plone.version": "5.1", + "service_class_name": "SomeRelatedThings", + "service_class_name_normalized": "some_related_things", + "service_name": "some-related-things", }, ) restapi_service._update_services_configure_zcml(configurator) with open( os.path.join( - package_path + '/api/services/configure.zcml', + package_path + "/api/services/configure.zcml", ), - 'r', + "r", ) as f: content = f.read() - assert content != template, u'configure.zcml was not updated!' + assert content != template, "configure.zcml was not updated!" diff --git a/package_tests/test_restapi_service.py b/package_tests/test_restapi_service.py index fb9270b03..648801f5e 100644 --- a/package_tests/test_restapi_service.py +++ b/package_tests/test_restapi_service.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -import os - +from bobtemplates.plone import base +from bobtemplates.plone import restapi_service from mrbob.configurator import Configurator -from bobtemplates.plone import base, restapi_service +import os def test_pre_renderer(tmpdir): diff --git a/package_tests/test_subscriber.py b/package_tests/test_subscriber.py index 0ac92f694..9b69daef2 100644 --- a/package_tests/test_subscriber.py +++ b/package_tests/test_subscriber.py @@ -2,14 +2,13 @@ """Test view generation.""" -import os - -import pytest +# from bobtemplates.plone import base +from bobtemplates.plone import subscriber from mrbob.bobexceptions import ValidationError from mrbob.configurator import Configurator -# from bobtemplates.plone import base -from bobtemplates.plone import subscriber +import os +import pytest def test_update_subscribers_configure_zcml(tmpdir): diff --git a/package_tests/test_svelte_app.py b/package_tests/test_svelte_app.py index 4781926e4..8ef66ba63 100644 --- a/package_tests/test_svelte_app.py +++ b/package_tests/test_svelte_app.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- -import os - -import pytest +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import svelte_app from mrbob.bobexceptions import ValidationError -from mrbob.configurator import Configurator, Question +from mrbob.configurator import Configurator +from mrbob.configurator import Question -from bobtemplates.plone import base, svelte_app - -from .base import init_package_base_structure +import os +import pytest def test_prep_renderer(tmpdir): diff --git a/package_tests/test_theme.py b/package_tests/test_theme.py index 4bea99c11..cd98038c8 100644 --- a/package_tests/test_theme.py +++ b/package_tests/test_theme.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- -import os - -import pytest +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import theme from mrbob.bobexceptions import ValidationError -from mrbob.configurator import Configurator, Question +from mrbob.configurator import Configurator +from mrbob.configurator import Question -from bobtemplates.plone import base, theme - -from .base import init_package_base_structure +import os +import pytest def test_pre_theme_name(tmpdir): diff --git a/package_tests/test_theme_barceloneta.py b/package_tests/test_theme_barceloneta.py index bcfbb811f..bcd2dd027 100644 --- a/package_tests/test_theme_barceloneta.py +++ b/package_tests/test_theme_barceloneta.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- -import os - -import pytest +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import theme_barceloneta from mrbob.bobexceptions import ValidationError -from mrbob.configurator import Configurator, Question +from mrbob.configurator import Configurator +from mrbob.configurator import Question -from bobtemplates.plone import base, theme_barceloneta - -from .base import init_package_base_structure +import os +import pytest def test_pre_theme_name(): diff --git a/package_tests/test_theme_basic.py b/package_tests/test_theme_basic.py index 7c71d5ae7..8482d8054 100644 --- a/package_tests/test_theme_basic.py +++ b/package_tests/test_theme_basic.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- -import os - -import pytest +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import theme_basic from mrbob.bobexceptions import ValidationError -from mrbob.configurator import Configurator, Question +from mrbob.configurator import Configurator +from mrbob.configurator import Question -from bobtemplates.plone import base, theme_basic - -from .base import init_package_base_structure +import os +import pytest def test_pre_theme_name(): diff --git a/package_tests/test_upgrade_step.py b/package_tests/test_upgrade_step.py index ae12781d9..237e600ea 100644 --- a/package_tests/test_upgrade_step.py +++ b/package_tests/test_upgrade_step.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -import os - +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import upgrade_step from mrbob.configurator import Configurator -from bobtemplates.plone import base, upgrade_step - -from .base import init_package_base_structure +import os def test_pre_renderer(tmpdir): diff --git a/package_tests/test_view.py b/package_tests/test_view.py index 603d3aebb..d3d99c678 100644 --- a/package_tests/test_view.py +++ b/package_tests/test_view.py @@ -2,15 +2,16 @@ """Test view generation.""" -import os +from .base import init_package_base_structure +from bobtemplates.plone import base +from bobtemplates.plone import view +from mrbob.bobexceptions import SkipQuestion +from mrbob.bobexceptions import ValidationError +from mrbob.configurator import Configurator +from mrbob.configurator import Question +import os import pytest -from mrbob.bobexceptions import SkipQuestion, ValidationError -from mrbob.configurator import Configurator, Question - -from bobtemplates.plone import base, view - -from .base import init_package_base_structure def test_get_view_name(): diff --git a/package_tests/test_viewlet.py b/package_tests/test_viewlet.py index 439ea279f..1b3f90cf3 100644 --- a/package_tests/test_viewlet.py +++ b/package_tests/test_viewlet.py @@ -2,13 +2,15 @@ """Test view generation.""" -import os +from bobtemplates.plone import base +from bobtemplates.plone import viewlet +from mrbob.bobexceptions import SkipQuestion +from mrbob.bobexceptions import ValidationError +from mrbob.configurator import Configurator +from mrbob.configurator import Question +import os import pytest -from mrbob.bobexceptions import SkipQuestion, ValidationError -from mrbob.configurator import Configurator, Question - -from bobtemplates.plone import base, viewlet def test_get_view_name_default(): diff --git a/package_tests/test_vocabulary.py b/package_tests/test_vocabulary.py index 1313a4bfd..785fcf1d5 100644 --- a/package_tests/test_vocabulary.py +++ b/package_tests/test_vocabulary.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -import os - +from bobtemplates.plone import base +from bobtemplates.plone import vocabulary from mrbob.configurator import Configurator -from bobtemplates.plone import base, vocabulary +import os def test_prepare_renderer(): diff --git a/setup.cfg b/setup.cfg index 3e5959995..670cdfe38 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,7 +14,7 @@ ignore = .gitattributes [isort] -profile = black +profile = plone [flake8] ignore = diff --git a/setup.py b/setup.py index 16a670435..73031a6cc 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- -from setuptools import find_packages, setup +from setuptools import find_packages +from setuptools import setup + version = "6.0b14.dev0" @@ -74,6 +76,7 @@ "plone_mockup_pattern = bobtemplates.plone.bobregistry:plone_mockup_pattern", "plone_portlet = bobtemplates.plone.bobregistry:plone_portlet", "plone_restapi_service = bobtemplates.plone.bobregistry:plone_restapi_service", # NOQA E501 + "plone_restapi_serializer = bobtemplates.plone.bobregistry:plone_restapi_serializer", # NOQA E501 "plone_svelte_app = bobtemplates.plone.bobregistry:plone_svelte_app", "plone_subscriber = bobtemplates.plone.bobregistry:plone_subscriber", "plone_theme = bobtemplates.plone.bobregistry:plone_theme", diff --git a/skeleton-tests/base.py b/skeleton-tests/base.py index 5324ad432..fd338cdbd 100644 --- a/skeleton-tests/base.py +++ b/skeleton-tests/base.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- # from bobtemplates.plone.utils import safe_encode +from bobtemplates.plone.utils import safe_unicode + import contextlib import logging import os import subprocess -from bobtemplates.plone.utils import safe_unicode logger = logging.getLogger("skeleton-tests") diff --git a/skeleton-tests/conftest.py b/skeleton-tests/conftest.py index 0e2a97da0..022ec222c 100644 --- a/skeleton-tests/conftest.py +++ b/skeleton-tests/conftest.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import os - import pytest diff --git a/skeleton-tests/test_addon.py b/skeleton-tests/test_addon.py index 8a596c1e8..c509ad4e3 100644 --- a/skeleton-tests/test_addon.py +++ b/skeleton-tests/test_addon.py @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- +from base import file_exists +from base import generate_answers_ini +from base import run_skeleton_tox_env + import glob import os.path import subprocess -from base import file_exists, generate_answers_ini, run_skeleton_tox_env base_files = [ ".editorconfig", diff --git a/skeleton-tests/test_addon_all.py b/skeleton-tests/test_addon_all.py index 0278332b1..6951c407c 100644 --- a/skeleton-tests/test_addon_all.py +++ b/skeleton-tests/test_addon_all.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- +from base import file_exists +from base import generate_answers_ini +from base import run_skeleton_tox_env + import os.path import subprocess -from base import file_exists, generate_answers_ini, run_skeleton_tox_env - def test_addon_all(tmpdir, capsys, config): answers_init_path = os.path.join(tmpdir.strpath, "answers.ini") diff --git a/skeleton-tests/test_addon_mockup_pattern.py b/skeleton-tests/test_addon_mockup_pattern.py index 5140d21e3..de08ae25b 100644 --- a/skeleton-tests/test_addon_mockup_pattern.py +++ b/skeleton-tests/test_addon_mockup_pattern.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- +from base import file_exists +from base import generate_answers_ini +from base import run_skeleton_tox_env +from mrbob.cli import main + import os import re -from base import file_exists, generate_answers_ini, run_skeleton_tox_env -from mrbob.cli import main - def test_addon_pattern(tmpdir, capsys, config): answers_ini_path = os.path.join(tmpdir.strpath, "answers.ini") diff --git a/skeleton-tests/test_addon_theme_barceloneta.py b/skeleton-tests/test_addon_theme_barceloneta.py index 6abe57ea7..7c1d435d0 100644 --- a/skeleton-tests/test_addon_theme_barceloneta.py +++ b/skeleton-tests/test_addon_theme_barceloneta.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- +from base import file_exists +from base import generate_answers_ini +from base import run_skeleton_tox_env + import os.path import subprocess -from base import file_exists, generate_answers_ini, run_skeleton_tox_env - def test_addon_theme(tmpdir, capsys, config): answers_init_path = os.path.join(tmpdir.strpath, "answers.ini")