Merge lp:~cjwatson/launchpad/snapcraft-yaml-more-paths into lp:launchpad

Proposed by Colin Watson on 2017-02-01
Status: Merged
Merged at revision: 18321
Proposed branch: lp:~cjwatson/launchpad/snapcraft-yaml-more-paths
Merge into: lp:launchpad
Diff against target: 129 lines (+40/-19)
4 files modified
lib/lp/snappy/browser/snap.py (+12/-6)
lib/lp/snappy/browser/tests/test_snap.py (+14/-0)
lib/lp/snappy/interfaces/snap.py (+12/-11)
lib/lp/snappy/templates/snap-new.pt (+2/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snapcraft-yaml-more-paths
Reviewer Review Type Date Requested Status
William Grant code 2017-02-01 Approve on 2017-02-02
Review via email: mp+316084@code.launchpad.net

Commit message

Consider snap/snapcraft.yaml as well as other paths for new snaps.

Description of the change

snap/snapcraft.yaml comes first, to match the logic in snapcraft itself.

The strings are increasingly ugly, but hopefully they won't get too much worse from here ...

To post a comment you must log in.
William Grant (wgrant) wrote :

I'd almost be tempted to turn it into a lop at this point.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/snappy/browser/snap.py'
2--- lib/lp/snappy/browser/snap.py 2017-01-16 22:27:56 +0000
3+++ lib/lp/snappy/browser/snap.py 2017-02-02 22:56:31 +0000
4@@ -436,12 +436,18 @@
5 if self.has_snappy_distro_series and IGitRef.providedBy(self.context):
6 # Try to extract Snap store name from snapcraft.yaml file.
7 try:
8- try:
9- blob = self.context.repository.getBlob(
10- 'snapcraft.yaml', self.context.name)
11- except GitRepositoryBlobNotFound:
12- blob = self.context.repository.getBlob(
13- '.snapcraft.yaml', self.context.name)
14+ paths = (
15+ 'snap/snapcraft.yaml',
16+ 'snapcraft.yaml',
17+ '.snapcraft.yaml',
18+ )
19+ for i, path in enumerate(paths):
20+ try:
21+ blob = self.context.repository.getBlob(
22+ path, self.context.name)
23+ except GitRepositoryBlobNotFound:
24+ if i == len(paths) - 1:
25+ raise
26 # Beware of unsafe yaml.load()!
27 store_name = yaml.safe_load(blob).get('name')
28 except GitRepositoryScanFault:
29
30=== modified file 'lib/lp/snappy/browser/tests/test_snap.py'
31--- lib/lp/snappy/browser/tests/test_snap.py 2017-01-16 22:27:56 +0000
32+++ lib/lp/snappy/browser/tests/test_snap.py 2017-02-02 22:56:31 +0000
33@@ -493,6 +493,20 @@
34 self.assertIn('store_name', initial_values)
35 self.assertEqual('test-snap', initial_values['store_name'])
36
37+ def test_initial_name_extraction_git_plain_snapcraft_yaml(self):
38+ def getBlob(filename, *args, **kwargs):
39+ if filename == "snapcraft.yaml":
40+ return "name: test-snap"
41+ else:
42+ raise GitRepositoryBlobNotFound()
43+
44+ [git_ref] = self.factory.makeGitRefs()
45+ git_ref.repository.getBlob = getBlob
46+ view = create_initialized_view(git_ref, "+new-snap")
47+ initial_values = view.initial_values
48+ self.assertIn('store_name', initial_values)
49+ self.assertIsNone(initial_values['store_name'])
50+
51 def test_initial_name_extraction_git_dot_snapcraft_yaml(self):
52 def getBlob(filename, *args, **kwargs):
53 if filename == ".snapcraft.yaml":
54
55=== modified file 'lib/lp/snappy/interfaces/snap.py'
56--- lib/lp/snappy/interfaces/snap.py 2017-01-16 22:27:56 +0000
57+++ lib/lp/snappy/interfaces/snap.py 2017-02-02 22:56:31 +0000
58@@ -425,22 +425,23 @@
59 title=_("Bazaar branch"), schema=IBranch, vocabulary="Branch",
60 required=False, readonly=False,
61 description=_(
62- "A Bazaar branch containing a snapcraft.yaml or .snapcraft.yaml "
63- "recipe at the top level.")))
64+ "A Bazaar branch containing a snap/snapcraft.yaml, "
65+ "snapcraft.yaml, or .snapcraft.yaml recipe at the top level.")))
66
67 git_repository = exported(ReferenceChoice(
68 title=_("Git repository"),
69 schema=IGitRepository, vocabulary="GitRepository",
70 required=False, readonly=True,
71 description=_(
72- "A Git repository with a branch containing a snapcraft.yaml or "
73- ".snapcraft.yaml recipe at the top level.")))
74+ "A Git repository with a branch containing a snap/snapcraft.yaml, "
75+ "snapcraft.yaml, or .snapcraft.yaml recipe at the top level.")))
76
77 git_repository_url = exported(URIField(
78 title=_("Git repository URL"), required=False, readonly=True,
79 description=_(
80 "The URL of a Git repository with a branch containing a "
81- "snapcraft.yaml or .snapcraft.yaml recipe at the top level."),
82+ "snap/snapcraft.yaml, snapcraft.yaml, or .snapcraft.yaml recipe "
83+ "at the top level."),
84 allowed_schemes=["git", "http", "https"],
85 allow_userinfo=True,
86 allow_port=True,
87@@ -451,22 +452,22 @@
88 git_path = exported(TextLine(
89 title=_("Git branch path"), required=False, readonly=True,
90 description=_(
91- "The path of the Git branch containing a snapcraft.yaml or "
92- ".snapcraft.yaml recipe at the top level.")))
93+ "The path of the Git branch containing a snap/snapcraft.yaml, "
94+ "snapcraft.yaml, or .snapcraft.yaml recipe at the top level.")))
95
96 git_ref = exported(Reference(
97 IGitRef, title=_("Git branch"), required=False, readonly=False,
98 description=_(
99- "The Git branch containing a snapcraft.yaml or .snapcraft.yaml "
100- "recipe at the top level.")))
101+ "The Git branch containing a snap/snapcraft.yaml, snapcraft.yaml, "
102+ "or .snapcraft.yaml recipe at the top level.")))
103
104 auto_build = exported(Bool(
105 title=_("Automatically build when branch changes"),
106 required=True, readonly=False,
107 description=_(
108 "Whether this snap package is built automatically when the branch "
109- "containing its snapcraft.yaml or .snapcraft.yaml recipe "
110- "changes.")))
111+ "containing its snap/snapcraft.yaml, snapcraft.yaml, or "
112+ ".snapcraft.yaml recipe changes.")))
113
114 auto_build_archive = exported(Reference(
115 IArchive, title=_("Source archive for automatic builds"),
116
117=== modified file 'lib/lp/snappy/templates/snap-new.pt'
118--- lib/lp/snappy/templates/snap-new.pt 2017-01-16 22:27:56 +0000
119+++ lib/lp/snappy/templates/snap-new.pt 2017-02-02 22:56:31 +0000
120@@ -15,8 +15,8 @@
121 Core</a>. Launchpad can build snap packages using <a
122 href="https://developer.ubuntu.com/en/snappy/snapcraft/">snapcraft</a>,
123 from any Git or Bazaar branch on Launchpad that has a
124- <tt>snapcraft.yaml</tt> or <tt>.snapcraft.yaml</tt> file at its top
125- level.
126+ <tt>snap/snapcraft.yaml</tt>, <tt>snapcraft.yaml</tt>, or
127+ <tt>.snapcraft.yaml</tt> file at its top level.
128 </p>
129 </div>
130