Merge lp:~sergiusens/snapcraft/mercury into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov
Status: Merged
Approved by: Leo Arias
Approved revision: 128
Merged at revision: 128
Proposed branch: lp:~sergiusens/snapcraft/mercury
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 221 lines (+126/-16)
7 files modified
debian/control (+2/-0)
integration-tests/data/hg-branch/snapcraft.yaml (+6/-0)
integration-tests/data/hg-head/snapcraft.yaml (+5/-0)
integration-tests/data/hg-tag/snapcraft.yaml (+6/-0)
integration-tests/units/jobs.pxu (+51/-0)
snapcraft/__init__.py (+24/-0)
snapcraft/tests/test_base_plugin.py (+32/-16)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/mercury
Reviewer Review Type Date Requested Status
Leo Arias (community) reviewed, tested Approve
Michael Terry (community) Needs Fixing
Review via email: mp+267080@code.launchpad.net

Commit message

Adding support for mercurial sources (includes debian/control dependency change).

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

Running ./runtests.sh reveals some pep8 failures.

Also, you should expand the unit tests in snapcraft/tests/test_base_plugin.py for this.

review: Needs Fixing
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

> Running ./runtests.sh reveals some pep8 failures.

Fixed.

> Also, you should expand the unit tests in snapcraft/tests/test_base_plugin.py
> for this.

I expanded the unit tests to be on par with git (which is only checking for tag + branch)

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

El miércoles, 5 de agosto de 2015 15h'15:49 ART, Sergio Schvezov escribió:
>> Running ./runtests.sh reveals some pep8 failures.
>
> Fixed.
>
>> Also, you should expand the unit tests in
>> snapcraft/tests/test_base_plugin.py
>> for this.
>
> I expanded the unit tests to be on par with git (which is only
> checking for tag + branch)

The merge proposal should be now

--
Sent using Dekko from my Ubuntu device

Revision history for this message
Leo Arias (elopio) wrote :

Looks good. And all the code you added is covered by tests, so get yourself a smiley sticker.

review: Approve (reviewed, tested)
Revision history for this message
Leo Arias (elopio) wrote :

oh wait, holding the top-approval. I think that the mercurial dependency should be added as a package dependency.
Also, if you don't mention it on the commit message you'll get a grumpy ogra. A grumpier ogra ;)

lp:~sergiusens/snapcraft/mercury updated
128. By Sergio Schvezov

Adding a runtime dep for mercurial

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-08-05 20:50:45 +0000
3+++ debian/control 2015-08-06 00:21:03 +0000
4@@ -7,6 +7,7 @@
5 debhelper (>= 9),
6 dh-python,
7 git,
8+ mercurial,
9 pep8,
10 plainbox,
11 pyflakes,
12@@ -32,6 +33,7 @@
13 git,
14 python3-apt,
15 python3-yaml,
16+ mercurial,
17 sudo,
18 ubuntu-snappy-cli,
19 wget,
20
21=== added directory 'integration-tests/data/hg-branch'
22=== added file 'integration-tests/data/hg-branch/snapcraft.yaml'
23--- integration-tests/data/hg-branch/snapcraft.yaml 1970-01-01 00:00:00 +0000
24+++ integration-tests/data/hg-branch/snapcraft.yaml 2015-08-06 00:21:03 +0000
25@@ -0,0 +1,6 @@
26+parts:
27+ mercurial:
28+ plugin: make-project
29+ source: .
30+ source-type: hg
31+ source-branch: second
32
33=== added directory 'integration-tests/data/hg-head'
34=== added file 'integration-tests/data/hg-head/snapcraft.yaml'
35--- integration-tests/data/hg-head/snapcraft.yaml 1970-01-01 00:00:00 +0000
36+++ integration-tests/data/hg-head/snapcraft.yaml 2015-08-06 00:21:03 +0000
37@@ -0,0 +1,5 @@
38+parts:
39+ mercurial:
40+ plugin: make-project
41+ source: .
42+ source-type: hg
43
44=== added directory 'integration-tests/data/hg-tag'
45=== added file 'integration-tests/data/hg-tag/snapcraft.yaml'
46--- integration-tests/data/hg-tag/snapcraft.yaml 1970-01-01 00:00:00 +0000
47+++ integration-tests/data/hg-tag/snapcraft.yaml 2015-08-06 00:21:03 +0000
48@@ -0,0 +1,6 @@
49+parts:
50+ mercurial:
51+ plugin: make-project
52+ source: .
53+ source-type: hg
54+ source-tag: initial
55
56=== modified file 'integration-tests/units/jobs.pxu'
57--- integration-tests/units/jobs.pxu 2015-08-05 14:38:33 +0000
58+++ integration-tests/units/jobs.pxu 2015-08-06 00:21:03 +0000
59@@ -247,3 +247,54 @@
60 test "$(git -C parts/git/src log -2 --oneline | cut -d' ' -f2 | tr '\n' ' ')" = "3 1 "
61 ${SNAPCRAFT} pull
62 test "$(git -C parts/git/src log -2 --oneline | cut -d' ' -f2 | tr '\n' ' ')" = "3 1 "
63+
64+id: snapcraft/normal/hg-head
65+plugin: shell
66+estimated_duration: 0.3
67+command:
68+ set -ex
69+ cp -rT $PLAINBOX_PROVIDER_DATA/hg-head .
70+ hg init .
71+ touch 1
72+ hg commit -m "1" --user "Example Dev" -A 1
73+ touch 2
74+ hg commit -m "2" --user "Example Dev" -A 2
75+ ${SNAPCRAFT} pull
76+ test "$(hg log --cwd parts/mercurial/src --template "{desc}" -r -1)" = "2"
77+ ${SNAPCRAFT} pull
78+ test "$(hg log --cwd parts/mercurial/src --template "{desc}" -r -1)" = "2"
79+
80+id: snapcraft/normal/hg-tag
81+plugin: shell
82+estimated_duration: 0.3
83+command:
84+ set -ex
85+ cp -rT $PLAINBOX_PROVIDER_DATA/hg-tag .
86+ hg init .
87+ touch 1
88+ hg commit -m "1" --user "Example Dev" -A 1
89+ hg tag initial --user "Example Dev"
90+ touch 2
91+ hg commit -m "2" --user "Example Dev" -A 2
92+ ${SNAPCRAFT} pull
93+ test "$(ls -1 parts/mercurial/src/ | wc -l )" = "1"
94+ ${SNAPCRAFT} pull
95+ test "$(ls -1 parts/mercurial/src/ | wc -l )" = "1"
96+
97+id: snapcraft/normal/hg-branch
98+plugin: shell
99+estimated_duration: 0.3
100+command:
101+ set -ex
102+ cp -rT $PLAINBOX_PROVIDER_DATA/hg-branch .
103+ hg init .
104+ hg branch second
105+ touch second
106+ hg commit -m "second" --user "Example Dev" -A second
107+ hg branch default
108+ touch default
109+ hg commit -m "default" --user "Example Dev" -A default
110+ ${SNAPCRAFT} pull
111+ test -e parts/mercurial/src/second
112+ ${SNAPCRAFT} pull
113+ test -e parts/mercurial/src/second
114
115=== modified file 'snapcraft/__init__.py'
116--- snapcraft/__init__.py 2015-08-04 15:16:11 +0000
117+++ snapcraft/__init__.py 2015-08-06 00:21:03 +0000
118@@ -75,6 +75,25 @@
119 os.rmdir(self.sourcedir)
120 return self.run(['bzr', 'branch'] + tag_opts + [source, self.sourcedir], cwd=os.getcwd())
121
122+ def pull_hg(self, source, source_tag=None, source_branch=None):
123+ if source_tag and source_branch:
124+ logger.error("You can't specify both source-tag and source-branch for a mercurial source (part '%s')." % self.name)
125+ snapcraft.common.fatal()
126+
127+ if os.path.exists(os.path.join(self.sourcedir, ".hg")):
128+ ref = []
129+ if source_tag:
130+ ref = ['-r', source_tag]
131+ elif source_branch:
132+ ref = ['-b', source_branch]
133+ return self.run(['hg', 'pull'] + ref + [source, ], cwd=os.getcwd())
134+ else:
135+ ref = []
136+ if source_tag or source_branch:
137+ ref = ['-u', source_tag or source_branch]
138+
139+ return self.run(['hg', 'clone'] + ref + [source, self.sourcedir], cwd=os.getcwd())
140+
141 def pull_git(self, source, source_tag=None, source_branch=None):
142 if source_tag and source_branch:
143 logger.error("You can't specify both source-tag and source-branch for a git source (part '%s')." % self.name)
144@@ -164,6 +183,11 @@
145 return False
146 if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]):
147 return False
148+ elif source_type == 'hg' or source_type == 'mercurial':
149+ if not self.pull_hg(source, source_tag=source_tag, source_branch=source_branch):
150+ return False
151+ if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]):
152+ return False
153 elif source_type == 'tar':
154 if source_branch:
155 logger.error("You can't specify source-branch for a tar source (part '%s')." % self.name)
156
157=== modified file 'snapcraft/tests/test_base_plugin.py'
158--- snapcraft/tests/test_base_plugin.py 2015-08-04 15:16:11 +0000
159+++ snapcraft/tests/test_base_plugin.py 2015-08-06 00:21:03 +0000
160@@ -49,22 +49,6 @@
161 self.assertFalse(plugin.isurl('/foo'))
162 self.assertFalse(plugin.isurl('/fo:o'))
163
164- def test_pull_git_with_tag_and_branch_must_raise_error(self):
165- fake_logger = fixtures.FakeLogger(level=logging.ERROR)
166- self.useFixture(fake_logger)
167-
168- plugin = snapcraft.BasePlugin('test_plugin', 'dummy_options')
169- with self.assertRaises(SystemExit) as raised:
170- plugin.pull_git(
171- 'dummy_source', source_tag='test_tag',
172- source_branch='test_branch')
173-
174- self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
175- expected = (
176- "You can't specify both source-tag and source-branch for a git "
177- "source (part 'test_plugin').\n")
178- self.assertEqual(expected, fake_logger.output)
179-
180 def test_pull_tarball_must_download_to_sourcedir(self):
181 server = http.server.HTTPServer(('', 0), FakeTarballHTTPRequestHandler)
182 server_thread = threading.Thread(target=server.serve_forever)
183@@ -111,6 +95,38 @@
184 self.assertTrue(os.path.exists(path))
185
186
187+class GetSourceWithBranches(tests.TestCase):
188+
189+ scenarios = [
190+ ('git with source branch and tag', {
191+ 'source_type': 'git',
192+ 'source_branch': 'test_branch',
193+ 'source_tag': 'tag',
194+ }),
195+ ('hg with source branch and tag', {
196+ 'source_type': 'mercurial',
197+ 'source_branch': 'test_branch',
198+ 'source_tag': 'tag',
199+ }),
200+ ]
201+
202+ def test_get_source_with_branch_and_tag_must_raise_error(self):
203+ fake_logger = fixtures.FakeLogger(level=logging.ERROR)
204+ self.useFixture(fake_logger)
205+
206+ plugin = snapcraft.BasePlugin('test_plugin', 'dummy_options')
207+ with self.assertRaises(SystemExit) as raised:
208+ plugin.get_source(
209+ 'dummy_source', source_type=self.source_type,
210+ source_branch=self.source_branch, source_tag=self.source_tag)
211+
212+ self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
213+ expected = (
214+ "You can't specify both source-tag and source-branch for a {} "
215+ "source (part 'test_plugin').\n".format(self.source_type))
216+ self.assertEqual(expected, fake_logger.output)
217+
218+
219 class GetSourceTestCase(tests.TestCase):
220
221 scenarios = [

Subscribers

People subscribed via source and target branches