Merge lp:~jelmer/brz/pypi-directory into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/pypi-directory
Merge into: lp:brz/3.1
Diff against target: 130 lines (+110/-0)
3 files modified
breezy/plugins/pypi/__init__.py (+29/-0)
breezy/plugins/pypi/directory.py (+78/-0)
doc/en/release-notes/brz-3.1.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/brz/pypi-directory
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+398643@code.launchpad.net

Commit message

Add a pypi plugin.

Description of the change

Add a pypi plugin.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'breezy/plugins/pypi'
2=== added file 'breezy/plugins/pypi/__init__.py'
3--- breezy/plugins/pypi/__init__.py 1970-01-01 00:00:00 +0000
4+++ breezy/plugins/pypi/__init__.py 2021-03-01 18:48:20 +0000
5@@ -0,0 +1,29 @@
6+# Copyright (C) 2021 Breezy Developers
7+#
8+# This program is free software; you can redistribute it and/or modify
9+# it under the terms of the GNU General Public License as published by
10+# the Free Software Foundation; either version 2 of the License, or
11+# (at your option) any later version.
12+#
13+# This program is distributed in the hope that it will be useful,
14+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+# GNU General Public License for more details.
17+#
18+# You should have received a copy of the GNU General Public License
19+# along with this program; if not, write to the Free Software
20+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
22+"""Support for looking up URLs from pypi.
23+"""
24+
25+from __future__ import absolute_import
26+
27+from ... import (
28+ version_info, # noqa: F401
29+ )
30+from ...directory_service import directories
31+
32+directories.register_lazy('pypi:', __name__ + '.directory',
33+ 'PypiDirectory',
34+ 'Pypi-based directory service',)
35
36=== added file 'breezy/plugins/pypi/directory.py'
37--- breezy/plugins/pypi/directory.py 1970-01-01 00:00:00 +0000
38+++ breezy/plugins/pypi/directory.py 2021-03-01 18:48:20 +0000
39@@ -0,0 +1,78 @@
40+# Copyright (C) 2021 Breezy Developers
41+#
42+# This program is free software; you can redistribute it and/or modify
43+# it under the terms of the GNU General Public License as published by
44+# the Free Software Foundation; either version 2 of the License, or
45+# (at your option) any later version.
46+#
47+# This program is distributed in the hope that it will be useful,
48+# but WITHOUT ANY WARRANTY; without even the implied warranty of
49+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+# GNU General Public License for more details.
51+#
52+# You should have received a copy of the GNU General Public License
53+# along with this program; if not, write to the Free Software
54+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
55+
56+"""Directory lookup that uses pypi."""
57+
58+from __future__ import absolute_import
59+
60+from breezy.errors import BzrError
61+from breezy.trace import note
62+from breezy.urlutils import InvalidURL
63+
64+import json
65+
66+try:
67+ from urllib.request import urlopen
68+ from urllib.parse import urlparse
69+ from urllib.error import HTTPError
70+except ImportError: # python < 3
71+ from urllib import urlopen, HTTPError
72+ from urlparse import urlparse
73+
74+
75+class PypiProjectWithoutRepositoryURL(InvalidURL):
76+
77+ _fmt = "No repository URL set for pypi project %(name)s"
78+
79+ def __init__(self, name, url=None):
80+ BzrError.__init__(self, name=name, url=url)
81+
82+
83+class NoSuchPypiProject(InvalidURL):
84+
85+ _fmt = "No pypi project with name %(name)s"
86+
87+ def __init__(self, name, url=None):
88+ BzrError.__init__(self, name=name, url=url)
89+
90+
91+def find_repo_url(data):
92+ for key, value in data['info']['project_urls'].items():
93+ if key == 'Repository':
94+ note('Found repository URL %s for pypi project %s',
95+ value, name)
96+ return value
97+ parsed_url = urlparse(value)
98+ if (parsed_url.hostname == 'github.com' and
99+ parsed_url.path.strip('/').count('/') == 1):
100+ return value
101+
102+
103+class PypiDirectory(object):
104+
105+ def look_up(self, name, url, purpose=None):
106+ """See DirectoryService.look_up"""
107+ try:
108+ with urlopen('https://pypi.org/pypi/%s/json' % name) as f:
109+ data = json.load(f)
110+ except HTTPError as e:
111+ if e.status == 404:
112+ raise NoSuchPypiProject(name, url=url)
113+ raise
114+ url = find_repo_url(data)
115+ if url is None:
116+ raise PypiProjectWithoutRepositoryURL(name, url=url)
117+ return url
118
119=== modified file 'doc/en/release-notes/brz-3.1.txt'
120--- doc/en/release-notes/brz-3.1.txt 2020-11-22 15:50:02 +0000
121+++ doc/en/release-notes/brz-3.1.txt 2021-03-01 18:48:20 +0000
122@@ -54,6 +54,9 @@
123 but it prevents the DWIM revision specifier from treating "svn:"
124 as a URL. (Jelmer Vernooij)
125
126+ * New `pypi` directory that can be used to access remote repositories
127+ declared in pypi. (Jelmer Vernooij)
128+
129 Bug Fixes
130 *********
131

Subscribers

People subscribed via source and target branches