diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml new file mode 100644 index 0000000..9e7ec42 --- /dev/null +++ b/.github/workflows/pythonpublish.yml @@ -0,0 +1,26 @@ +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/.gitignore b/.gitignore index d09b336..a9ca840 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ parts/ sdist/ var/ wheels/ +share/python-wheels/ *.egg-info/ .installed.cfg *.egg @@ -43,14 +44,17 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ +.nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover +*.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo @@ -60,6 +64,7 @@ coverage.xml *.log local_settings.py db.sqlite3 +db.sqlite3-journal # Flask stuff: instance/ @@ -72,16 +77,34 @@ instance/ docs/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints +# IPython +profile_default/ +ipython_config.py + # pyenv -.python-version +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock -# celery beat schedule file +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff celerybeat-schedule +celerybeat.pid # SageMath parsed files *.sage.py @@ -107,6 +130,17 @@ venv.bak/ # mypy .mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ # VirtualEnv rules # Virtualenv @@ -140,6 +174,7 @@ pip-selfcheck.json # Windows rules # Windows thumbnail cache files Thumbs.db +Thumbs.db:encryptable ehthumbs.db ehthumbs_vista.db @@ -238,9 +273,14 @@ flycheck_*.el # directory configuration .dir-locals.el +# network security +/network-security.data + + # Vim rules # Swap [._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files [._]*.sw[a-p] [._]s[a-rt-v][a-z] [._]ss[a-gi-z] @@ -248,6 +288,7 @@ flycheck_*.el # Session Session.vim +Sessionx.vim # Temporary .netrwhist @@ -258,7 +299,7 @@ tags [._]*.un~ # JetBrains rules -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff @@ -268,6 +309,9 @@ tags .idea/**/dictionaries .idea/**/shelf +# Generated files +.idea/**/contentModel.xml + # Sensitive or high-churn files .idea/**/dataSources/ .idea/**/dataSources.ids @@ -281,6 +325,19 @@ tags .idea/**/gradle.xml .idea/**/libraries +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + # CMake cmake-build-*/ @@ -311,6 +368,9 @@ fabric.properties # Editor-based Rest Client .idea/httpRequests +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + # SublimeText rules # Cache files for Sublime Text *.tmlanguage.cache @@ -326,6 +386,7 @@ fabric.properties # SFTP configuration file sftp-config.json +sftp-config-alt*.json # Package control specific files Package Control.last-run @@ -363,6 +424,10 @@ tmtags !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ # Xcode rules # Xcode @@ -389,8 +454,10 @@ DerivedData/ *.perspectivev3 !default.perspectivev3 -# Eclipse rules +## Gcc Patch +/*.gcno +# Eclipse rules .metadata bin/ tmp/ @@ -441,12 +508,17 @@ local.properties # Annotation Processing .apt_generated/ +.apt_generated_test/ # Scala IDE specific (Scala & Java development for Eclipse) .cache-main .scala_dependencies .worksheet +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + # TortoiseGit rules # Project-level settings /.tgitconfig diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..8b406be --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,12 @@ +[settings] +line_length=79 +# Ignore generated files +skip=setup.py, moban/__init__.py +known_third_party=airspeed, moban, lml,ยง mock, nose +indent=' ' +multi_line_output=3 +length_sort=1 +include_trailing_comma=true +default_section=FIRSTPARTY +no_lines_before=LOCALFOLDER +sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER diff --git a/.moban.d/CUSTOM_README.rst.jj2 b/.moban.d/CUSTOM_README.rst.jj2 index 09b6cd1..92f630b 100644 --- a/.moban.d/CUSTOM_README.rst.jj2 +++ b/.moban.d/CUSTOM_README.rst.jj2 @@ -5,5 +5,8 @@ {% block features %} With `airspeed` for Python 3, this library allows moban users to have velocity -template in their next documentation endeavour. +template in their next documentation endeavour. + +{%include "velocity_example.rst.jj2" %} + {% endblock %} diff --git a/.moban.d/custom_travis.yml.jj2 b/.moban.d/custom_travis.yml.jj2 new file mode 100644 index 0000000..6bbad02 --- /dev/null +++ b/.moban.d/custom_travis.yml.jj2 @@ -0,0 +1,8 @@ +{% extends 'travis.yml.jj2' %} + +{%block custom_python_versions%} +python: + - 3.7 + - 3.6 + - 3.8 +{%endblock%} diff --git a/.moban.d/tests/custom_requirements.txt.jj2 b/.moban.d/tests/custom_requirements.txt.jj2 index a22fe7e..6b56e5a 100644 --- a/.moban.d/tests/custom_requirements.txt.jj2 +++ b/.moban.d/tests/custom_requirements.txt.jj2 @@ -1,4 +1,7 @@ {% extends "tests/requirements.txt.jj2" %} {%block extras %} +moban +black;python_version>="3.6" +isort;python_version>="3.6" {%endblock%} diff --git a/.moban.d/velocity_example.rst.jj2 b/.moban.d/velocity_example.rst.jj2 new file mode 100644 index 0000000..251c6bb --- /dev/null +++ b/.moban.d/velocity_example.rst.jj2 @@ -0,0 +1,43 @@ +Given the following data.json: + +.. code-block:: + + {"people": + [ + {"name": "Bill", "age": 100}, + {"name": "Bob", "age": 90}, + {"name": "Mark", "age": 25} + ] + } + +And given the following velocity.template: + +.. code-block:: + + Old people: + #foreach ($person in $people) + #if($person.age > 70) + $person.name + #end + #end + + Third person is $people[2].name + +**moban** can do the template: + +.. code-block:: bash + + $ moban --template-type velocity -c data.json -t velocity.template + Velocity-templating vo.t to moban.output + Velocity-templated 1 file. + $ cat moban.output + Old people: + + Bill + + Bob + + + Third person is Mark + + diff --git a/.moban.yml b/.moban.yml index 2fc785b..c23ea23 100644 --- a/.moban.yml +++ b/.moban.yml @@ -1,8 +1,7 @@ -requires: - - pypi-mobans-pkg==0.0.2 configuration: template_dir: - - "pypi-mobans-pkg:templates" + - "git://github.com/moremoban/pypi-mobans?submodule=true&branch=dev!/templates" + - "git://github.com/moremoban/pypi-mobans?submodule=true&branch=dev!/statics" - ".moban.d" configuration: moban-velocity.yml targets: @@ -14,8 +13,12 @@ targets: - test.sh: test.script.jj2 - "moban_velocity/_version.py": "_version.py.jj2" - .gitignore: gitignore.jj2 - - .travis.yml: travis.yml.jj2 + - .travis.yml: custom_travis.yml.jj2 - Pipfile: Pipfile.jj2 - output: CHANGELOG.rst configuration: changelog.yml - template: CHANGELOG.rst.jj2 \ No newline at end of file + template: CHANGELOG.rst.jj2 + - lint.sh: lint.script.jj2 + - LICENSE: "mit_license.jj2" + - MANIFEST.in: MANIFEST.in.jj2 + - ".github/workflows/pythonpublish.yml": "pythonpublish.yml" diff --git a/.travis.yml b/.travis.yml index 8295c53..e83fb22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,51 @@ sudo: false +dist: xenial language: python notifications: email: false python: - - pypy-5.3.1 - - 3.7-dev + - 3.7 - 3.6 - - 3.5 - - 3.4 - - 2.7 + - 3.8 + +stages: + - lint + - moban + - test + + +.lint: &lint + git: + submodules: false + python: 3.6 + env: + - MINREQ=0 + stage: lint + script: make install_test lint format git-diff-check + +.moban: &moban + python: 3.6 + env: + - MINREQ=0 + stage: moban + install: pip install moban>=0.0.4 gitfs2 pypifs + script: + - moban + - git diff --exit-code + +jobs: + include: + - *moban + - *lint + +stage: test + before_install: - - if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install flake8==2.6.2; fi - if [[ -f min_requirements.txt && "$MINREQ" -eq 1 ]]; then mv min_requirements.txt requirements.txt ; fi - - test ! -f rnd_requirements.txt || pip install --no-deps -r rnd_requirements.txt + - test ! -f rnd_requirements.txt || + pip install --no-deps -r rnd_requirements.txt - test ! -f rnd_requirements.txt || pip install -r rnd_requirements.txt ; - pip install -r tests/requirements.txt script: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8b375c6..f94fcec 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,10 +1,16 @@ Change log ================================================================================ +0.0.2 - 03.06.2020 +-------------------------------------------------------------------------------- + +**Added** + +#. Support moban v0.6.0+ + 0.0.1 - 02.02.2018 -------------------------------------------------------------------------------- -First release -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**First release** #. Render .velocity, .vtl files for moban diff --git a/LICENSE b/LICENSE index 63e84ec..800e2f2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Moremoban dev team. (See Contributors for details) +Copyright (c) 2019-2020 Moremoban dev team and its contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/MANIFEST.in b/MANIFEST.in index 5f13ef0..e86ae54 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,6 @@ include README.rst +include LICENSE include CHANGELOG.rst +include CONTRIBUTORS.rst +recursive-include tests * +recursive-include docs * diff --git a/Makefile b/Makefile index 26d9b68..d7e640e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,19 @@ all: test -test: +test: lint bash test.sh -document: - bash document.sh +install_test: + pip install -r tests/requirements.txt + +git-diff-check: + git diff --exit-code + +lint: + bash lint.sh + +format: + bash format.sh + +git-diff-check: + git diff --exit-code diff --git a/Pipfile b/Pipfile index 1872188..2d3821d 100644 --- a/Pipfile +++ b/Pipfile @@ -7,5 +7,12 @@ name = 'pypi' python_version= '3.6' [packages] - lml>=0.0.7 - airspeed = "*" +lml = '>=0.0.7' +airspeed = "*" + +[dev-packages] +nose = "*" +mock = "*" +codecov = "*" +coverage = "*" +flake8 = "*" diff --git a/README.rst b/README.rst index 8a938d5..e26fe44 100644 --- a/README.rst +++ b/README.rst @@ -7,11 +7,63 @@ moban-velocity .. image:: https://codecov.io/github/moremoban/moban-velocity/coverage.png :target: https://codecov.io/github/moremoban/moban-velocity +.. image:: https://badge.fury.io/py/moban-velocity.svg + :target: https://pypi.org/project/moban-velocity +.. image:: https://pepy.tech/badge/moban-velocity/month + :target: https://pepy.tech/project/moban-velocity/month + +.. image:: https://img.shields.io/github/stars/moremoban/moban-velocity.svg?style=social&maxAge=3600&label=Star + :target: https://github.com/moremoban/moban-velocity/stargazers With `airspeed` for Python 3, this library allows moban users to have velocity -template in their next documentation endeavour. +template in their next documentation endeavour. + +Given the following data.json: + +.. code-block:: + + {"people": + [ + {"name": "Bill", "age": 100}, + {"name": "Bob", "age": 90}, + {"name": "Mark", "age": 25} + ] + } + +And given the following velocity.template: + +.. code-block:: + + Old people: + #foreach ($person in $people) + #if($person.age > 70) + $person.name + #end + #end + + Third person is $people[2].name + +**moban** can do the template: + +.. code-block:: bash + + $ moban --template-type velocity -c data.json -t velocity.template + Velocity-templating vo.t to moban.output + Velocity-templated 1 file. + $ cat moban.output + Old people: + + Bill + + Bob + + + Third person is Mark + + + Installation ================================================================================ diff --git a/changelog.yml b/changelog.yml index 3b83dc5..68644b0 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,6 +1,12 @@ name: moban-velocity organisation: moremoban releases: +- changes: + - action: Added + details: + - Support moban v0.6.0+ + date: 03.06.2020 + version: 0.0.2 - changes: - action: First release details: diff --git a/docs/source/conf.py b/docs/source/conf.py index 382190a..d7d3d14 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- -# # Configuration file for the Sphinx documentation builder. # -# This file does only contain a selection of the most common options. For a -# full list see the documentation: -# http://www.sphinx-doc.org/en/master/config +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- @@ -18,22 +16,16 @@ # -- Project information ----------------------------------------------------- -project = u'' -copyright = u'' -author = u'' - +project = '' +copyright = '' +author = 'Ayan Banerjee, C.W. et al' # The short X.Y version -version = u'' +version = '0.0.2' # The full version, including alpha/beta/rc tags -release = u'' - +release = '0.0.2' # -- General configuration --------------------------------------------------- -# If your documentation needs a minimal Sphinx version, state it here. -# -# needs_sphinx = '1.0' - # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. @@ -51,21 +43,11 @@ # The master toctree document. master_doc = '' -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = '' - # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. exclude_patterns = [] -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = None - # -- Options for HTML output ------------------------------------------------- @@ -74,98 +56,7 @@ # html_theme = 'alabaster' -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# -# html_theme_options = {} - # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['static'] - -# Custom sidebar templates, must be a dictionary that maps document names -# to template names. -# -# The default sidebars (for documents that don't match any pattern) are -# defined by theme itself. Builtin themes are using these templates by -# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', -# 'searchbox.html']``. -# -# html_sidebars = {} - - -# -- Options for HTMLHelp output --------------------------------------------- - -# Output file base name for HTML help builder. -htmlhelp_basename = 'doc' - - -# -- Options for LaTeX output ------------------------------------------------ - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, '.tex', u'', - u'', 'manual'), -] - - -# -- Options for manual page output ------------------------------------------ - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, '', u'', - [author], 1) -] - - -# -- Options for Texinfo output ---------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - (master_doc, '', u'', - author, '', 'One line description of project.', - 'Miscellaneous'), -] - - -# -- Options for Epub output ------------------------------------------------- - -# Bibliographic Dublin Core info. -epub_title = project - -# The unique identifier of the text. This can be a ISBN number -# or the project homepage. -# -# epub_identifier = '' - -# A unique identification for the text. -# -# epub_uid = '' - -# A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] \ No newline at end of file +html_static_path = ['static'] \ No newline at end of file diff --git a/format.sh b/format.sh new file mode 100644 index 0000000..988dd94 --- /dev/null +++ b/format.sh @@ -0,0 +1,3 @@ +isort -y $(find moban_velocity -name "*.py"|xargs echo) $(find tests -name "*.py"|xargs echo) +black -l 79 moban_velocity +black -l 79 tests diff --git a/lint.sh b/lint.sh new file mode 100644 index 0000000..976f745 --- /dev/null +++ b/lint.sh @@ -0,0 +1,2 @@ +pip install flake8 +flake8 . --exclude=.moban.d,docs,setup.py --builtins=unicode,xrange,long \ No newline at end of file diff --git a/moban-velocity.yml b/moban-velocity.yml index aa201b5..028ffe5 100644 --- a/moban-velocity.yml +++ b/moban-velocity.yml @@ -3,10 +3,11 @@ organisation: "moremoban" author: "Ayan Banerjee, C.W. et al" contact: "wangc_2011@hotmail.com" company: "Moremoban dev team and its contributors" -version: "0.0.1" -current_version: "0.0.1" -release: "0.0.1" -copyright_year: 2019 +version: "0.0.2" +current_version: "0.0.2" +release: "0.0.2" +copyright_year: 2019-2020 license: MIT dependencies: ["lml>=0.0.7", "airspeed"] description: "Provide velocity templating capability to moban" +lint_command: make install_test lint format git-diff-check \ No newline at end of file diff --git a/moban_velocity/__init__.py b/moban_velocity/__init__.py index 71e73ee..79835cc 100644 --- a/moban_velocity/__init__.py +++ b/moban_velocity/__init__.py @@ -1,15 +1,13 @@ # flake8: noqa -from lml.plugin import PluginInfo, PluginInfoChain import moban.constants as constants +from lml.plugin import PluginInfo, PluginInfoChain -from moban_velocity._version import __version__ -from moban_velocity._version import __author__ - +from moban_velocity._version import __author__, __version__ PluginInfoChain(__name__).add_a_plugin_instance( PluginInfo( constants.TEMPLATE_ENGINE_EXTENSION, "%s.engine.EngineVelocity" % __name__, - tags=["velocity","vtl",], + tags=["velocity", "vtl",], ) ) diff --git a/moban_velocity/_version.py b/moban_velocity/_version.py index e860cec..26e5ab7 100644 --- a/moban_velocity/_version.py +++ b/moban_velocity/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.0.1" +__version__ = "0.0.2" __author__ = "Ayan Banerjee, C.W. et al" diff --git a/moban_velocity/engine.py b/moban_velocity/engine.py index 4711f3e..e8a2140 100644 --- a/moban_velocity/engine.py +++ b/moban_velocity/engine.py @@ -1,19 +1,26 @@ -import codecs - from airspeed import Template -import moban.utils as utils +from moban.externals import file_system class EngineVelocity(object): - def __init__(self, template_dirs, extensions=None): - self.template_dirs = template_dirs + ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Velocity-templating" + ACTION_IN_PAST_TENSE = "Velocity-templated" + + def __init__(self, template_fs, options=None): + """ + template_fs is a multfs instance and gives you the power to load + a template from equiped template directories. + :param fs.multifs.MultiFS template_fs: a MultiFS instance or an FS + instance + :param options: a dictionary of potential parameters. + not used yet. + """ + self.template_fs = template_fs def get_template(self, template_file): - actual_file = utils.get_template_path( - self.template_dirs, template_file - ) - with codecs.open(actual_file, "r", encoding="utf-8") as source: - template = Template(source.read()) + template_file = file_system.to_unicode(template_file) + template = self.template_fs.readtext(template_file) + template = Template(template) return template def get_template_from_string(self, string): diff --git a/setup.py b/setup.py index 52f21bf..3a5239a 100644 --- a/setup.py +++ b/setup.py @@ -1,60 +1,81 @@ #!/usr/bin/env python3 -# Template by pypi-mobans +""" +Template by pypi-mobans +""" + import os import sys import codecs +import locale +import platform from shutil import rmtree from setuptools import Command, setup, find_packages PY2 = sys.version_info[0] == 2 PY26 = PY2 and sys.version_info[1] < 7 - -NAME = 'moban-velocity' -AUTHOR = 'Ayan Banerjee, C.W. et al' -VERSION = '0.0.1' -EMAIL = 'wangc_2011@hotmail.com' -LICENSE = 'MIT' +PY33 = sys.version_info < (3, 4) + +# Work around mbcs bug in distutils. +# http://bugs.python.org/issue10945 +# This work around is only if a project supports Python < 3.4 + +# Work around for locale not being set +try: + lc = locale.getlocale() + pf = platform.system() + if pf != "Windows" and lc == (None, None): + locale.setlocale(locale.LC_ALL, "C.UTF-8") +except (ValueError, UnicodeError, locale.Error): + locale.setlocale(locale.LC_ALL, "en_US.UTF-8") + +NAME = "moban-velocity" +AUTHOR = "Ayan Banerjee, C.W. et al" +VERSION = "0.0.2" +EMAIL = "wangc_2011@hotmail.com" +LICENSE = "MIT" DESCRIPTION = ( - 'Provide velocity templating capability to moban' + "Provide velocity templating capability to moban" ) -URL = 'https://github.com/moremoban/moban-velocity' -DOWNLOAD_URL = '%s/archive/0.0.1.tar.gz' % URL -FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst'] +URL = "https://github.com/moremoban/moban-velocity" +DOWNLOAD_URL = "%s/archive/0.0.2.tar.gz" % URL +FILES = ["README.rst", 'CONTRIBUTORS.rst', "CHANGELOG.rst"] KEYWORDS = [ - 'python', + "python", ] CLASSIFIERS = [ - 'Topic :: Software Development :: Libraries', - 'Programming Language :: Python', - 'Intended Audience :: Developers', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', + "Topic :: Software Development :: Libraries", + "Programming Language :: Python", + "Intended Audience :: Developers", + "Programming Language :: Python :: 2.6", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + ] + INSTALL_REQUIRES = [ - 'lml>=0.0.7', - 'airspeed', + "lml>=0.0.7", + "airspeed", ] SETUP_COMMANDS = {} - -PACKAGES = find_packages(exclude=['ez_setup', 'examples', 'tests']) +PACKAGES = find_packages(exclude=["ez_setup", "examples", "tests", "tests.*"]) EXTRAS_REQUIRE = { } # 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-velocity v0.0.1 ' + - "Find 0.0.1 in changelog for more details") -NO_GS_MESSAGE = ('Automatic github release is disabled. ' + - 'Please install gease to enable it.') +PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable) +GS_COMMAND = ("gs moban-velocity v0.0.2 " + + "Find 0.0.2 in changelog for more details") +NO_GS_MESSAGE = ("Automatic github release is disabled. " + + "Please install gease to enable it.") UPLOAD_FAILED_MSG = ( 'Upload failed. please run "%s" yourself.' % PUBLISH_COMMAND) HERE = os.path.abspath(os.path.dirname(__file__)) @@ -63,13 +84,13 @@ class PublishCommand(Command): """Support setup.py upload.""" - description = 'Build and publish the package on github and pypi' + description = "Build and publish the package on github and pypi" user_options = [] @staticmethod def status(s): """Prints things in bold.""" - print('\033[1m{0}\033[0m'.format(s)) + print("\033[1m{0}\033[0m".format(s)) def initialize_options(self): pass @@ -79,14 +100,14 @@ def finalize_options(self): def run(self): try: - self.status('Removing previous builds...') - rmtree(os.path.join(HERE, 'dist')) - rmtree(os.path.join(HERE, 'build')) - rmtree(os.path.join(HERE, 'moban_velocity.egg-info')) + self.status("Removing previous builds...") + rmtree(os.path.join(HERE, "dist")) + rmtree(os.path.join(HERE, "build")) + rmtree(os.path.join(HERE, "moban_velocity.egg-info")) except OSError: pass - self.status('Building Source and Wheel (universal) distribution...') + self.status("Building Source and Wheel (universal) distribution...") run_status = True if has_gease(): run_status = os.system(GS_COMMAND) == 0 @@ -94,13 +115,13 @@ def run(self): self.status(NO_GS_MESSAGE) if run_status: if os.system(PUBLISH_COMMAND) != 0: - self.status(UPLOAD_FAILED_MSG % PUBLISH_COMMAND) + self.status(UPLOAD_FAILED_MSG) sys.exit() SETUP_COMMANDS.update({ - 'publish': PublishCommand + "publish": PublishCommand }) @@ -129,7 +150,7 @@ def read_files(*files): def read(afile): """Read a file into setup""" the_relative_file = os.path.join(HERE, afile) - with codecs.open(the_relative_file, 'r', 'utf-8') as opened_file: + with codecs.open(the_relative_file, "r", "utf-8") as opened_file: content = filter_out_test_code(opened_file) content = "".join(list(content)) return content @@ -138,11 +159,11 @@ def read(afile): def filter_out_test_code(file_handle): found_test_code = False for line in file_handle.readlines(): - if line.startswith('.. testcode:'): + if line.startswith(".. testcode:"): found_test_code = True continue if found_test_code is True: - if line.startswith(' '): + if line.startswith(" "): continue else: empty_line = line.strip() @@ -152,15 +173,16 @@ def filter_out_test_code(file_handle): found_test_code = False yield line else: - for keyword in ['|version|', '|today|']: + for keyword in ["|version|", "|today|"]: if keyword in line: break else: yield line -if __name__ == '__main__': +if __name__ == "__main__": setup( + test_suite="tests", name=NAME, author=AUTHOR, version=VERSION, @@ -172,7 +194,7 @@ def filter_out_test_code(file_handle): license=LICENSE, keywords=KEYWORDS, extras_require=EXTRAS_REQUIRE, - tests_require=['nose'], + tests_require=["nose"], install_requires=INSTALL_REQUIRES, packages=PACKAGES, include_package_data=True, diff --git a/test.sh b/test.sh index e0fd5d0..3795439 100644 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ pip freeze -nosetests --with-coverage --cover-package moban_velocity --cover-package tests tests docs/source moban_velocity && flake8 . --exclude=.moban.d,docs --builtins=unicode,xrange,long +nosetests --with-coverage --cover-package moban_velocity --cover-package tests tests docs/source moban_velocity diff --git a/tests/requirements.txt b/tests/requirements.txt index c445df5..020e09e 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,5 +1,8 @@ nose -mock +mock;python_version<"3" codecov coverage flake8 +moban +black;python_version>="3.6" +isort;python_version>="3.6" diff --git a/tests/test_velocity_engine.py b/tests/test_velocity_engine.py index 4973641..02b8c8e 100644 --- a/tests/test_velocity_engine.py +++ b/tests/test_velocity_engine.py @@ -1,24 +1,25 @@ import os +from moban.core import ENGINES, plugins from nose.tools import eq_ -from moban.plugins import ENGINES, BaseEngine -from moban_velocity.engine import EngineVelocity + +plugins.make_sure_all_pkg_are_loaded() def test_velocity_engine_type(): engine = ENGINES.get_engine("velocity", [], "") - assert engine.engine_cls == EngineVelocity - pass + assert engine.engine.__class__.__name__ == "EngineVelocity" def test_velocity_file_test(): output = "test.txt" path = os.path.join("tests", "fixtures", "velocity_tests") - engine = BaseEngine(path, path, EngineVelocity) + engine = ENGINES.get_engine("velocity", [path], path) engine.render_to_file("file_tests.velocity", "file_tests.json", output) with open(output, "r") as output_file: - expected_path = os.path.join("tests", "fixtures", "velocity_tests", - "expected_output.txt") + expected_path = os.path.join( + "tests", "fixtures", "velocity_tests", "expected_output.txt" + ) with open(expected_path) as expected_file: expected = expected_file.read() content = output_file.read() @@ -30,7 +31,7 @@ def test_velocity_string_template(): string_template = "Hello $hello" output = "test.txt" path = os.path.join("tests", "fixtures", "velocity_tests") - engine = BaseEngine(path, path, EngineVelocity) + engine = ENGINES.get_engine("velocity", [path], path) engine.render_string_to_file(string_template, "file_tests.json", output) with open(output, "r") as output_file: expected = "Hello World!"