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
=== modified file 'debian/control'
--- debian/control 2015-08-05 20:50:45 +0000
+++ debian/control 2015-08-06 00:21:03 +0000
@@ -7,6 +7,7 @@
7 debhelper (>= 9),7 debhelper (>= 9),
8 dh-python,8 dh-python,
9 git,9 git,
10 mercurial,
10 pep8,11 pep8,
11 plainbox,12 plainbox,
12 pyflakes,13 pyflakes,
@@ -32,6 +33,7 @@
32 git,33 git,
33 python3-apt,34 python3-apt,
34 python3-yaml,35 python3-yaml,
36 mercurial,
35 sudo,37 sudo,
36 ubuntu-snappy-cli,38 ubuntu-snappy-cli,
37 wget,39 wget,
3840
=== added directory 'integration-tests/data/hg-branch'
=== added file 'integration-tests/data/hg-branch/snapcraft.yaml'
--- integration-tests/data/hg-branch/snapcraft.yaml 1970-01-01 00:00:00 +0000
+++ integration-tests/data/hg-branch/snapcraft.yaml 2015-08-06 00:21:03 +0000
@@ -0,0 +1,6 @@
1parts:
2 mercurial:
3 plugin: make-project
4 source: .
5 source-type: hg
6 source-branch: second
07
=== added directory 'integration-tests/data/hg-head'
=== added file 'integration-tests/data/hg-head/snapcraft.yaml'
--- integration-tests/data/hg-head/snapcraft.yaml 1970-01-01 00:00:00 +0000
+++ integration-tests/data/hg-head/snapcraft.yaml 2015-08-06 00:21:03 +0000
@@ -0,0 +1,5 @@
1parts:
2 mercurial:
3 plugin: make-project
4 source: .
5 source-type: hg
06
=== added directory 'integration-tests/data/hg-tag'
=== added file 'integration-tests/data/hg-tag/snapcraft.yaml'
--- integration-tests/data/hg-tag/snapcraft.yaml 1970-01-01 00:00:00 +0000
+++ integration-tests/data/hg-tag/snapcraft.yaml 2015-08-06 00:21:03 +0000
@@ -0,0 +1,6 @@
1parts:
2 mercurial:
3 plugin: make-project
4 source: .
5 source-type: hg
6 source-tag: initial
07
=== modified file 'integration-tests/units/jobs.pxu'
--- integration-tests/units/jobs.pxu 2015-08-05 14:38:33 +0000
+++ integration-tests/units/jobs.pxu 2015-08-06 00:21:03 +0000
@@ -247,3 +247,54 @@
247 test "$(git -C parts/git/src log -2 --oneline | cut -d' ' -f2 | tr '\n' ' ')" = "3 1 "247 test "$(git -C parts/git/src log -2 --oneline | cut -d' ' -f2 | tr '\n' ' ')" = "3 1 "
248 ${SNAPCRAFT} pull248 ${SNAPCRAFT} pull
249 test "$(git -C parts/git/src log -2 --oneline | cut -d' ' -f2 | tr '\n' ' ')" = "3 1 "249 test "$(git -C parts/git/src log -2 --oneline | cut -d' ' -f2 | tr '\n' ' ')" = "3 1 "
250
251id: snapcraft/normal/hg-head
252plugin: shell
253estimated_duration: 0.3
254command:
255 set -ex
256 cp -rT $PLAINBOX_PROVIDER_DATA/hg-head .
257 hg init .
258 touch 1
259 hg commit -m "1" --user "Example Dev" -A 1
260 touch 2
261 hg commit -m "2" --user "Example Dev" -A 2
262 ${SNAPCRAFT} pull
263 test "$(hg log --cwd parts/mercurial/src --template "{desc}" -r -1)" = "2"
264 ${SNAPCRAFT} pull
265 test "$(hg log --cwd parts/mercurial/src --template "{desc}" -r -1)" = "2"
266
267id: snapcraft/normal/hg-tag
268plugin: shell
269estimated_duration: 0.3
270command:
271 set -ex
272 cp -rT $PLAINBOX_PROVIDER_DATA/hg-tag .
273 hg init .
274 touch 1
275 hg commit -m "1" --user "Example Dev" -A 1
276 hg tag initial --user "Example Dev"
277 touch 2
278 hg commit -m "2" --user "Example Dev" -A 2
279 ${SNAPCRAFT} pull
280 test "$(ls -1 parts/mercurial/src/ | wc -l )" = "1"
281 ${SNAPCRAFT} pull
282 test "$(ls -1 parts/mercurial/src/ | wc -l )" = "1"
283
284id: snapcraft/normal/hg-branch
285plugin: shell
286estimated_duration: 0.3
287command:
288 set -ex
289 cp -rT $PLAINBOX_PROVIDER_DATA/hg-branch .
290 hg init .
291 hg branch second
292 touch second
293 hg commit -m "second" --user "Example Dev" -A second
294 hg branch default
295 touch default
296 hg commit -m "default" --user "Example Dev" -A default
297 ${SNAPCRAFT} pull
298 test -e parts/mercurial/src/second
299 ${SNAPCRAFT} pull
300 test -e parts/mercurial/src/second
250301
=== modified file 'snapcraft/__init__.py'
--- snapcraft/__init__.py 2015-08-04 15:16:11 +0000
+++ snapcraft/__init__.py 2015-08-06 00:21:03 +0000
@@ -75,6 +75,25 @@
75 os.rmdir(self.sourcedir)75 os.rmdir(self.sourcedir)
76 return self.run(['bzr', 'branch'] + tag_opts + [source, self.sourcedir], cwd=os.getcwd())76 return self.run(['bzr', 'branch'] + tag_opts + [source, self.sourcedir], cwd=os.getcwd())
7777
78 def pull_hg(self, source, source_tag=None, source_branch=None):
79 if source_tag and source_branch:
80 logger.error("You can't specify both source-tag and source-branch for a mercurial source (part '%s')." % self.name)
81 snapcraft.common.fatal()
82
83 if os.path.exists(os.path.join(self.sourcedir, ".hg")):
84 ref = []
85 if source_tag:
86 ref = ['-r', source_tag]
87 elif source_branch:
88 ref = ['-b', source_branch]
89 return self.run(['hg', 'pull'] + ref + [source, ], cwd=os.getcwd())
90 else:
91 ref = []
92 if source_tag or source_branch:
93 ref = ['-u', source_tag or source_branch]
94
95 return self.run(['hg', 'clone'] + ref + [source, self.sourcedir], cwd=os.getcwd())
96
78 def pull_git(self, source, source_tag=None, source_branch=None):97 def pull_git(self, source, source_tag=None, source_branch=None):
79 if source_tag and source_branch:98 if source_tag and source_branch:
80 logger.error("You can't specify both source-tag and source-branch for a git source (part '%s')." % self.name)99 logger.error("You can't specify both source-tag and source-branch for a git source (part '%s')." % self.name)
@@ -164,6 +183,11 @@
164 return False183 return False
165 if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]):184 if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]):
166 return False185 return False
186 elif source_type == 'hg' or source_type == 'mercurial':
187 if not self.pull_hg(source, source_tag=source_tag, source_branch=source_branch):
188 return False
189 if not self.run(['cp', '-Trfa', self.sourcedir, self.builddir]):
190 return False
167 elif source_type == 'tar':191 elif source_type == 'tar':
168 if source_branch:192 if source_branch:
169 logger.error("You can't specify source-branch for a tar source (part '%s')." % self.name)193 logger.error("You can't specify source-branch for a tar source (part '%s')." % self.name)
170194
=== modified file 'snapcraft/tests/test_base_plugin.py'
--- snapcraft/tests/test_base_plugin.py 2015-08-04 15:16:11 +0000
+++ snapcraft/tests/test_base_plugin.py 2015-08-06 00:21:03 +0000
@@ -49,22 +49,6 @@
49 self.assertFalse(plugin.isurl('/foo'))49 self.assertFalse(plugin.isurl('/foo'))
50 self.assertFalse(plugin.isurl('/fo:o'))50 self.assertFalse(plugin.isurl('/fo:o'))
5151
52 def test_pull_git_with_tag_and_branch_must_raise_error(self):
53 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
54 self.useFixture(fake_logger)
55
56 plugin = snapcraft.BasePlugin('test_plugin', 'dummy_options')
57 with self.assertRaises(SystemExit) as raised:
58 plugin.pull_git(
59 'dummy_source', source_tag='test_tag',
60 source_branch='test_branch')
61
62 self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
63 expected = (
64 "You can't specify both source-tag and source-branch for a git "
65 "source (part 'test_plugin').\n")
66 self.assertEqual(expected, fake_logger.output)
67
68 def test_pull_tarball_must_download_to_sourcedir(self):52 def test_pull_tarball_must_download_to_sourcedir(self):
69 server = http.server.HTTPServer(('', 0), FakeTarballHTTPRequestHandler)53 server = http.server.HTTPServer(('', 0), FakeTarballHTTPRequestHandler)
70 server_thread = threading.Thread(target=server.serve_forever)54 server_thread = threading.Thread(target=server.serve_forever)
@@ -111,6 +95,38 @@
111 self.assertTrue(os.path.exists(path))95 self.assertTrue(os.path.exists(path))
11296
11397
98class GetSourceWithBranches(tests.TestCase):
99
100 scenarios = [
101 ('git with source branch and tag', {
102 'source_type': 'git',
103 'source_branch': 'test_branch',
104 'source_tag': 'tag',
105 }),
106 ('hg with source branch and tag', {
107 'source_type': 'mercurial',
108 'source_branch': 'test_branch',
109 'source_tag': 'tag',
110 }),
111 ]
112
113 def test_get_source_with_branch_and_tag_must_raise_error(self):
114 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
115 self.useFixture(fake_logger)
116
117 plugin = snapcraft.BasePlugin('test_plugin', 'dummy_options')
118 with self.assertRaises(SystemExit) as raised:
119 plugin.get_source(
120 'dummy_source', source_type=self.source_type,
121 source_branch=self.source_branch, source_tag=self.source_tag)
122
123 self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
124 expected = (
125 "You can't specify both source-tag and source-branch for a {} "
126 "source (part 'test_plugin').\n".format(self.source_type))
127 self.assertEqual(expected, fake_logger.output)
128
129
114class GetSourceTestCase(tests.TestCase):130class GetSourceTestCase(tests.TestCase):
115131
116 scenarios = [132 scenarios = [

Subscribers

People subscribed via source and target branches