Skip to content

Commit ca3d26e

Browse files
committed
✨ support repo in requires syntax. resolves #97
1 parent 834162e commit ca3d26e

File tree

7 files changed

+88
-3
lines changed

7 files changed

+88
-3
lines changed

Diff for: .moban.cd/changelog.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: moban
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: Added
6+
details:
7+
- "`#97`: requires will clone a repo if given. Note: only github, gitlab, bitbucket for now"
8+
date: unreleased
9+
version: 0.3.1
410
- changes:
511
- action: Added
612
details:

Diff for: .moban.d/setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
{%block platform_block%}
44
{%endblock%}
5+
6+
{%block morefiles%} 'CONTRIBUTORS.rst',{%endblock%}

Diff for: CHANGELOG.rst

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Change log
22
================================================================================
33

4+
0.3.1 - unreleased
5+
--------------------------------------------------------------------------------
6+
7+
Added
8+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
10+
#. `#97 <https://github.com/moremoban/moban/issues/97>`_: requires will clone a
11+
repo if given. Note: only github, gitlab, bitbucket for now
12+
413
0.3.0 - 27-18-2018
514
--------------------------------------------------------------------------------
615

Diff for: moban/mobanfile.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import moban.constants as constants
99
import moban.reporter as reporter
1010
from moban.engine import ENGINES
11-
from moban.utils import merge, parse_targets
11+
from moban.utils import merge, parse_targets, git_clone
1212
from moban.utils import expand_directories, pip_install
1313
from moban.copier import Copier
1414

@@ -137,4 +137,25 @@ def extract_target(options):
137137

138138

139139
def handle_requires(requires):
140-
pip_install(requires)
140+
pypi_pkgs = []
141+
git_repos = []
142+
for require in requires:
143+
if is_repo(require):
144+
git_repos.append(require)
145+
else:
146+
pypi_pkgs.append(require)
147+
if pypi_pkgs:
148+
pip_install(pypi_pkgs)
149+
if git_repos:
150+
git_clone(git_repos)
151+
152+
153+
def is_repo(require):
154+
return (
155+
require.startswith('http') and
156+
(
157+
'github.com' in require or
158+
'gitlab.com' in require or
159+
'bitbucket.com' in require
160+
)
161+
)

Diff for: moban/utils.py

+9
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ def pip_install(packages):
147147
)
148148

149149

150+
def git_clone(repos):
151+
import subprocess
152+
153+
for repo in repos:
154+
subprocess.check_call(
155+
['git', 'clone', repo]
156+
)
157+
158+
150159
def get_template_path(template_dirs, template):
151160
temp_dir = ""
152161
for a_dir in template_dirs:

Diff for: tests/test_moban_file.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,37 @@ def test_no_moban_file(self):
3535

3636

3737
@patch("moban.mobanfile.pip_install")
38-
def test_handle_requires(fake_pip_install):
38+
def test_handle_requires_pypkg(fake_pip_install):
3939
modules = ["package1", "package2"]
4040
from moban.mobanfile import handle_requires
4141

4242
handle_requires(modules)
4343
fake_pip_install.assert_called_with(modules)
44+
45+
46+
@patch("moban.mobanfile.git_clone")
47+
def test_handle_requires_repos(fake_git_clone):
48+
repos = ["https://github.com/my/repo", "https://gitlab.com/my/repo"]
49+
from moban.mobanfile import handle_requires
50+
51+
handle_requires(repos)
52+
fake_git_clone.assert_called_with(repos)
53+
54+
55+
def test_is_repo():
56+
repos = [
57+
"https://github.com/my/repo",
58+
"https://gitlab.com/my/repo",
59+
"https://bitbucket.com/my/repo",
60+
"https://unsupported.com/my/repo",
61+
"invalid/repo/rul"
62+
]
63+
from moban.mobanfile import is_repo
64+
65+
actual = [
66+
is_repo(repo) for repo in repos
67+
]
68+
expected = [
69+
True, True, True, False, False
70+
]
71+
eq_(expected, actual)

Diff for: tests/test_utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,13 @@ def test_pip_install(fake_check_all):
102102
fake_check_all.assert_called_with(
103103
[sys.executable, "-m", "pip", "install", "package1 package2"]
104104
)
105+
106+
107+
@patch("subprocess.check_call")
108+
def test_git_clone(fake_check_all):
109+
from moban.utils import git_clone
110+
111+
git_clone(["https://github.com/my/repo", "https://gitlab.com/my/repo"])
112+
fake_check_all.assert_called_with(
113+
["git", "clone", "https://gitlab.com/my/repo"]
114+
)

0 commit comments

Comments
 (0)