diff --git a/.gitignore b/.gitignore index 33211632..5ef0acc0 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ parts/ sdist/ var/ wheels/ +pip-wheel-metadata/ +share/python-wheels/ *.egg-info/ .installed.cfg *.egg @@ -43,6 +45,7 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ +.nox/ .coverage .coverage.* .cache @@ -77,9 +80,20 @@ target/ # Jupyter Notebook .ipynb_checkpoints +# IPython +profile_default/ +ipython_config.py + # pyenv .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 celerybeat-schedule @@ -107,6 +121,11 @@ venv.bak/ # mypy .mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ # VirtualEnv rules # Virtualenv @@ -238,6 +257,10 @@ flycheck_*.el # directory configuration .dir-locals.el +# network security +/network-security.data + + # Vim rules # Swap [._]*.s[a-v][a-z] @@ -268,6 +291,9 @@ tags .idea/**/dictionaries .idea/**/shelf +# Generated files +.idea/**/contentModel.xml + # Sensitive or high-churn files .idea/**/dataSources/ .idea/**/dataSources.ids @@ -281,6 +307,14 @@ 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/modules.xml +# .idea/*.iml +# .idea/modules + # CMake cmake-build-*/ @@ -311,6 +345,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 @@ -390,7 +427,6 @@ DerivedData/ !default.perspectivev3 # Eclipse rules - .metadata bin/ tmp/ @@ -488,3 +524,9 @@ docs/level-16-group-targets-using-template-type/test-dir/ docs/level-16-group-targets-using-template-type/test-recursive-dir/ docs/level-17-force-template-type-from-moban-file/test-dir/ docs/level-17-force-template-type-from-moban-file/test-recursive-dir/ +docs/level-11-use-handlebars/b.output +docs/level-14-custom-data-loader/b.output +docs/level-19-moban-a-sub-group-in-targets/test-dir/ +docs/level-19-moban-a-sub-group-in-targets/test-recursive-dir/ +docs/level-6-complex-configuration/a.output +docs/level-7-use-custom-jinja2-filter-test-n-global/filter.output diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 5be73210..6560d83d 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,11 +1,17 @@ name: moban organisation: moremoban releases: +- changes: + - action: Updated + details: + - "`#271`: support git branch change in later run." + date: 07.07.2019 + version: 0.4.5 - changes: - action: Updated details: - "`#265`: Use simple `read binary` to read instead of encoding" - date: 27.05.2019 + date: 26.05.2019 version: 0.4.4 - changes: - action: Removed diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 15b5d874..56490822 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -4,9 +4,9 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.4.4 -current_version: 0.4.4 -release: 0.4.3 +version: 0.4.5 +current_version: 0.4.5 +release: 0.4.5 branch: master master: index command_line_interface: "moban" @@ -27,3 +27,4 @@ dependencies: - giturlparse>=0.9.1 description: Yet another jinja2 cli command for static text generation scm_host: github.com +lint: sh lint.sh \ No newline at end of file diff --git a/.moban.d/moban_gitignore.jj2 b/.moban.d/moban_gitignore.jj2 index 856dc75a..3ed4a68e 100644 --- a/.moban.d/moban_gitignore.jj2 +++ b/.moban.d/moban_gitignore.jj2 @@ -19,4 +19,10 @@ docs/level-16-group-targets-using-template-type/test-dir/ docs/level-16-group-targets-using-template-type/test-recursive-dir/ docs/level-17-force-template-type-from-moban-file/test-dir/ docs/level-17-force-template-type-from-moban-file/test-recursive-dir/ +docs/level-11-use-handlebars/b.output +docs/level-14-custom-data-loader/b.output +docs/level-19-moban-a-sub-group-in-targets/test-dir/ +docs/level-19-moban-a-sub-group-in-targets/test-recursive-dir/ +docs/level-6-complex-configuration/a.output +docs/level-7-use-custom-jinja2-filter-test-n-global/filter.output {% endblock %} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 3fa8fc09..d7b0b96d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ + sudo: false dist: xenial language: python @@ -14,8 +15,34 @@ matrix: include: - python: 2.7 env: MINREQ=1 + +stages: + - test + - lint + +.disable_global: &disable_global + before_install: false + install: true + before_script: false + after_success: false + after_failure: false + +.lint: &lint + <<: *disable_global + python: 3.6 + stage: lint + install: pip install flake8 + script: sh lint.sh + +jobs: + include: + - *lint + +stage: test + +script: make 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 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2c21d304..b2a846a4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,16 @@ Change log ================================================================================ -0.4.4 - 27.05.2019 +0.4.5 - 07.07.2019 +-------------------------------------------------------------------------------- + +Updated +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#271 `_: support git branch + change in later run. + +0.4.4 - 26.05.2019 -------------------------------------------------------------------------------- Updated diff --git a/docs/conf.py b/docs/conf.py index b14bf239..018af81e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,12 +22,12 @@ # -- Project information ----------------------------------------------------- project = 'moban' -copyright = '2017-2019 Onni Software Ltd. and its contributors' -author = 'Onni Software Ltd.' +copyright = '2017-2019 Onni Software Ltd.' +author = 'C. W.' # The short X.Y version -version = '0.4.4' +version = '0.4.5' # The full version, including alpha/beta/rc tags -release = '0.4.3' +release = '0.4.5' # -- General configuration --------------------------------------------------- diff --git a/docs/level-10-moban-dependency-as-git-repo/README.rst b/docs/level-10-moban-dependency-as-git-repo/README.rst index 093fcc14..f96262aa 100644 --- a/docs/level-10-moban-dependency-as-git-repo/README.rst +++ b/docs/level-10-moban-dependency-as-git-repo/README.rst @@ -36,5 +36,6 @@ The alternative syntax is:: url: https://github.com/your-git-url submodule: true branch: your_choice_or_default_branch_if_not_specified + reference: your_alternative_reference_but_not_used_together_with_branch ... diff --git a/docs/level-14-custom-data-loader/custom-data-loader/custom.py b/docs/level-14-custom-data-loader/custom-data-loader/custom.py index 61813cce..f7c32dad 100644 --- a/docs/level-14-custom-data-loader/custom-data-loader/custom.py +++ b/docs/level-14-custom-data-loader/custom-data-loader/custom.py @@ -1,8 +1,7 @@ import csv -from lml.plugin import PluginInfo - from moban import constants +from lml.plugin import PluginInfo @PluginInfo(constants.DATA_LOADER_EXTENSION, tags=["custom"]) diff --git a/lint.sh b/lint.sh new file mode 100644 index 00000000..b53891e2 --- /dev/null +++ b/lint.sh @@ -0,0 +1 @@ +flake8 . --exclude=.moban.d,docs --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504 diff --git a/moban/_version.py b/moban/_version.py index cffb9330..de146422 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.4.4" +__version__ = "0.4.5" __author__ = "C. W." diff --git a/moban/constants.py b/moban/constants.py index 94f0bcfa..507ee903 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -95,6 +95,7 @@ GIT_HAS_SUBMODULE = "submodule" GIT_URL = "url" GIT_BRANCH = "branch" +GIT_REFERENCE = "reference" PYPI_REQUIRE = "PYPI" PYPI_PACKAGE_NAME = "name" REQUIRE_TYPE = "type" diff --git a/moban/copy/__init__.py b/moban/copy/__init__.py index 2b7f0c7b..1d197d1d 100644 --- a/moban/copy/__init__.py +++ b/moban/copy/__init__.py @@ -1,10 +1,7 @@ +from moban import utils, constants from lml.plugin import PluginInfo -from moban import utils -from moban import constants - - @PluginInfo( constants.TEMPLATE_ENGINE_EXTENSION, tags=[constants.TEMPLATE_COPY] ) diff --git a/moban/data_loaders/json_loader.py b/moban/data_loaders/json_loader.py index 30f57268..b5726fee 100644 --- a/moban/data_loaders/json_loader.py +++ b/moban/data_loaders/json_loader.py @@ -1,8 +1,7 @@ import json -from lml.plugin import PluginInfo - from moban import constants +from lml.plugin import PluginInfo @PluginInfo(constants.DATA_LOADER_EXTENSION, tags=["json"]) diff --git a/moban/data_loaders/manager.py b/moban/data_loaders/manager.py index 2e63c06b..3dd402a9 100644 --- a/moban/data_loaders/manager.py +++ b/moban/data_loaders/manager.py @@ -1,8 +1,7 @@ import os -from lml.plugin import PluginManager - from moban import utils, constants +from lml.plugin import PluginManager class AnyDataLoader(PluginManager): diff --git a/moban/data_loaders/yaml.py b/moban/data_loaders/yaml.py index c73feafb..8fce4710 100644 --- a/moban/data_loaders/yaml.py +++ b/moban/data_loaders/yaml.py @@ -1,8 +1,7 @@ +from moban import constants from lml.plugin import PluginInfo from ruamel.yaml import YAML -from moban import constants - @PluginInfo(constants.DATA_LOADER_EXTENSION, tags=["yaml", "yml"]) def open_yaml(file_name): diff --git a/moban/definitions.py b/moban/definitions.py index ce955a7e..8ae4ea45 100644 --- a/moban/definitions.py +++ b/moban/definitions.py @@ -4,10 +4,13 @@ class GitRequire(object): - def __init__(self, git_url=None, branch=None, submodule=False): + def __init__( + self, git_url=None, branch=None, submodule=False, reference=None + ): self.git_url = git_url self.submodule = submodule self.branch = branch + self.reference = reference def clone_params(self): clone_params = { @@ -16,6 +19,8 @@ def clone_params(self): } if self.branch is not None: clone_params["branch"] = self.branch + elif self.reference is not None: + clone_params["reference"] = self.reference return clone_params def __eq__(self, other): @@ -23,6 +28,7 @@ def __eq__(self, other): self.git_url == other.git_url and self.submodule == other.submodule and self.branch == other.branch + and self.reference == other.reference ) def __repr__(self): diff --git a/moban/jinja2/engine.py b/moban/jinja2/engine.py index 0e29a4ba..e80cd15f 100644 --- a/moban/jinja2/engine.py +++ b/moban/jinja2/engine.py @@ -1,13 +1,12 @@ import re from importlib import import_module +from moban import constants, exceptions from jinja2 import Template, Environment, FileSystemLoader from lml.loader import scan_plugins_regex from lml.plugin import PluginInfo, PluginManager from jinja2.exceptions import TemplateNotFound -from moban import constants, exceptions - JINJA2_LIBRARIES = "^moban_jinja2_.+$" JINJA2_EXENSIONS = [ "moban.jinja2.filters.repr", diff --git a/moban/jinja2/extensions.py b/moban/jinja2/extensions.py index 7b21dbfd..a4817ca1 100644 --- a/moban/jinja2/extensions.py +++ b/moban/jinja2/extensions.py @@ -1,6 +1,5 @@ -from lml.plugin import PluginInfo - from moban import constants +from lml.plugin import PluginInfo class JinjaFilter(PluginInfo): diff --git a/moban/mobanfile/__init__.py b/moban/mobanfile/__init__.py index dd3a33a7..2d3dca4e 100644 --- a/moban/mobanfile/__init__.py +++ b/moban/mobanfile/__init__.py @@ -3,17 +3,14 @@ import sys from collections import OrderedDict +from moban import plugins, reporter, constants from lml.utils import do_import - -from moban import reporter -from moban import constants -from moban import plugins from moban.repo import git_clone from moban.utils import merge, pip_install -from moban.mobanfile.targets import parse_targets, extract_group_targets from moban.deprecated import deprecated from moban.definitions import GitRequire from moban.plugins.template import expand_template_directories +from moban.mobanfile.targets import parse_targets, extract_group_targets try: from urllib.parse import urlparse @@ -193,6 +190,7 @@ def handle_requires(requires): GitRequire( git_url=require.get(constants.GIT_URL), branch=require.get(constants.GIT_BRANCH), + reference=require.get(constants.GIT_REFERENCE), submodule=require.get( constants.GIT_HAS_SUBMODULE, False ), diff --git a/moban/plugins/__init__.py b/moban/plugins/__init__.py index 9458e5ed..5cfdf27e 100644 --- a/moban/plugins/__init__.py +++ b/moban/plugins/__init__.py @@ -1,7 +1,6 @@ +from moban import constants from lml.loader import scan_plugins_regex from moban.plugins.template import MobanFactory -from moban import constants - BUILTIN_EXENSIONS = [ "moban.jinja2.engine", diff --git a/moban/plugins/library.py b/moban/plugins/library.py index ff9c782d..4c7405dc 100644 --- a/moban/plugins/library.py +++ b/moban/plugins/library.py @@ -1,6 +1,5 @@ -from lml.plugin import PluginManager - from moban import constants +from lml.plugin import PluginManager class LibraryManager(PluginManager): diff --git a/moban/plugins/template.py b/moban/plugins/template.py index 63117f8d..8a72f9e7 100644 --- a/moban/plugins/template.py +++ b/moban/plugins/template.py @@ -2,9 +2,8 @@ import sys import logging -from lml.plugin import PluginManager - from moban import repo, utils, reporter, constants, exceptions +from lml.plugin import PluginManager from moban.hashstore import HASH_STORE from moban.plugins.context import Context from moban.plugins.library import LIBRARIES diff --git a/moban/repo.py b/moban/repo.py index 615a2a5a..c614aeeb 100644 --- a/moban/repo.py +++ b/moban/repo.py @@ -25,6 +25,10 @@ def git_clone(requires): reporter.report_git_pull(repo_name) repo = Repo(local_repo_folder) repo.git.pull() + if require.reference: + repo.git.checkout(require.reference) + elif require.branch: + repo.git.checkout(require.branch) if require.submodule: reporter.report_info_message("updating submodule") repo.git.submodule("update") diff --git a/moban/reporter.py b/moban/reporter.py index e79ad989..b706ef79 100644 --- a/moban/reporter.py +++ b/moban/reporter.py @@ -1,6 +1,7 @@ -import crayons import moban.constants as constants +import crayons + MESSAGE_TEMPLATING = "Templating {0} to {1}" MESSAGE_UP_TO_DATE = "Everything is up to date!" MESSAGE_NO_TEMPLATING = "No templating" diff --git a/setup.py b/setup.py index 486a7d40..06ee131a 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 # Template by pypi-mobans -import os -import sys import codecs import locale +import os import platform +import sys from shutil import rmtree -from setuptools import Command, setup, find_packages +from setuptools import Command, find_packages, setup PY2 = sys.version_info[0] == 2 PY26 = PY2 and sys.version_info[1] < 7 @@ -22,82 +22,76 @@ try: lc = locale.getlocale() pf = platform.system() - if pf != 'Windows' and lc == (None, None): - locale.setlocale(locale.LC_ALL, 'C.UTF-8') + 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' -AUTHOR = 'C. W.' -VERSION = '0.4.4' -EMAIL = 'wangc_2011@hotmail.com' -LICENSE = 'MIT' -ENTRY_POINTS = { - 'console_scripts': [ - 'moban = moban.main:main' - ], -} -DESCRIPTION = ( - 'Yet another jinja2 cli command for static text generation' -) -URL = 'https://github.com/moremoban/moban' -DOWNLOAD_URL = '%s/archive/0.4.3.tar.gz' % URL -FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst'] -KEYWORDS = [ - 'python', - 'jinja2', - 'moban', -] + locale.setlocale(locale.LC_ALL, "en_US.UTF-8") + +NAME = "moban" +AUTHOR = "C. W." +VERSION = "0.4.5" +EMAIL = "wangc_2011@hotmail.com" +LICENSE = "MIT" +ENTRY_POINTS = {"console_scripts": ["moban = moban.main:main"]} +DESCRIPTION = "Yet another jinja2 cli command for static text generation" +URL = "https://github.com/moremoban/moban" +DOWNLOAD_URL = "%s/archive/0.4.5.tar.gz" % URL +FILES = ["README.rst", "CONTRIBUTORS.rst", "CHANGELOG.rst"] +KEYWORDS = ["python", "jinja2", "moban"] 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 = [ - 'ruamel.yaml>=0.15.5', - 'jinja2>=2.7.1', - 'lml>=0.0.9', - 'appdirs>=1.2.0', - 'crayons>= 0.1.0', - 'GitPython>=2.0.0', - 'giturlparse>=0.9.1', + "ruamel.yaml>=0.15.5", + "jinja2>=2.7.1", + "lml>=0.0.9", + "appdirs>=1.2.0", + "crayons>= 0.1.0", + "GitPython>=2.0.0", + "giturlparse>=0.9.1", ] SETUP_COMMANDS = {} -PACKAGES = find_packages(exclude=['ez_setup', 'examples', 'tests']) -EXTRAS_REQUIRE = { -} +PACKAGES = find_packages(exclude=["ez_setup", "examples", "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 v0.4.3 ' + - "Find 0.4.3 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 v0.4.5 " + "Find 0.4.5 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) + 'Upload failed. please run "%s" yourself.' % PUBLISH_COMMAND +) HERE = os.path.abspath(os.path.dirname(__file__)) 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 @@ -107,14 +101,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.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.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 @@ -127,9 +121,7 @@ def run(self): sys.exit() -SETUP_COMMANDS.update({ - 'publish': PublishCommand -}) +SETUP_COMMANDS.update({"publish": PublishCommand}) def has_gease(): @@ -140,6 +132,7 @@ def has_gease(): """ try: import gease # noqa + return True except ImportError: return False @@ -157,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 @@ -166,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() @@ -180,14 +173,14 @@ 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, @@ -201,12 +194,12 @@ 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, zip_safe=False, entry_points=ENTRY_POINTS, classifiers=CLASSIFIERS, - cmdclass=SETUP_COMMANDS + cmdclass=SETUP_COMMANDS, ) diff --git a/test.sh b/test.sh index 6f15b0f5..b294f53a 100644 --- a/test.sh +++ b/test.sh @@ -1,3 +1,3 @@ pip freeze -nosetests --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests && flake8 . --exclude=.moban.d,docs --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504 +nosetests --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 6cbe3fe6..2c141bf6 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -4,7 +4,6 @@ from mock import patch from nose.tools import eq_, raises, assert_raises - from moban.definitions import TemplateTarget diff --git a/tests/mobanfile/test_mobanfile.py b/tests/mobanfile/test_mobanfile.py index d30f79d1..4592c76c 100644 --- a/tests/mobanfile/test_mobanfile.py +++ b/tests/mobanfile/test_mobanfile.py @@ -2,7 +2,6 @@ from mock import patch from nose.tools import eq_ - from moban.definitions import GitRequire, TemplateTarget diff --git a/tests/mobanfile/test_targets.py b/tests/mobanfile/test_targets.py index 81dd1139..283ecf2c 100644 --- a/tests/mobanfile/test_targets.py +++ b/tests/mobanfile/test_targets.py @@ -2,7 +2,6 @@ import uuid from nose.tools import eq_, raises - from moban.mobanfile import targets from moban.exceptions import GroupTargetNotFound from moban.definitions import TemplateTarget diff --git a/tests/mobanfile/test_templates.py b/tests/mobanfile/test_templates.py index 11812a1b..21d90f2a 100644 --- a/tests/mobanfile/test_templates.py +++ b/tests/mobanfile/test_templates.py @@ -2,7 +2,6 @@ from mock import patch from nose.tools import eq_ - from moban.mobanfile.templates import handle_template diff --git a/tests/test_context.py b/tests/test_context.py index b4dab595..23b64133 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -1,7 +1,6 @@ import os from nose.tools import eq_ - from moban.plugins.context import Context diff --git a/tests/test_copy_encoding.py b/tests/test_copy_encoding.py index f024a223..de45bfbe 100644 --- a/tests/test_copy_encoding.py +++ b/tests/test_copy_encoding.py @@ -1,8 +1,7 @@ import os -from nose.tools import eq_ - from moban.copy import ContentForwardEngine +from nose.tools import eq_ class TestCopyEncoding: diff --git a/tests/test_copy_engine.py b/tests/test_copy_engine.py index 504ea19c..eecf9a95 100644 --- a/tests/test_copy_engine.py +++ b/tests/test_copy_engine.py @@ -1,8 +1,7 @@ import os -from nose.tools import eq_ - from moban.copy import ContentForwardEngine +from nose.tools import eq_ class TestContentForwardEngine: diff --git a/tests/test_definitions.py b/tests/test_definitions.py index 9348c49f..75d2bc60 100644 --- a/tests/test_definitions.py +++ b/tests/test_definitions.py @@ -1,5 +1,4 @@ from nose.tools import eq_ - from moban.definitions import GitRequire, TemplateTarget diff --git a/tests/test_docs.py b/tests/test_docs.py index 6df7320c..7f78cb30 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -3,9 +3,8 @@ from textwrap import dedent from mock import patch -from nose.tools import eq_ - from moban.main import main +from nose.tools import eq_ def custom_dedent(long_texts): diff --git a/tests/test_engine.py b/tests/test_engine.py index 62ed8bb2..803258fa 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -1,11 +1,10 @@ import os import sys +import moban.exceptions as exceptions from mock import patch from lml.plugin import PluginInfo from nose.tools import eq_, raises - -import moban.exceptions as exceptions from moban.plugins import ENGINES from moban.jinja2.engine import ( Engine, diff --git a/tests/test_filter_github.py b/tests/test_filter_github.py index 25aa58d1..2bb043fd 100644 --- a/tests/test_filter_github.py +++ b/tests/test_filter_github.py @@ -1,5 +1,4 @@ from nose.tools import eq_ - from moban.jinja2.filters.github import github_expand diff --git a/tests/test_filter_repr.py b/tests/test_filter_repr.py index 01d388ea..c18d458b 100644 --- a/tests/test_filter_repr.py +++ b/tests/test_filter_repr.py @@ -1,5 +1,4 @@ from nose.tools import eq_ - from moban.jinja2.filters.repr import repr as repr_function diff --git a/tests/test_hash_store.py b/tests/test_hash_store.py index cdd7d1bf..2e22ef17 100644 --- a/tests/test_hash_store.py +++ b/tests/test_hash_store.py @@ -2,7 +2,6 @@ import sys from nose import SkipTest - from moban.hashstore import HashStore diff --git a/tests/test_jinja2_engine.py b/tests/test_jinja2_engine.py index 1a979971..8996d951 100644 --- a/tests/test_jinja2_engine.py +++ b/tests/test_jinja2_engine.py @@ -1,7 +1,6 @@ import os from nose.tools import eq_ - from moban.jinja2.engine import Engine diff --git a/tests/test_jinja2_extensions.py b/tests/test_jinja2_extensions.py index f9009fcb..5ef492ba 100644 --- a/tests/test_jinja2_extensions.py +++ b/tests/test_jinja2_extensions.py @@ -1,7 +1,6 @@ import os from nose.tools import eq_ - from moban.jinja2.engine import Engine from moban.plugins.template import MobanEngine from moban.jinja2.extensions import jinja_global diff --git a/tests/test_json_loader.py b/tests/test_json_loader.py index fc38acd2..8a05ef9a 100644 --- a/tests/test_json_loader.py +++ b/tests/test_json_loader.py @@ -1,7 +1,6 @@ import os from nose.tools import eq_ - from moban.data_loaders.json_loader import open_json diff --git a/tests/test_main.py b/tests/test_main.py index 01de0769..3f8b27db 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,11 +2,10 @@ import sys from shutil import copyfile +import moban.exceptions as exceptions from mock import patch from nose.tools import raises, assert_raises -import moban.exceptions as exceptions - class TestException: def setUp(self): diff --git a/tests/test_regression.py b/tests/test_regression.py index 6e52a3c1..f80e8336 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -4,9 +4,8 @@ from textwrap import dedent from mock import patch -from nose.tools import eq_ - from moban.main import main +from nose.tools import eq_ def custom_dedent(long_texts): diff --git a/tests/test_repo.py b/tests/test_repo.py index 4d219d3a..aa70beed 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -1,14 +1,13 @@ import os from mock import patch -from nose.tools import eq_, raises - from moban.repo import ( git_clone, get_repo_name, get_moban_home, make_sure_git_is_available, ) +from nose.tools import eq_, raises from moban.exceptions import NoGitCommand from moban.definitions import GitRequire @@ -28,6 +27,9 @@ def setUp(self): self.require_with_branch = GitRequire( git_url=self.repo, branch="ghpages" ) + self.require_with_reference = GitRequire( + git_url=self.repo, reference="a-commit-reference" + ) self.expected_local_repo_path = os.path.join( "root", "repos", self.repo_name ) @@ -89,6 +91,37 @@ def test_checkout_new_with_branch( repo = fake_repo.return_value eq_(repo.git.submodule.called, False) + def test_update_existing_with_branch_parameter( + self, fake_repo, local_folder_exists, *_ + ): + local_folder_exists.return_value = True + git_clone([self.require_with_branch]) + repo = fake_repo.return_value + repo.git.checkout.assert_called_with("ghpages") + + def test_checkout_new_with_reference( + self, fake_repo, local_folder_exists, *_ + ): + local_folder_exists.return_value = False + git_clone([self.require_with_reference]) + fake_repo.clone_from.assert_called_with( + self.repo, + self.expected_local_repo_path, + reference="a-commit-reference", + single_branch=True, + depth=2, + ) + repo = fake_repo.return_value + eq_(repo.git.submodule.called, False) + + def test_update_existing_with_reference_parameter( + self, fake_repo, local_folder_exists, *_ + ): + local_folder_exists.return_value = True + git_clone([self.require_with_reference]) + repo = fake_repo.return_value + repo.git.checkout.assert_called_with("a-commit-reference") + def test_get_repo_name(): repos = [ diff --git a/tests/test_reporter.py b/tests/test_reporter.py index 7e8265b5..4a62e029 100644 --- a/tests/test_reporter.py +++ b/tests/test_reporter.py @@ -1,10 +1,9 @@ import sys +import moban.reporter as reporter from mock import patch from nose.tools import eq_ -import moban.reporter as reporter - PY2 = sys.version_info[0] == 2 if PY2: from StringIO import StringIO diff --git a/tests/test_template.py b/tests/test_template.py index d9b9d2b3..4c495195 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -2,7 +2,6 @@ from mock import patch from nose.tools import eq_ - from moban.plugins import ENGINES from moban.definitions import TemplateTarget from moban.jinja2.engine import Engine diff --git a/tests/test_text_filter.py b/tests/test_text_filter.py index 17f000df..177c0c5c 100644 --- a/tests/test_text_filter.py +++ b/tests/test_text_filter.py @@ -1,5 +1,4 @@ from nose.tools import eq_ - from moban.jinja2.filters.text import split_length diff --git a/tests/test_utils.py b/tests/test_utils.py index a732b8e7..7ce9ffcf 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,7 +6,6 @@ from mock import patch from nose import SkipTest from nose.tools import eq_, raises - from moban.utils import ( mkdir_p, write_file_out, diff --git a/tests/test_yaml_loader.py b/tests/test_yaml_loader.py index 0a3a6b0a..fe3cefe5 100644 --- a/tests/test_yaml_loader.py +++ b/tests/test_yaml_loader.py @@ -1,7 +1,6 @@ import os from nose.tools import eq_, raises - from moban.data_loaders.yaml import open_yaml from moban.data_loaders.manager import load_data