Skip to content

Commit

Permalink
Merge pull request #116 from moremoban/dev
Browse files Browse the repository at this point in the history
release 0.3.3
  • Loading branch information
chfw authored Nov 5, 2018
2 parents 9a322e2 + 104f82c commit 203d5c3
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 19 deletions.
8 changes: 7 additions & 1 deletion .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
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
8 changes: 4 additions & 4 deletions 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 All @@ -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',
Expand Down Expand Up @@ -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 = (
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

0 comments on commit 203d5c3

Please sign in to comment.