From ca3d26e3bc23594dfdeec2e90a3551c7373afb83 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 31 Oct 2018 18:19:32 +0000 Subject: [PATCH 01/17] :sparkles: support repo in requires syntax. resolves #97 --- .moban.cd/changelog.yml | 6 ++++++ .moban.d/setup.py | 2 ++ CHANGELOG.rst | 9 +++++++++ moban/mobanfile.py | 25 +++++++++++++++++++++++-- moban/utils.py | 9 +++++++++ tests/test_moban_file.py | 30 +++++++++++++++++++++++++++++- tests/test_utils.py | 10 ++++++++++ 7 files changed, 88 insertions(+), 3 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 42322d2c..246d7c0e 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: +- changes: + - action: Added + details: + - "`#97`: requires will clone a repo if given. Note: only github, gitlab, bitbucket for now" + date: unreleased + version: 0.3.1 - changes: - action: Added details: diff --git a/.moban.d/setup.py b/.moban.d/setup.py index 0e86846e..901b9222 100644 --- a/.moban.d/setup.py +++ b/.moban.d/setup.py @@ -2,3 +2,5 @@ {%block platform_block%} {%endblock%} + +{%block morefiles%} 'CONTRIBUTORS.rst',{%endblock%} diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 305c4c3d..f24f9cc4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.3.1 - unreleased +-------------------------------------------------------------------------------- + +Added +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#97 `_: requires will clone a + repo if given. Note: only github, gitlab, bitbucket for now + 0.3.0 - 27-18-2018 -------------------------------------------------------------------------------- diff --git a/moban/mobanfile.py b/moban/mobanfile.py index ce1f901b..2ba1235d 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -8,7 +8,7 @@ import moban.constants as constants import moban.reporter as reporter from moban.engine import ENGINES -from moban.utils import merge, parse_targets +from moban.utils import merge, parse_targets, git_clone from moban.utils import expand_directories, pip_install from moban.copier import Copier @@ -137,4 +137,25 @@ def extract_target(options): def handle_requires(requires): - pip_install(requires) + pypi_pkgs = [] + git_repos = [] + for require in requires: + if is_repo(require): + git_repos.append(require) + else: + pypi_pkgs.append(require) + if pypi_pkgs: + pip_install(pypi_pkgs) + if git_repos: + git_clone(git_repos) + + +def is_repo(require): + return ( + require.startswith('http') and + ( + 'github.com' in require or + 'gitlab.com' in require or + 'bitbucket.com' in require + ) + ) diff --git a/moban/utils.py b/moban/utils.py index 6f050ec7..9665c69f 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -147,6 +147,15 @@ def pip_install(packages): ) +def git_clone(repos): + import subprocess + + for repo in repos: + subprocess.check_call( + ['git', 'clone', repo] + ) + + def get_template_path(template_dirs, template): temp_dir = "" for a_dir in template_dirs: diff --git a/tests/test_moban_file.py b/tests/test_moban_file.py index a7fdbd56..6f670057 100644 --- a/tests/test_moban_file.py +++ b/tests/test_moban_file.py @@ -35,9 +35,37 @@ def test_no_moban_file(self): @patch("moban.mobanfile.pip_install") -def test_handle_requires(fake_pip_install): +def test_handle_requires_pypkg(fake_pip_install): modules = ["package1", "package2"] from moban.mobanfile import handle_requires handle_requires(modules) fake_pip_install.assert_called_with(modules) + + +@patch("moban.mobanfile.git_clone") +def test_handle_requires_repos(fake_git_clone): + repos = ["https://github.com/my/repo", "https://gitlab.com/my/repo"] + from moban.mobanfile import handle_requires + + handle_requires(repos) + fake_git_clone.assert_called_with(repos) + + +def test_is_repo(): + repos = [ + "https://github.com/my/repo", + "https://gitlab.com/my/repo", + "https://bitbucket.com/my/repo", + "https://unsupported.com/my/repo", + "invalid/repo/rul" + ] + from moban.mobanfile import is_repo + + actual = [ + is_repo(repo) for repo in repos + ] + expected = [ + True, True, True, False, False + ] + eq_(expected, actual) diff --git a/tests/test_utils.py b/tests/test_utils.py index a5885b18..bcee8249 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -102,3 +102,13 @@ def test_pip_install(fake_check_all): fake_check_all.assert_called_with( [sys.executable, "-m", "pip", "install", "package1 package2"] ) + + +@patch("subprocess.check_call") +def test_git_clone(fake_check_all): + from moban.utils import git_clone + + git_clone(["https://github.com/my/repo", "https://gitlab.com/my/repo"]) + fake_check_all.assert_called_with( + ["git", "clone", "https://gitlab.com/my/repo"] + ) From f3decf9c4362db0c2773b58440a4cfc3ca4e2cf8 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 1 Nov 2018 06:55:51 +0000 Subject: [PATCH 02/17] :hammer: coding style update --- moban/mobanfile.py | 11 ++++------- moban/utils.py | 4 +--- tests/test_moban_file.py | 10 +++------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 2ba1235d..17f1603f 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -151,11 +151,8 @@ def handle_requires(requires): def is_repo(require): - return ( - require.startswith('http') and - ( - 'github.com' in require or - 'gitlab.com' in require or - 'bitbucket.com' in require - ) + return require.startswith("http") and ( + "github.com" in require + or "gitlab.com" in require + or "bitbucket.com" in require ) diff --git a/moban/utils.py b/moban/utils.py index 9665c69f..f5ee75f7 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -151,9 +151,7 @@ def git_clone(repos): import subprocess for repo in repos: - subprocess.check_call( - ['git', 'clone', repo] - ) + subprocess.check_call(["git", "clone", repo]) def get_template_path(template_dirs, template): diff --git a/tests/test_moban_file.py b/tests/test_moban_file.py index 6f670057..1c2a6342 100644 --- a/tests/test_moban_file.py +++ b/tests/test_moban_file.py @@ -58,14 +58,10 @@ def test_is_repo(): "https://gitlab.com/my/repo", "https://bitbucket.com/my/repo", "https://unsupported.com/my/repo", - "invalid/repo/rul" + "invalid/repo/url", ] from moban.mobanfile import is_repo - actual = [ - is_repo(repo) for repo in repos - ] - expected = [ - True, True, True, False, False - ] + actual = [is_repo(repo) for repo in repos] + expected = [True, True, True, False, False] eq_(expected, actual) From 6af93e55d5bc7be4166fbec0de6fde3e7011f0aa Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 1 Nov 2018 07:11:11 +0000 Subject: [PATCH 03/17] :hammer: code refactoring --- moban/mobanfile.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 17f1603f..41926a9e 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -12,6 +12,8 @@ from moban.utils import expand_directories, pip_install from moban.copier import Copier +KNOWN_DOMAIN_FOR_GIT = ["github.com", "gitlab.com", "bitbucket.com"] + def find_default_moban_file(): for moban_file in constants.DEFAULT_MOBAN_FILES: @@ -151,8 +153,10 @@ def handle_requires(requires): def is_repo(require): - return require.startswith("http") and ( - "github.com" in require - or "gitlab.com" in require - or "bitbucket.com" in require - ) + one_of_the_domain = False + for domain in KNOWN_DOMAIN_FOR_GIT: + if domain in require: + one_of_the_domain = True + break + + return require.startswith("http") and one_of_the_domain From e15142f74605ad634af68873926b0c3cd26095cd Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 1 Nov 2018 18:26:07 +0000 Subject: [PATCH 04/17] :sparkles: maintain user defined, dependency(requires) git repos in users home directory as .moban/repos. #97 --- moban/constants.py | 2 ++ moban/engine.py | 11 ++++++++--- moban/mobanfile.py | 10 +++------- moban/utils.py | 35 ++++++++++++++++++++++++++++++++++- tests/test_utils.py | 2 +- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/moban/constants.py b/moban/constants.py index 5c7e8ab4..88afce3d 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -49,6 +49,8 @@ # moban file version MOBAN_VERSION = "moban_file_spec_version" DEFAULT_MOBAN_VERSION = "1.0" +MOBAN_DIR_NAME_UNDER_USER_HOME = ".moban" +MOBAN_REPOS_DIR_NAME = "reps" # error messages ERROR_DATA_FILE_NOT_FOUND = "Both %s and %s does not exist" diff --git a/moban/engine.py b/moban/engine.py index 0eb563f5..fd6c98c3 100644 --- a/moban/engine.py +++ b/moban/engine.py @@ -214,9 +214,14 @@ def expand_template_directories(dirs): for directory in dirs: if ":" in directory: - library_name, relative_path = directory.split(":") - library_path = LIBRARIES.resource_path_of(library_name) - yield os.path.join(library_path, relative_path) + library_or_repo_name, relative_path = directory.split(":") + potential_repo_path = os.path.join( + utils.get_moban_home(), library_or_repo_name) + if os.path.exists(potential_repo_path): + yield potential_repo_path + else: + library_path = LIBRARIES.resource_path_of(library_or_repo_name) + yield os.path.join(library_path, relative_path) else: yield directory diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 41926a9e..131f3b33 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -1,6 +1,7 @@ import os import re import sys +from urllib.parse import urlparse from collections import defaultdict from lml.utils import do_import @@ -153,10 +154,5 @@ def handle_requires(requires): def is_repo(require): - one_of_the_domain = False - for domain in KNOWN_DOMAIN_FOR_GIT: - if domain in require: - one_of_the_domain = True - break - - return require.startswith("http") and one_of_the_domain + result = urlparse(require) + return result.scheme != '' and result.netloc in KNOWN_DOMAIN_FOR_GIT diff --git a/moban/utils.py b/moban/utils.py index f5ee75f7..ea33429b 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -149,9 +149,20 @@ def pip_install(packages): def git_clone(repos): import subprocess + moban_home = get_moban_home() + mkdir_p(moban_home) for repo in repos: - subprocess.check_call(["git", "clone", repo]) + repo_name = get_repo_name(repo) + local_repo_folder = os.path.join(moban_home, repo_name) + current_working_dir = os.getcwd() + if os.path.exists(local_repo_folder): + os.chdir(local_repo_folder) + subprocess.check_call(["git", "pull"]) + else: + os.chdir(moban_home) + subprocess.check_call(["git", "clone", repo, repo_name]) + os.chdir(current_working_dir) def get_template_path(template_dirs, template): @@ -169,3 +180,25 @@ def get_template_path(template_dirs, template): os.getcwd(), os.path.join(temp_dir, template.filename) ) return temp_file_path + + +def get_repo_name(repo_url): + path = repo_url.split('/') + repo_name = path[-1] + repo_name = _remove_dot_git(repo_name) + return repo_name + + +def get_moban_home(): + home_dir = os.path.expanduser('~') + if os.path.exists(home_dir): + return os.path.join( + home_dir, + constants.MOBAN_DIR_NAME_UNDER_USER_HOME, + constants.MOBAN_REPOS_DIR_NAME + ) + raise IOError("Failed to find user home directory") + + +def _remove_dot_git(repo_name): + return repo_name.split('.')[0] diff --git a/tests/test_utils.py b/tests/test_utils.py index bcee8249..17c5b1a9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -110,5 +110,5 @@ def test_git_clone(fake_check_all): git_clone(["https://github.com/my/repo", "https://gitlab.com/my/repo"]) fake_check_all.assert_called_with( - ["git", "clone", "https://gitlab.com/my/repo"] + ["git", "clone", "https://gitlab.com/my/repo", "repo"] ) From 573348cb3912e9ca33461331c1674f3105dd1cbb Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 07:55:21 +0000 Subject: [PATCH 05/17] :microscope: test the util to expand git repo home --- moban/constants.py | 2 +- moban/engine.py | 5 ++++- tests/test_engine.py | 13 ++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/moban/constants.py b/moban/constants.py index 88afce3d..9960ca22 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -50,7 +50,7 @@ MOBAN_VERSION = "moban_file_spec_version" DEFAULT_MOBAN_VERSION = "1.0" MOBAN_DIR_NAME_UNDER_USER_HOME = ".moban" -MOBAN_REPOS_DIR_NAME = "reps" +MOBAN_REPOS_DIR_NAME = "repos" # error messages ERROR_DATA_FILE_NOT_FOUND = "Both %s and %s does not exist" diff --git a/moban/engine.py b/moban/engine.py index fd6c98c3..9fc5d014 100644 --- a/moban/engine.py +++ b/moban/engine.py @@ -218,11 +218,14 @@ def expand_template_directories(dirs): potential_repo_path = os.path.join( utils.get_moban_home(), library_or_repo_name) if os.path.exists(potential_repo_path): - yield potential_repo_path + # expand repo template path + yield os.path.join(potential_repo_path, relative_path) else: + # expand pypi template path library_path = LIBRARIES.resource_path_of(library_or_repo_name) yield os.path.join(library_path, relative_path) else: + # local template path yield directory diff --git a/tests/test_engine.py b/tests/test_engine.py index 4b8d340e..daca546a 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -1,4 +1,6 @@ import os + +from mock import patch from nose.tools import raises, eq_ from moban.engine import ENGINES, Engine, Context import moban.exceptions as exceptions @@ -14,12 +16,21 @@ def __init__(self): self.resources_path = os.path.join(__package_path__, "fixtures") -def test_expand_dir(): +def test_expand_pypi_dir(): dirs = list(expand_template_directories("testmobans:template-tests")) for directory in dirs: assert os.path.exists(directory) +@patch("moban.utils.get_moban_home", return_value="/user/home/.moban/repos") +@patch("os.path.exists", return_value=True) +def test_expand_repo_dir(_, __): + dirs = list(expand_template_directories("git_repo:template")) + + expected = ['/user/home/.moban/repos/git_repo/template'] + eq_(expected, dirs) + + def test_default_template_type(): engine_class = ENGINES.get_engine("jj2") assert engine_class == Engine From d1542afdeb968ed9e01bd2ac6f0911f018355f51 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 08:00:35 +0000 Subject: [PATCH 06/17] :books: document git repository support --- docs/README.rst | 2 ++ .../.moban.yml | 10 +++++++ .../README.rst | 26 +++++++++++++++++++ .../config.yml | 1 + .../mytravis.yml | 23 ++++++++++++++++ tests/test_docs.py | 5 ++++ 6 files changed, 67 insertions(+) create mode 100644 docs/level-10-moban-dependency-as-git-repo/.moban.yml create mode 100644 docs/level-10-moban-dependency-as-git-repo/README.rst create mode 100644 docs/level-10-moban-dependency-as-git-repo/config.yml create mode 100644 docs/level-10-moban-dependency-as-git-repo/mytravis.yml diff --git a/docs/README.rst b/docs/README.rst index ed0b5bed..37ccfaf4 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -12,6 +12,7 @@ This section covers the use cases for moban. Please check them out individually. #. `Use custom jinja2 filter test n global`_ #. `Pass a folder full of templates`_ #. `Use pypi package as a moban dependency`_ +#. `Use git repository as a moban dependency`_ .. _Jinja2 command line: level-1-jinja2-cli .. _Template inheritance: level-2-template-inheritance @@ -22,3 +23,4 @@ This section covers the use cases for moban. Please check them out individually. .. _Use custom jinja2 filter test n global: level-7-use-custom-jinja2-filter-test-n-global .. _Pass a folder full of templates: level-8-pass-a-folder-full-of-templates .. _Use pypi package as a moban dependency: level-9-moban-dependency-as-pypi-package +.. _Use git repository as a moban dependency: level-10-moban-dependency-as-git-repo diff --git a/docs/level-10-moban-dependency-as-git-repo/.moban.yml b/docs/level-10-moban-dependency-as-git-repo/.moban.yml new file mode 100644 index 00000000..34bfc340 --- /dev/null +++ b/docs/level-10-moban-dependency-as-git-repo/.moban.yml @@ -0,0 +1,10 @@ +requires: + - https://github.com/moremoban/pypi-mobans +configuration: + template_dir: + - "pypi-mobans:templates" + - local + configuration: config.yml +targets: + - mytravis.yml: travis.yml.jj2 + - test.txt: demo.txt.jj2 diff --git a/docs/level-10-moban-dependency-as-git-repo/README.rst b/docs/level-10-moban-dependency-as-git-repo/README.rst new file mode 100644 index 00000000..7a711c31 --- /dev/null +++ b/docs/level-10-moban-dependency-as-git-repo/README.rst @@ -0,0 +1,26 @@ +level 10: moban dependency as git repo +================================================================================ + +Since the support to have a pypi package as dependency, the pro user of moban +find it more useful to have git repo so that the changes to static content +could get propagate as it happens using git push and git pull. + +For now, github.com, gitlab.com and bitbucket.com are supported. Pull request +is welcome to add or improve this feature. + + +Here are the sample file:: + + requires: + - https://github.com/moremoban/pypi-mobans + configuration: + template_dir: + - "pypi-mobans:templates" + - local + configuration: config.yml + targets: + - mytravis.yml: travis.yml.jj2 + - test.txt: demo.txt.jj2 + +where `requires` lead to a list of pypi packages. And when you refer to it, +please use "pypi-mobans:" diff --git a/docs/level-10-moban-dependency-as-git-repo/config.yml b/docs/level-10-moban-dependency-as-git-repo/config.yml new file mode 100644 index 00000000..97ee12f9 --- /dev/null +++ b/docs/level-10-moban-dependency-as-git-repo/config.yml @@ -0,0 +1 @@ +level9: "moban dependency as pypi package" diff --git a/docs/level-10-moban-dependency-as-git-repo/mytravis.yml b/docs/level-10-moban-dependency-as-git-repo/mytravis.yml new file mode 100644 index 00000000..8295c536 --- /dev/null +++ b/docs/level-10-moban-dependency-as-git-repo/mytravis.yml @@ -0,0 +1,23 @@ +sudo: false +language: python +notifications: + email: false +python: + - pypy-5.3.1 + - 3.7-dev + - 3.6 + - 3.5 + - 3.4 + - 2.7 +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 -r rnd_requirements.txt ; + - pip install -r tests/requirements.txt +script: + - make test +after_success: + codecov diff --git a/tests/test_docs.py b/tests/test_docs.py index 8b24cf01..e903eaf4 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -96,6 +96,11 @@ def test_level_9(self): folder = "level-9-moban-dependency-as-pypi-package" self._raw_moban(["moban"], folder, expected, "test.txt") + def test_level_10(self): + expected = "moban dependency as pypi package" + folder = "level-10-moban-dependency-as-git-repo" + self._raw_moban(["moban"], folder, expected, "test.txt") + def test_misc_1(self): expected = "test file\n" From e27f6aeb95f8fc2ca97daedd2fbc69e9628aeebe Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 08:09:15 +0000 Subject: [PATCH 07/17] :lipstick: beautify the code using black spell --- moban/engine.py | 3 ++- moban/mobanfile.py | 2 +- moban/utils.py | 9 +++++---- tests/test_engine.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/moban/engine.py b/moban/engine.py index 9fc5d014..16260fa5 100644 --- a/moban/engine.py +++ b/moban/engine.py @@ -216,7 +216,8 @@ def expand_template_directories(dirs): if ":" in directory: library_or_repo_name, relative_path = directory.split(":") potential_repo_path = os.path.join( - utils.get_moban_home(), library_or_repo_name) + utils.get_moban_home(), library_or_repo_name + ) if os.path.exists(potential_repo_path): # expand repo template path yield os.path.join(potential_repo_path, relative_path) diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 131f3b33..2f1e71fc 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -155,4 +155,4 @@ def handle_requires(requires): def is_repo(require): result = urlparse(require) - return result.scheme != '' and result.netloc in KNOWN_DOMAIN_FOR_GIT + return result.scheme != "" and result.netloc in KNOWN_DOMAIN_FOR_GIT diff --git a/moban/utils.py b/moban/utils.py index ea33429b..4740a114 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -149,6 +149,7 @@ def pip_install(packages): def git_clone(repos): import subprocess + moban_home = get_moban_home() mkdir_p(moban_home) @@ -183,22 +184,22 @@ def get_template_path(template_dirs, template): def get_repo_name(repo_url): - path = repo_url.split('/') + path = repo_url.split("/") repo_name = path[-1] repo_name = _remove_dot_git(repo_name) return repo_name def get_moban_home(): - home_dir = os.path.expanduser('~') + home_dir = os.path.expanduser("~") if os.path.exists(home_dir): return os.path.join( home_dir, constants.MOBAN_DIR_NAME_UNDER_USER_HOME, - constants.MOBAN_REPOS_DIR_NAME + constants.MOBAN_REPOS_DIR_NAME, ) raise IOError("Failed to find user home directory") def _remove_dot_git(repo_name): - return repo_name.split('.')[0] + return repo_name.split(".")[0] diff --git a/tests/test_engine.py b/tests/test_engine.py index daca546a..4d353613 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -27,7 +27,7 @@ def test_expand_pypi_dir(): def test_expand_repo_dir(_, __): dirs = list(expand_template_directories("git_repo:template")) - expected = ['/user/home/.moban/repos/git_repo/template'] + expected = ["/user/home/.moban/repos/git_repo/template"] eq_(expected, dirs) From 5b5dfab08b84066d81c38514db27e818816d2a0a Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 08:10:22 +0000 Subject: [PATCH 08/17] :books: pump up version --- .moban.cd/moban.yml | 4 ++-- docs/conf.py | 2 +- moban/_version.py | 2 +- setup.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 967ed18e..22dad202 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -3,8 +3,8 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.3.0 -current_version: 0.3.0 +version: 0.3.1 +current_version: 0.3.1 release: 0.3.0 branch: master command_line_interface: "moban" diff --git a/docs/conf.py b/docs/conf.py index 961d9670..81d88f41 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,7 @@ # The short X.Y version version = u'0.3.0' # The full version, including alpha/beta/rc tags -release = u'0.3.0' +release = u'0.3.1' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index a8f4a9bf..88f30297 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.3.0" +__version__ = "0.3.1" __author__ = "C. W." diff --git a/setup.py b/setup.py index 5a47c1e4..50e546e7 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ NAME = 'moban' AUTHOR = 'C. W.' -VERSION = '0.3.0' +VERSION = '0.3.1' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'MIT' ENTRY_POINTS = { From d6de3a831007520dcca0441a3a5c05425c61d356 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 18:24:20 +0000 Subject: [PATCH 09/17] :bug: fix broken build --- .../local/demo.txt.jj2 | 1 + .../local/mytravis.yml | 23 +++++++++++++++++++ moban/mobanfile.py | 6 ++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 create mode 100644 docs/level-10-moban-dependency-as-git-repo/local/mytravis.yml diff --git a/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 b/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 new file mode 100644 index 00000000..1f57ab9b --- /dev/null +++ b/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 @@ -0,0 +1 @@ +{{level9}} \ No newline at end of file diff --git a/docs/level-10-moban-dependency-as-git-repo/local/mytravis.yml b/docs/level-10-moban-dependency-as-git-repo/local/mytravis.yml new file mode 100644 index 00000000..8295c536 --- /dev/null +++ b/docs/level-10-moban-dependency-as-git-repo/local/mytravis.yml @@ -0,0 +1,23 @@ +sudo: false +language: python +notifications: + email: false +python: + - pypy-5.3.1 + - 3.7-dev + - 3.6 + - 3.5 + - 3.4 + - 2.7 +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 -r rnd_requirements.txt ; + - pip install -r tests/requirements.txt +script: + - make test +after_success: + codecov diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 2f1e71fc..8f991b68 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -1,7 +1,11 @@ import os import re import sys -from urllib.parse import urlparse +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse + from collections import defaultdict from lml.utils import do_import From 45de283d234f12a4d6c8597d177a8db5e28d6877 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 22:11:20 +0000 Subject: [PATCH 10/17] :microscope: more test coverage --- tests/test_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 17c5b1a9..77cd9b7c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,12 +2,14 @@ import stat from shutil import rmtree from mock import patch -from nose.tools import eq_ +from nose.tools import eq_, raises from moban.utils import file_permissions_copy +from moban.utils import file_permissions from moban.utils import write_file_out from moban.utils import strip_off_trailing_new_lines from moban.utils import mkdir_p, expand_directories, get_template_path from mock import Mock +from moban.exceptions import FileNotFound def create_file(test_file, permission): @@ -31,6 +33,11 @@ def test_file_permission_copy(): os.unlink(test_dest) +@raises(FileNotFound) +def test_file_permissions_file_not_found(): + file_permissions('I does not exist') + + def test_file_permission_copy_symlink(): test_source = "test_file_permission_copy1" test_dest = "test_file_permission_copy2" From a523546bc6907fcfacaa22838cacbe8b456bc70c Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:10:13 +0000 Subject: [PATCH 11/17] :sparkles: integration test with coala-mobans --- moban/engine.py | 12 +++++++++--- moban/mobanfile.py | 8 ++++++-- moban/reporter.py | 16 ++++++++++++++++ moban/utils.py | 8 +++++++- tests/test_utils.py | 14 +++++++++++++- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/moban/engine.py b/moban/engine.py index 16260fa5..cea09ba4 100644 --- a/moban/engine.py +++ b/moban/engine.py @@ -220,14 +220,20 @@ def expand_template_directories(dirs): ) if os.path.exists(potential_repo_path): # expand repo template path - yield os.path.join(potential_repo_path, relative_path) + if relative_path: + yield os.path.join(potential_repo_path, relative_path) + else: + yield potential_repo_path else: # expand pypi template path library_path = LIBRARIES.resource_path_of(library_or_repo_name) - yield os.path.join(library_path, relative_path) + if relative_path: + yield os.path.join(library_path, relative_path) + else: + yield library_path else: # local template path - yield directory + yield os.path.abspath(directory) def verify_the_existence_of_directories(dirs): diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 8f991b68..910cf7fb 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -12,7 +12,7 @@ import moban.constants as constants import moban.reporter as reporter -from moban.engine import ENGINES +from moban.engine import ENGINES, expand_template_directories from moban.utils import merge, parse_targets, git_clone from moban.utils import expand_directories, pip_install from moban.copier import Copier @@ -71,7 +71,11 @@ def handle_moban_file_v1(moban_file_configurations, command_line_options): def handle_copy(template_dirs, copy_config): - copier = Copier(template_dirs) + # expanding function is added so that + # copy function understands repo and pypi_pkg path, since 0.3.1 + expanded_dirs = list(expand_template_directories(template_dirs)) + + copier = Copier(expanded_dirs) copier.copy_files(copy_config) copier.report() return copier.number_of_copied_files() diff --git a/moban/reporter.py b/moban/reporter.py index f1b4719a..b7e789b6 100644 --- a/moban/reporter.py +++ b/moban/reporter.py @@ -11,6 +11,8 @@ MESSAGE_TEMPLATED_ALL = "Templated {0} files." MESSAGE_COPY_REPORT = "Copied {0} out of {1} files." MESSAGE_COPIED_ALL = "Copied {0} files." +MESSAGE_PULLING_REPO = "Updating {0}..." +MESSAGE_CLONING_REPO = "Cloning {0}..." def report_templating(source_file, destination_file): @@ -82,6 +84,20 @@ def report_copying_summary(total, copies): print(_format_single(message, total)) +def report_git_pull(repo): + colored_repo = crayons.green(repo, bold=True) + print( + MESSAGE_PULLING_REPO.format(colored_repo) + ) + + +def report_git_clone(repo): + colored_repo = crayons.green(repo, bold=True) + print( + MESSAGE_CLONING_REPO.format(colored_repo) + ) + + def _format_single(message, count): if count == 1: return message.replace("files", "file") diff --git a/moban/utils.py b/moban/utils.py index 4740a114..9802f8da 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -6,6 +6,7 @@ import yaml import moban.constants as constants import moban.exceptions as exceptions +import moban.reporter as reporter def merge(left, right): @@ -158,9 +159,11 @@ def git_clone(repos): local_repo_folder = os.path.join(moban_home, repo_name) current_working_dir = os.getcwd() if os.path.exists(local_repo_folder): + reporter.report_git_pull(repo_name) os.chdir(local_repo_folder) subprocess.check_call(["git", "pull"]) else: + reporter.report_git_clone(repo_name) os.chdir(moban_home) subprocess.check_call(["git", "clone", repo, repo_name]) os.chdir(current_working_dir) @@ -185,7 +188,10 @@ def get_template_path(template_dirs, template): def get_repo_name(repo_url): path = repo_url.split("/") - repo_name = path[-1] + if repo_url.endswith('/'): + repo_name = path[-2] + else: + repo_name = path[-1] repo_name = _remove_dot_git(repo_name) return repo_name diff --git a/tests/test_utils.py b/tests/test_utils.py index 77cd9b7c..5691c0ec 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,7 +6,7 @@ from moban.utils import file_permissions_copy from moban.utils import file_permissions from moban.utils import write_file_out -from moban.utils import strip_off_trailing_new_lines +from moban.utils import strip_off_trailing_new_lines, get_repo_name from moban.utils import mkdir_p, expand_directories, get_template_path from mock import Mock from moban.exceptions import FileNotFound @@ -119,3 +119,15 @@ def test_git_clone(fake_check_all): fake_check_all.assert_called_with( ["git", "clone", "https://gitlab.com/my/repo", "repo"] ) + + +def test_get_repo_name(): + repos = [ + "https://github.com/abc/repo", + "https://github.com/abc/repo/" + ] + actual = [ + get_repo_name(repo) for repo in repos + ] + expected = ['repo', 'repo'] + eq_(expected, actual) From f4331dfdc703b7a84c95d113b9c5ebb2fcc9310e Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:18:09 +0000 Subject: [PATCH 12/17] :fire: get rid of duplicated no copy report function --- moban/reporter.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/moban/reporter.py b/moban/reporter.py index b7e789b6..4694911f 100644 --- a/moban/reporter.py +++ b/moban/reporter.py @@ -68,10 +68,6 @@ def report_copying(source_file, destination_file): ) -def report_no_copying_done(): - print(crayons.red(MESSAGE_NO_COPY, bold=True)) - - def report_copying_summary(total, copies): if total == copies: figure = crayons.green(str(total), bold=True) From fc534490834ac22bf22944f93cc3f156b3d8115b Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:37:09 +0000 Subject: [PATCH 13/17] :lipstick: make format will format the code to highest asthetics --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .isort.cfg | 10 ++++++ Makefile | 5 +++ .../custom-jj2-plugin/filter.py | 1 + .../custom-jj2-plugin/global.py | 1 - moban/__main__.py | 1 - moban/constants.py | 1 - moban/engine.py | 16 +++++++--- moban/extensions.py | 3 +- moban/filters/github.py | 2 +- moban/filters/text.py | 1 + moban/hashstore.py | 1 - moban/main.py | 10 +++--- moban/mobanfile.py | 24 ++++++++------ moban/reporter.py | 9 ++---- moban/tests/files.py | 13 ++++++-- moban/utils.py | 5 +-- setup.py | 4 ++- .../test_command_line_options.py | 5 +-- tests/requirements.txt | 2 ++ tests/test_context.py | 1 - tests/test_copier.py | 7 ++-- tests/test_docs.py | 3 +- tests/test_engine.py | 10 +++--- tests/test_filter_github.py | 2 +- tests/test_filter_repr.py | 2 +- tests/test_main.py | 5 +-- tests/test_moban_file.py | 2 +- tests/test_reporter.py | 3 +- tests/test_template.py | 1 + tests/test_text_filter.py | 2 +- tests/test_utils.py | 32 +++++++++---------- tests/test_yaml_loader.py | 3 +- 33 files changed, 113 insertions(+), 76 deletions(-) create mode 100644 .isort.cfg diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8c52df17..5f335815 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,7 +1,7 @@ Before raising the PR, here is a check list: 1) have you written unit tests for your code changes? -2) have you run "black -l 79 on_your_changed_files.py"? +2) have you run "make format"? 3) are you requesting to "dev"? 4) have you updated the change log? 5) do you think that you can understand your changes after 6 month? diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..53668475 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,10 @@ +[settings] +line_length=79 +known_first_party=lml, jinja2 +indent=' ' +multi_line_output=3 +length_sort=1 +forced_separate=django.contrib,django.utils +default_section=FIRSTPARTY +no_lines_before=LOCALFOLDER +sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER diff --git a/Makefile b/Makefile index 360c0a2a..d275cdef 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,8 @@ update: test: bash test.sh + +format: + isort -y $(find moban -name "*.py"|xargs echo) $(find tests -name "*.py"|xargs echo) + black -l 79 moban + black -l 79 tests diff --git a/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/filter.py b/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/filter.py index d321ef4f..7888a1bc 100644 --- a/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/filter.py +++ b/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/filter.py @@ -1,5 +1,6 @@ import sys import base64 + from moban.extensions import JinjaFilter diff --git a/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/global.py b/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/global.py index a3943ee0..007bc4a5 100644 --- a/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/global.py +++ b/docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/global.py @@ -1,4 +1,3 @@ from moban.extensions import jinja_global - jinja_global('global', dict(hello='world')) diff --git a/moban/__main__.py b/moban/__main__.py index 45483daf..e0021823 100644 --- a/moban/__main__.py +++ b/moban/__main__.py @@ -1,5 +1,4 @@ from moban.main import main - if __name__ == "__main__": main() diff --git a/moban/constants.py b/moban/constants.py index 9960ca22..a141d5c8 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -1,6 +1,5 @@ import os - # Configurations PROGRAM_NAME = "moban" PROGRAM_DESCRIPTION = ( diff --git a/moban/engine.py b/moban/engine.py index cea09ba4..7f335553 100644 --- a/moban/engine.py +++ b/moban/engine.py @@ -1,16 +1,22 @@ import os from collections import defaultdict + from jinja2 import Environment, FileSystemLoader -from lml.plugin import PluginManager, PluginInfo from lml.loader import scan_plugins_regex -from moban.hashstore import HASH_STORE -from moban.extensions import JinjaFilterManager, JinjaTestManager -from moban.extensions import JinjaGlobalsManager, LibraryManager +from lml.plugin import PluginInfo, PluginManager + import moban.utils as utils +import moban.reporter as reporter import moban.constants as constants import moban.exceptions as exceptions -import moban.reporter as reporter from moban.utils import get_template_path +from moban.hashstore import HASH_STORE +from moban.extensions import ( + LibraryManager, + JinjaTestManager, + JinjaFilterManager, + JinjaGlobalsManager, +) BUILTIN_EXENSIONS = [ "moban.filters.repr", diff --git a/moban/extensions.py b/moban/extensions.py index f9bdb609..61e174c7 100644 --- a/moban/extensions.py +++ b/moban/extensions.py @@ -1,4 +1,5 @@ -from lml.plugin import PluginManager, PluginInfo +from lml.plugin import PluginInfo, PluginManager + import moban.constants as constants diff --git a/moban/filters/github.py b/moban/filters/github.py index da7feb14..efea56ad 100644 --- a/moban/filters/github.py +++ b/moban/filters/github.py @@ -1,6 +1,6 @@ import re -from moban.extensions import JinjaFilter +from moban.extensions import JinjaFilter GITHUB_REF_PATTERN = "`([^`]*?#[0-9]+)`" ISSUE = "^.*?" + GITHUB_REF_PATTERN + ".*?$" diff --git a/moban/filters/text.py b/moban/filters/text.py index 865b6203..95306992 100644 --- a/moban/filters/text.py +++ b/moban/filters/text.py @@ -1,4 +1,5 @@ import re + from moban.extensions import JinjaFilter diff --git a/moban/hashstore.py b/moban/hashstore.py index 76f42ab5..44a079bb 100644 --- a/moban/hashstore.py +++ b/moban/hashstore.py @@ -6,7 +6,6 @@ import moban.utils as utils import moban.constants as constants - PY2 = sys.version_info[0] == 2 diff --git a/moban/main.py b/moban/main.py index 5b1ceb33..3fb6cedf 100644 --- a/moban/main.py +++ b/moban/main.py @@ -12,13 +12,13 @@ import sys import argparse -from moban.engine import ENGINES -from moban.hashstore import HASH_STORE -from moban.utils import merge, open_yaml +import moban.reporter as reporter import moban.constants as constants -import moban.exceptions as exceptions import moban.mobanfile as mobanfile -import moban.reporter as reporter +import moban.exceptions as exceptions +from moban.utils import merge, open_yaml +from moban.engine import ENGINES +from moban.hashstore import HASH_STORE def main(): diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 910cf7fb..75102b0e 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -1,21 +1,27 @@ import os import re import sys -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse - from collections import defaultdict from lml.utils import do_import -import moban.constants as constants import moban.reporter as reporter -from moban.engine import ENGINES, expand_template_directories -from moban.utils import merge, parse_targets, git_clone -from moban.utils import expand_directories, pip_install +import moban.constants as constants +from moban.utils import ( + merge, + git_clone, + pip_install, + parse_targets, + expand_directories, +) from moban.copier import Copier +from moban.engine import ENGINES, expand_template_directories + +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse + KNOWN_DOMAIN_FOR_GIT = ["github.com", "gitlab.com", "bitbucket.com"] diff --git a/moban/reporter.py b/moban/reporter.py index 4694911f..bdb5bc42 100644 --- a/moban/reporter.py +++ b/moban/reporter.py @@ -1,5 +1,4 @@ import crayons - import moban.constants as constants MESSAGE_TEMPLATING = "Templating {0} to {1}" @@ -82,16 +81,12 @@ def report_copying_summary(total, copies): def report_git_pull(repo): colored_repo = crayons.green(repo, bold=True) - print( - MESSAGE_PULLING_REPO.format(colored_repo) - ) + print(MESSAGE_PULLING_REPO.format(colored_repo)) def report_git_clone(repo): colored_repo = crayons.green(repo, bold=True) - print( - MESSAGE_CLONING_REPO.format(colored_repo) - ) + print(MESSAGE_CLONING_REPO.format(colored_repo)) def _format_single(message, count): diff --git a/moban/tests/files.py b/moban/tests/files.py index 27ebc0d2..07170dee 100644 --- a/moban/tests/files.py +++ b/moban/tests/files.py @@ -1,9 +1,16 @@ -from os.path import isdir, isfile, isabs, exists -from os.path import lexists, islink, samefile, ismount +from os.path import ( + isabs, + isdir, + exists, + isfile, + islink, + ismount, + lexists, + samefile, +) from moban.extensions import jinja_tests - jinja_tests( is_dir=isdir, directory=isdir, diff --git a/moban/utils.py b/moban/utils.py index 9802f8da..c7bf71ab 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -3,10 +3,11 @@ import sys import stat import errno + import yaml +import moban.reporter as reporter import moban.constants as constants import moban.exceptions as exceptions -import moban.reporter as reporter def merge(left, right): @@ -188,7 +189,7 @@ def get_template_path(template_dirs, template): def get_repo_name(repo_url): path = repo_url.split("/") - if repo_url.endswith('/'): + if repo_url.endswith("/"): repo_name = path[-2] else: repo_name = path[-1] diff --git a/setup.py b/setup.py index 50e546e7..649e9dc6 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,9 @@ import sys import codecs from shutil import rmtree -from setuptools import setup, find_packages, Command + +from setuptools import Command, setup, find_packages + PY2 = sys.version_info[0] == 2 PY26 = PY2 and sys.version_info[1] < 7 diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 1ea18e7c..153e10e5 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -1,9 +1,10 @@ import os import sys from shutil import copyfile -from moban.main import main + from mock import patch -from nose.tools import raises, assert_raises, eq_ +from moban.main import main +from nose.tools import eq_, raises, assert_raises class TestCustomOptions: diff --git a/tests/requirements.txt b/tests/requirements.txt index 24244803..3da77aa1 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -4,3 +4,5 @@ coverage mock flake8 moban +black +isort diff --git a/tests/test_context.py b/tests/test_context.py index 73c86253..afe9419a 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -1,7 +1,6 @@ import os from nose.tools import eq_ - from moban.engine import Context diff --git a/tests/test_copier.py b/tests/test_copier.py index 68d1b6b2..6d650695 100644 --- a/tests/test_copier.py +++ b/tests/test_copier.py @@ -1,9 +1,10 @@ import os +import shutil + +from mock import patch +from nose.tools import eq_ from moban.copier import Copier from moban.mobanfile import handle_copy -from nose.tools import eq_ -from mock import patch -import shutil class TestCopier: diff --git a/tests/test_docs.py b/tests/test_docs.py index e903eaf4..ac5a607c 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,10 +1,9 @@ import os import sys -from nose.tools import eq_ - from mock import patch from moban.main import main +from nose.tools import eq_ class TestTutorial: diff --git a/tests/test_engine.py b/tests/test_engine.py index 4d353613..a78792f0 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -1,12 +1,12 @@ import os -from mock import patch -from nose.tools import raises, eq_ -from moban.engine import ENGINES, Engine, Context +from lml.plugin import PluginInfo + import moban.exceptions as exceptions +from mock import patch +from nose.tools import eq_, raises +from moban.engine import ENGINES, Engine, Context, expand_template_directories from moban.extensions import jinja_global -from moban.engine import expand_template_directories -from lml.plugin import PluginInfo @PluginInfo("library", tags=["testmobans"]) diff --git a/tests/test_filter_github.py b/tests/test_filter_github.py index 3ac86f4d..5cbc8e1e 100644 --- a/tests/test_filter_github.py +++ b/tests/test_filter_github.py @@ -1,5 +1,5 @@ -from moban.filters.github import github_expand from nose.tools import eq_ +from moban.filters.github import github_expand def test_github_expand(): diff --git a/tests/test_filter_repr.py b/tests/test_filter_repr.py index f63bda78..62116dba 100644 --- a/tests/test_filter_repr.py +++ b/tests/test_filter_repr.py @@ -1,5 +1,5 @@ -from moban.filters.repr import repr as repr_function from nose.tools import eq_ +from moban.filters.repr import repr as repr_function def test_string(): diff --git a/tests/test_main.py b/tests/test_main.py index 1159a42e..87e5aadd 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,9 +1,10 @@ import os import sys from shutil import copyfile -from nose.tools import raises -from mock import patch + import moban.exceptions as exceptions +from mock import patch +from nose.tools import raises class TestException: diff --git a/tests/test_moban_file.py b/tests/test_moban_file.py index 1c2a6342..56a5fea6 100644 --- a/tests/test_moban_file.py +++ b/tests/test_moban_file.py @@ -1,5 +1,5 @@ -from nose.tools import eq_ from mock import patch +from nose.tools import eq_ class TestFinder: diff --git a/tests/test_reporter.py b/tests/test_reporter.py index 2bb03f38..4f6865f4 100644 --- a/tests/test_reporter.py +++ b/tests/test_reporter.py @@ -1,6 +1,7 @@ import sys -from mock import patch + import moban.reporter as reporter +from mock import patch from nose.tools import eq_ PY2 = sys.version_info[0] == 2 diff --git a/tests/test_template.py b/tests/test_template.py index 462e6c05..b9d7f8a8 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -1,4 +1,5 @@ import os + from mock import patch from moban.engine import Engine diff --git a/tests/test_text_filter.py b/tests/test_text_filter.py index 3afddff0..e49cd646 100644 --- a/tests/test_text_filter.py +++ b/tests/test_text_filter.py @@ -1,5 +1,5 @@ -from moban.filters.text import split_length from nose.tools import eq_ +from moban.filters.text import split_length def test_split_length(): diff --git a/tests/test_utils.py b/tests/test_utils.py index 5691c0ec..4289d048 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,14 +1,19 @@ import os import stat from shutil import rmtree -from mock import patch + +from mock import Mock, patch from nose.tools import eq_, raises -from moban.utils import file_permissions_copy -from moban.utils import file_permissions -from moban.utils import write_file_out -from moban.utils import strip_off_trailing_new_lines, get_repo_name -from moban.utils import mkdir_p, expand_directories, get_template_path -from mock import Mock +from moban.utils import ( + mkdir_p, + get_repo_name, + write_file_out, + file_permissions, + get_template_path, + expand_directories, + file_permissions_copy, + strip_off_trailing_new_lines, +) from moban.exceptions import FileNotFound @@ -35,7 +40,7 @@ def test_file_permission_copy(): @raises(FileNotFound) def test_file_permissions_file_not_found(): - file_permissions('I does not exist') + file_permissions("I does not exist") def test_file_permission_copy_symlink(): @@ -122,12 +127,7 @@ def test_git_clone(fake_check_all): def test_get_repo_name(): - repos = [ - "https://github.com/abc/repo", - "https://github.com/abc/repo/" - ] - actual = [ - get_repo_name(repo) for repo in repos - ] - expected = ['repo', 'repo'] + repos = ["https://github.com/abc/repo", "https://github.com/abc/repo/"] + actual = [get_repo_name(repo) for repo in repos] + expected = ["repo", "repo"] eq_(expected, actual) diff --git a/tests/test_yaml_loader.py b/tests/test_yaml_loader.py index b15587a4..5028e18a 100644 --- a/tests/test_yaml_loader.py +++ b/tests/test_yaml_loader.py @@ -1,5 +1,6 @@ import os -from nose.tools import raises, eq_ + +from nose.tools import eq_, raises from moban.utils import open_yaml From 6decf35b01b9c8e678438587d52a8ea9a841f211 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:43:36 +0000 Subject: [PATCH 14/17] :bug: fix test issues --- CONTRIBUTING.md | 4 ++++ tests/requirements.txt | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8013faad..434e0276 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,10 @@ $ pip install tests/requirements.txt $ make ``` +## In order to format the code automatically + +you will need python 3.6 to run "make format" + When you enable travis-ci on your own account, you shall see travis-ci running a build on each of your pushed commit to your own fork. ## Steps for creating a Pull Request diff --git a/tests/requirements.txt b/tests/requirements.txt index 3da77aa1..7730caf8 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -4,5 +4,5 @@ coverage mock flake8 moban -black -isort +black;python_version>="3.6" +isort;python_version>="3.6" From 45d1b8fb46cacb46273f45a3bb6559bce0a0e417 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:50:18 +0000 Subject: [PATCH 15/17] :eggs: :ferris_wheel: release 0.3.1. support git repo --- .moban.cd/moban.yml | 2 +- docs/conf.py | 2 +- setup.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 22dad202..b4f13f0a 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -5,7 +5,7 @@ contact: wangc_2011@hotmail.com license: MIT version: 0.3.1 current_version: 0.3.1 -release: 0.3.0 +release: 0.3.1 branch: master command_line_interface: "moban" entry_point: "moban.main:main" diff --git a/docs/conf.py b/docs/conf.py index 81d88f41..ce937530 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ author = u'C. W.' # The short X.Y version -version = u'0.3.0' +version = u'0.3.1' # The full version, including alpha/beta/rc tags release = u'0.3.1' diff --git a/setup.py b/setup.py index 50e546e7..49754db7 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ 'Yet another jinja2 cli command for static text generation' ) URL = 'https://github.com/moremoban/moban' -DOWNLOAD_URL = '%s/archive/0.3.0.tar.gz' % URL +DOWNLOAD_URL = '%s/archive/0.3.1.tar.gz' % URL FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst'] KEYWORDS = [ 'jinja2', @@ -58,8 +58,8 @@ # You do not need to read beyond this line PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format( sys.executable) -GS_COMMAND = ('gs moban v0.3.0 ' + - "Find 0.3.0 in changelog for more details") +GS_COMMAND = ('gs moban v0.3.1 ' + + "Find 0.3.1 in changelog for more details") NO_GS_MESSAGE = ('Automatic github release is disabled. ' + 'Please install gease to enable it.') UPLOAD_FAILED_MSG = ( From 0a90ccb3ef0594baebee191502e151249f18f7b7 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:52:15 +0000 Subject: [PATCH 16/17] :books: update release date --- .moban.cd/changelog.yml | 2 +- CHANGELOG.rst | 2 +- setup.py | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 246d7c0e..96184f99 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -5,7 +5,7 @@ releases: - action: Added details: - "`#97`: requires will clone a repo if given. Note: only github, gitlab, bitbucket for now" - date: unreleased + date: 02-11-2018 version: 0.3.1 - changes: - action: Added diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f24f9cc4..98b46016 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ Change log ================================================================================ -0.3.1 - unreleased +0.3.1 - 02-11-2018 -------------------------------------------------------------------------------- Added diff --git a/setup.py b/setup.py index 1d321a88..49754db7 100644 --- a/setup.py +++ b/setup.py @@ -5,9 +5,7 @@ import sys import codecs from shutil import rmtree - -from setuptools import Command, setup, find_packages - +from setuptools import setup, find_packages, Command PY2 = sys.version_info[0] == 2 PY26 = PY2 and sys.version_info[1] < 7 From 51f8351b46758fdb32fb138845e1d35f3e095b52 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 2 Nov 2018 23:56:23 +0000 Subject: [PATCH 17/17] :art: minor tweaking --- docs/level-10-moban-dependency-as-git-repo/config.yml | 2 +- docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 | 2 +- tests/test_docs.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/level-10-moban-dependency-as-git-repo/config.yml b/docs/level-10-moban-dependency-as-git-repo/config.yml index 97ee12f9..7a525ab2 100644 --- a/docs/level-10-moban-dependency-as-git-repo/config.yml +++ b/docs/level-10-moban-dependency-as-git-repo/config.yml @@ -1 +1 @@ -level9: "moban dependency as pypi package" +level10: "moban dependency as git repo" \ No newline at end of file diff --git a/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 b/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 index 1f57ab9b..b39cb6a3 100644 --- a/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 +++ b/docs/level-10-moban-dependency-as-git-repo/local/demo.txt.jj2 @@ -1 +1 @@ -{{level9}} \ No newline at end of file +{{level10}} \ No newline at end of file diff --git a/tests/test_docs.py b/tests/test_docs.py index ac5a607c..274565fb 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -96,7 +96,7 @@ def test_level_9(self): self._raw_moban(["moban"], folder, expected, "test.txt") def test_level_10(self): - expected = "moban dependency as pypi package" + expected = "moban dependency as git repo" folder = "level-10-moban-dependency-as-git-repo" self._raw_moban(["moban"], folder, expected, "test.txt")