diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 3d822bd3..d899c1e7 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -4,8 +4,14 @@ releases: - changes: - action: Added details: - - "`requires` shall support configuration dirs. In other words, configuration file could be stored in python package or git repository." + - "alternative and expanded syntax for requires, so as to accomendate github submodule recursive" date: 05-11-2018 + version: 0.3.3 +- changes: + - action: Added + details: + - "`requires` shall support configuration dirs. In other words, configuration file could be stored in python package or git repository." + date: 04-11-2018 version: 0.3.2 - changes: - action: Added diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 32bd767d..a36be3eb 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -3,9 +3,9 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.3.2 -current_version: 0.3.2 -release: 0.3.2 +version: 0.3.3 +current_version: 0.3.3 +release: 0.3.3 branch: master command_line_interface: "moban" entry_point: "moban.main:main" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index de0defce..bfa01b0c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,16 @@ Change log ================================================================================ -0.3.2 - 05-11-2018 +0.3.3 - 05-11-2018 +-------------------------------------------------------------------------------- + +Added +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. alternative and expanded syntax for requires, so as to accomendate github + submodule recursive + +0.3.2 - 04-11-2018 -------------------------------------------------------------------------------- Added diff --git a/docs/conf.py b/docs/conf.py index 095c5611..2a3d7184 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,9 +28,9 @@ author = u'C. W.' # The short X.Y version -version = u'0.3.2' +version = u'0.3.3' # The full version, including alpha/beta/rc tags -release = u'0.3.2' +release = u'0.3.3' # -- 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 7a711c31..6733c3e2 100644 --- a/docs/level-10-moban-dependency-as-git-repo/README.rst +++ b/docs/level-10-moban-dependency-as-git-repo/README.rst @@ -23,4 +23,17 @@ Here are the sample file:: - test.txt: demo.txt.jj2 where `requires` lead to a list of pypi packages. And when you refer to it, -please use "pypi-mobans:" +as in level-9 section, please use "pypi-mobans:" + + +Alternative syntax when submodule exists +-------------------------------------------------------------------------------- + +The alternative syntax is:: + + requires: + - type: git + url: https://github.com/your-git-url + submodule: true + ... + diff --git a/docs/level-9-moban-dependency-as-pypi-package/README.rst b/docs/level-9-moban-dependency-as-pypi-package/README.rst index 800ec3c6..7bc94496 100644 --- a/docs/level-9-moban-dependency-as-pypi-package/README.rst +++ b/docs/level-9-moban-dependency-as-pypi-package/README.rst @@ -21,5 +21,29 @@ Here are the sample file:: - 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:" +where `requires` lead to a list of pypi packages. The short syntax is:: + + requires: + - python-package-name + +When you refer to it in configuration section, here is the syntax:: + + configuration: + - template_dir: + - "python-package-name:relative-folder-inside-the-package" + +Note: when you do not have relative directory, please keep semi-colon:: + + configuration: + template_dir: + - "python-package-name:" + +Alternative syntax +-------------------------------------------------------------------------------- + +The alternative syntax is:: + + requires: + - type: pypi + name: pypi-mobans + ... diff --git a/moban/_version.py b/moban/_version.py index 7e9c9817..96dc8dbe 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.3.2" +__version__ = "0.3.3" __author__ = "C. W." diff --git a/moban/constants.py b/moban/constants.py index a141d5c8..2871ef76 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -72,6 +72,14 @@ ERROR = 2 NO_CHANGES = 0 +# Require +GIT_REQUIRE = "GIT" +GIT_HAS_SUBMODULE = "submodule" +GIT_URL = "url" +PYPI_REQUIRE = "PYPI" +PYPI_PACKAGE_NAME = "name" +REQUIRE_TYPE = "type" + # Extension JINJA_FILTER_EXTENSION = "jinja_filter" diff --git a/moban/mobanfile.py b/moban/mobanfile.py index 75102b0e..b9a0062b 100644 --- a/moban/mobanfile.py +++ b/moban/mobanfile.py @@ -156,15 +156,29 @@ def extract_target(options): def handle_requires(requires): pypi_pkgs = [] git_repos = [] + git_repos_with_sub = [] for require in requires: - if is_repo(require): - git_repos.append(require) + if isinstance(require, dict): + require_type = require.get(constants.REQUIRE_TYPE, "") + if require_type.upper() == constants.GIT_REQUIRE: + submodule_flag = require.get(constants.GIT_HAS_SUBMODULE) + if submodule_flag is True: + git_repos_with_sub.append(require.get(constants.GIT_URL)) + else: + git_repos.append(require.get(constants.GIT_URL)) + elif require_type.upper() == constants.PYPI_REQUIRE: + pypi_pkgs.append(require.get(constants.PYPI_PACKAGE_NAME)) else: - pypi_pkgs.append(require) + 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) + if git_repos_with_sub: + git_clone(git_repos_with_sub, submodule=True) def is_repo(require): diff --git a/moban/utils.py b/moban/utils.py index c7bf71ab..4ca03716 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -149,7 +149,7 @@ def pip_install(packages): ) -def git_clone(repos): +def git_clone(repos, submodule=False): import subprocess moban_home = get_moban_home() @@ -163,10 +163,16 @@ def git_clone(repos): reporter.report_git_pull(repo_name) os.chdir(local_repo_folder) subprocess.check_call(["git", "pull"]) + if submodule: + subprocess.check_call(["git", "submodule", "update"]) else: reporter.report_git_clone(repo_name) os.chdir(moban_home) subprocess.check_call(["git", "clone", repo, repo_name]) + if submodule: + os.chdir(os.path.join(moban_home, repo_name)) + subprocess.check_call(["git", "submodule", "init"]) + subprocess.check_call(["git", "submodule", "update"]) os.chdir(current_working_dir) diff --git a/setup.py b/setup.py index c555ca6a..f79b17a5 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ NAME = 'moban' AUTHOR = 'C. W.' -VERSION = '0.3.2' +VERSION = '0.3.3' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'MIT' ENTRY_POINTS = { @@ -25,7 +25,7 @@ 'Yet another jinja2 cli command for static text generation' ) URL = 'https://github.com/moremoban/moban' -DOWNLOAD_URL = '%s/archive/0.3.2.tar.gz' % URL +DOWNLOAD_URL = '%s/archive/0.3.3.tar.gz' % URL FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst'] KEYWORDS = [ 'jinja2', @@ -60,8 +60,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.2 ' + - "Find 0.3.2 in changelog for more details") +GS_COMMAND = ('gs moban v0.3.3 ' + + "Find 0.3.3 in changelog for more details") NO_GS_MESSAGE = ('Automatic github release is disabled. ' + 'Please install gease to enable it.') UPLOAD_FAILED_MSG = ( diff --git a/tests/test_moban_file.py b/tests/test_moban_file.py index 56a5fea6..8c07531f 100644 --- a/tests/test_moban_file.py +++ b/tests/test_moban_file.py @@ -43,6 +43,15 @@ def test_handle_requires_pypkg(fake_pip_install): fake_pip_install.assert_called_with(modules) +@patch("moban.mobanfile.pip_install") +def test_handle_requires_pypkg_with_alternative_syntax(fake_pip_install): + modules = [{"type": "pypi", "name": "pypi-mobans"}] + from moban.mobanfile import handle_requires + + handle_requires(modules) + fake_pip_install.assert_called_with(["pypi-mobans"]) + + @patch("moban.mobanfile.git_clone") def test_handle_requires_repos(fake_git_clone): repos = ["https://github.com/my/repo", "https://gitlab.com/my/repo"] @@ -52,6 +61,27 @@ def test_handle_requires_repos(fake_git_clone): fake_git_clone.assert_called_with(repos) +@patch("moban.mobanfile.git_clone") +def test_handle_requires_repos_with_alternative_syntax(fake_git_clone): + repos = [{"type": "git", "url": "https://github.com/my/repo"}] + from moban.mobanfile import handle_requires + + handle_requires(repos) + fake_git_clone.assert_called_with(["https://github.com/my/repo"]) + + +@patch("moban.mobanfile.git_clone") +def test_handle_requires_repos_with_submodule(fake_git_clone): + repos = [ + {"type": "git", "url": "https://github.com/my/repo", "submodule": True} + ] + from moban.mobanfile import handle_requires + + expected = ["https://github.com/my/repo"] + handle_requires(repos) + fake_git_clone.assert_called_with(expected, submodule=True) + + def test_is_repo(): repos = [ "https://github.com/my/repo", diff --git a/tests/test_utils.py b/tests/test_utils.py index 4289d048..30eb212f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -126,6 +126,31 @@ def test_git_clone(fake_check_all): ) +@patch("os.chdir") +@patch("subprocess.check_call") +def test_git_clone_with_submodules(fake_check_all, _): + from moban.utils import git_clone + + git_clone( + ["https://github.com/my/repo", "https://gitlab.com/my/repo"], + submodule=True, + ) + fake_check_all.assert_called_with(["git", "submodule", "update"]) + + +@patch("os.path.exists", return_value=True) +@patch("os.chdir") +@patch("subprocess.check_call") +def test_git_clone_with_existing_repo(fake_check_all, _, __): + from moban.utils import git_clone + + git_clone( + ["https://github.com/my/repo", "https://gitlab.com/my/repo"], + submodule=True, + ) + fake_check_all.assert_called_with(["git", "submodule", "update"]) + + 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]