Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: moban
organisation: moremoban
releases:
- changes:
- action: Added
details:
- "alternative and expanded syntax for requires, so as to accomendate github submodule recursive"
date: unreleased
version: 0.3.3
- changes:
- action: Added
details:
Expand Down
4 changes: 2 additions & 2 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ organisation: moremoban
author: C. W.
contact: wangc_2011@hotmail.com
license: MIT
version: 0.3.2
current_version: 0.3.2
version: 0.3.3
current_version: 0.3.3
release: 0.3.2
branch: master
command_line_interface: "moban"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change log
================================================================================

0.3.3 - unreleased
--------------------------------------------------------------------------------

Added
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. alternative and expanded syntax for requires, so as to accomendate github
submodule recursive

0.3.2 - 05-11-2018
--------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# The short X.Y version
version = u'0.3.2'
# The full version, including alpha/beta/rc tags
release = u'0.3.2'
release = u'0.3.3'


# -- General configuration ---------------------------------------------------
Expand Down
15 changes: 14 additions & 1 deletion docs/level-10-moban-dependency-as-git-repo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
...

28 changes: 26 additions & 2 deletions docs/level-9-moban-dependency-as-pypi-package/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
2 changes: 1 addition & 1 deletion moban/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.3.2"
__version__ = "0.3.3"
__author__ = "C. W."
8 changes: 8 additions & 0 deletions moban/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 17 additions & 3 deletions moban/mobanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion moban/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
30 changes: 30 additions & 0 deletions tests/test_moban_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down