Merge lp:~jml/pkgme-devportal/entry_point into lp:pkgme-devportal

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 14
Proposed branch: lp:~jml/pkgme-devportal/entry_point
Merge into: lp:pkgme-devportal
Diff against target: 783 lines (+702/-20)
9 files modified
.bzrignore (+3/-0)
MANIFEST.in (+2/-0)
bin/guess-deps (+2/-9)
bin/guess-executable (+2/-11)
devportalbinary/__init__.py (+14/-0)
devportalbinary/binary.py (+13/-0)
distribute_setup.py (+477/-0)
setup.py (+42/-0)
setup_helpers.py (+147/-0)
To merge this branch: bzr merge lp:~jml/pkgme-devportal/entry_point
Reviewer Review Type Date Requested Status
pkgme binary committers Pending
Review via email: mp+82399@code.launchpad.net

Description of the change

This makes the binary plugin setup.py-installable and makes it discoverable by the new entry-point-based system that pkgme uses (see https://code.launchpad.net/~jml/pkgme/include-backends/+merge/82396)

To post a comment you must log in.
lp:~jml/pkgme-devportal/entry_point updated
16. By Jonathan Lange

Export the two other scripts as endpoints.

17. By Jonathan Lange

Don't think we actually need this.

18. By Jonathan Lange

Tweaks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2011-11-16 16:53:24 +0000
@@ -0,0 +1,3 @@
1build
2dist
3pkgme_binary.egg-info
04
=== added file 'MANIFEST.in'
--- MANIFEST.in 1970-01-01 00:00:00 +0000
+++ MANIFEST.in 2011-11-16 16:53:24 +0000
@@ -0,0 +1,2 @@
1include *.py
2graft devportalbinary/backends
03
=== modified file 'bin/guess-deps'
--- bin/guess-deps 2011-08-23 17:21:54 +0000
+++ bin/guess-deps 2011-11-16 16:53:24 +0000
@@ -4,15 +4,8 @@
44
5import sys5import sys
66
7from devportalbinary.binary import guess_dependencies7from devportalbinary.binary import print_dependencies
8
9
10def main():
11 deps = guess_dependencies('.')
12 for dep in deps:
13 print dep
14 return 0
158
169
17if __name__ == '__main__':10if __name__ == '__main__':
18 sys.exit(main())11 sys.exit(print_dependencies())
1912
=== modified file 'bin/guess-executable'
--- bin/guess-executable 2011-08-23 17:21:54 +0000
+++ bin/guess-executable 2011-11-16 16:53:24 +0000
@@ -5,17 +5,8 @@
5import os5import os
6import sys6import sys
77
8from devportalbinary.binary import (8from devportalbinary.binary import print_executable
9 guess_executable,
10 iter_executables,
11 )
12
13
14def main():
15 cwd = os.getcwd()
16 print guess_executable(os.path.dirname(cwd), iter_executables(cwd))
17 return 0
189
1910
20if __name__ == '__main__':11if __name__ == '__main__':
21 sys.exit(main())12 sys.exit(print_executable())
2213
=== modified file 'devportalbinary/__init__.py'
--- devportalbinary/__init__.py 2011-08-23 17:21:54 +0000
+++ devportalbinary/__init__.py 2011-11-16 16:53:24 +0000
@@ -1,2 +1,16 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4from pkg_resources import resource_filename
5
6__all__ = [
7 '__version__',
8 'get_backends_path',
9 ]
10
11
12__version__ = '0.0.1'
13
14
15def get_backends_path():
16 return resource_filename(__name__, 'backends')
317
=== modified file 'devportalbinary/binary.py'
--- devportalbinary/binary.py 2011-10-24 22:02:09 +0000
+++ devportalbinary/binary.py 2011-11-16 16:53:24 +0000
@@ -279,3 +279,16 @@
279 libraries = get_shared_library_dependencies(binaries, library_finder)279 libraries = get_shared_library_dependencies(binaries, library_finder)
280 deps = libraries_to_deps(libraries, 'i386')280 deps = libraries_to_deps(libraries, 'i386')
281 return deps281 return deps
282
283
284def print_dependencies():
285 deps = guess_dependencies('.')
286 for dep in deps:
287 print dep
288 return 0
289
290
291def print_executable():
292 cwd = os.getcwd()
293 print guess_executable(os.path.dirname(cwd), iter_executables(cwd))
294 return 0
282295
=== added file 'distribute_setup.py'
--- distribute_setup.py 1970-01-01 00:00:00 +0000
+++ distribute_setup.py 2011-11-16 16:53:24 +0000
@@ -0,0 +1,477 @@
1#!python
2"""Bootstrap distribute installation
3
4If you want to use setuptools in your package's setup.py, just include this
5file in the same directory with it, and add this to the top of your setup.py::
6
7 from distribute_setup import use_setuptools
8 use_setuptools()
9
10If you want to require a specific version of setuptools, set a download
11mirror, or use an alternate download directory, you can do so by supplying
12the appropriate options to ``use_setuptools()``.
13
14This file can also be run as a script to install or upgrade setuptools.
15"""
16import os
17import sys
18import time
19import fnmatch
20import tempfile
21import tarfile
22from distutils import log
23
24try:
25 from site import USER_SITE
26except ImportError:
27 USER_SITE = None
28
29try:
30 import subprocess
31
32 def _python_cmd(*args):
33 args = (sys.executable,) + args
34 return subprocess.call(args) == 0
35
36except ImportError:
37 # will be used for python 2.3
38 def _python_cmd(*args):
39 args = (sys.executable,) + args
40 # quoting arguments if windows
41 if sys.platform == 'win32':
42 def quote(arg):
43 if ' ' in arg:
44 return '"%s"' % arg
45 return arg
46 args = [quote(arg) for arg in args]
47 return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
48
49DEFAULT_VERSION = "0.6.10"
50DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
51SETUPTOOLS_FAKED_VERSION = "0.6c11"
52
53SETUPTOOLS_PKG_INFO = """\
54Metadata-Version: 1.0
55Name: setuptools
56Version: %s
57Summary: xxxx
58Home-page: xxx
59Author: xxx
60Author-email: xxx
61License: xxx
62Description: xxx
63""" % SETUPTOOLS_FAKED_VERSION
64
65
66def _install(tarball):
67 # extracting the tarball
68 tmpdir = tempfile.mkdtemp()
69 log.warn('Extracting in %s', tmpdir)
70 old_wd = os.getcwd()
71 try:
72 os.chdir(tmpdir)
73 tar = tarfile.open(tarball)
74 _extractall(tar)
75 tar.close()
76
77 # going in the directory
78 subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
79 os.chdir(subdir)
80 log.warn('Now working in %s', subdir)
81
82 # installing
83 log.warn('Installing Distribute')
84 if not _python_cmd('setup.py', 'install'):
85 log.warn('Something went wrong during the installation.')
86 log.warn('See the error message above.')
87 finally:
88 os.chdir(old_wd)
89
90
91def _build_egg(egg, tarball, to_dir):
92 # extracting the tarball
93 tmpdir = tempfile.mkdtemp()
94 log.warn('Extracting in %s', tmpdir)
95 old_wd = os.getcwd()
96 try:
97 os.chdir(tmpdir)
98 tar = tarfile.open(tarball)
99 _extractall(tar)
100 tar.close()
101
102 # going in the directory
103 subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
104 os.chdir(subdir)
105 log.warn('Now working in %s', subdir)
106
107 # building an egg
108 log.warn('Building a Distribute egg in %s', to_dir)
109 _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
110
111 finally:
112 os.chdir(old_wd)
113 # returning the result
114 log.warn(egg)
115 if not os.path.exists(egg):
116 raise IOError('Could not build the egg.')
117
118
119def _do_download(version, download_base, to_dir, download_delay):
120 egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
121 % (version, sys.version_info[0], sys.version_info[1]))
122 if not os.path.exists(egg):
123 tarball = download_setuptools(version, download_base,
124 to_dir, download_delay)
125 _build_egg(egg, tarball, to_dir)
126 sys.path.insert(0, egg)
127 import setuptools
128 setuptools.bootstrap_install_from = egg
129
130
131def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
132 to_dir=os.curdir, download_delay=15, no_fake=True):
133 # making sure we use the absolute path
134 to_dir = os.path.abspath(to_dir)
135 was_imported = 'pkg_resources' in sys.modules or \
136 'setuptools' in sys.modules
137 try:
138 try:
139 import pkg_resources
140 if not hasattr(pkg_resources, '_distribute'):
141 if not no_fake:
142 _fake_setuptools()
143 raise ImportError
144 except ImportError:
145 return _do_download(version, download_base, to_dir, download_delay)
146 try:
147 pkg_resources.require("distribute>="+version)
148 return
149 except pkg_resources.VersionConflict:
150 e = sys.exc_info()[1]
151 if was_imported:
152 sys.stderr.write(
153 "The required version of distribute (>=%s) is not available,\n"
154 "and can't be installed while this script is running. Please\n"
155 "install a more recent version first, using\n"
156 "'easy_install -U distribute'."
157 "\n\n(Currently using %r)\n" % (version, e.args[0]))
158 sys.exit(2)
159 else:
160 del pkg_resources, sys.modules['pkg_resources'] # reload ok
161 return _do_download(version, download_base, to_dir,
162 download_delay)
163 except pkg_resources.DistributionNotFound:
164 return _do_download(version, download_base, to_dir,
165 download_delay)
166 finally:
167 if not no_fake:
168 _create_fake_setuptools_pkg_info(to_dir)
169
170def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
171 to_dir=os.curdir, delay=15):
172 """Download distribute from a specified location and return its filename
173
174 `version` should be a valid distribute version number that is available
175 as an egg for download under the `download_base` URL (which should end
176 with a '/'). `to_dir` is the directory where the egg will be downloaded.
177 `delay` is the number of seconds to pause before an actual download
178 attempt.
179 """
180 # making sure we use the absolute path
181 to_dir = os.path.abspath(to_dir)
182 try:
183 from urllib.request import urlopen
184 except ImportError:
185 from urllib2 import urlopen
186 tgz_name = "distribute-%s.tar.gz" % version
187 url = download_base + tgz_name
188 saveto = os.path.join(to_dir, tgz_name)
189 src = dst = None
190 if not os.path.exists(saveto): # Avoid repeated downloads
191 try:
192 log.warn("Downloading %s", url)
193 src = urlopen(url)
194 # Read/write all in one block, so we don't create a corrupt file
195 # if the download is interrupted.
196 data = src.read()
197 dst = open(saveto, "wb")
198 dst.write(data)
199 finally:
200 if src:
201 src.close()
202 if dst:
203 dst.close()
204 return os.path.realpath(saveto)
205
206
207def _patch_file(path, content):
208 """Will backup the file then patch it"""
209 existing_content = open(path).read()
210 if existing_content == content:
211 # already patched
212 log.warn('Already patched.')
213 return False
214 log.warn('Patching...')
215 _rename_path(path)
216 f = open(path, 'w')
217 try:
218 f.write(content)
219 finally:
220 f.close()
221 return True
222
223
224def _same_content(path, content):
225 return open(path).read() == content
226
227def _no_sandbox(function):
228 def __no_sandbox(*args, **kw):
229 try:
230 from setuptools.sandbox import DirectorySandbox
231 def violation(*args):
232 pass
233 DirectorySandbox._old = DirectorySandbox._violation
234 DirectorySandbox._violation = violation
235 patched = True
236 except ImportError:
237 patched = False
238
239 try:
240 return function(*args, **kw)
241 finally:
242 if patched:
243 DirectorySandbox._violation = DirectorySandbox._old
244 del DirectorySandbox._old
245
246 return __no_sandbox
247
248@_no_sandbox
249def _rename_path(path):
250 new_name = path + '.OLD.%s' % time.time()
251 log.warn('Renaming %s into %s', path, new_name)
252 os.rename(path, new_name)
253 return new_name
254
255def _remove_flat_installation(placeholder):
256 if not os.path.isdir(placeholder):
257 log.warn('Unkown installation at %s', placeholder)
258 return False
259 found = False
260 for file in os.listdir(placeholder):
261 if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
262 found = True
263 break
264 if not found:
265 log.warn('Could not locate setuptools*.egg-info')
266 return
267
268 log.warn('Removing elements out of the way...')
269 pkg_info = os.path.join(placeholder, file)
270 if os.path.isdir(pkg_info):
271 patched = _patch_egg_dir(pkg_info)
272 else:
273 patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
274
275 if not patched:
276 log.warn('%s already patched.', pkg_info)
277 return False
278 # now let's move the files out of the way
279 for element in ('setuptools', 'pkg_resources.py', 'site.py'):
280 element = os.path.join(placeholder, element)
281 if os.path.exists(element):
282 _rename_path(element)
283 else:
284 log.warn('Could not find the %s element of the '
285 'Setuptools distribution', element)
286 return True
287
288
289def _after_install(dist):
290 log.warn('After install bootstrap.')
291 placeholder = dist.get_command_obj('install').install_purelib
292 _create_fake_setuptools_pkg_info(placeholder)
293
294@_no_sandbox
295def _create_fake_setuptools_pkg_info(placeholder):
296 if not placeholder or not os.path.exists(placeholder):
297 log.warn('Could not find the install location')
298 return
299 pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
300 setuptools_file = 'setuptools-%s-py%s.egg-info' % \
301 (SETUPTOOLS_FAKED_VERSION, pyver)
302 pkg_info = os.path.join(placeholder, setuptools_file)
303 if os.path.exists(pkg_info):
304 log.warn('%s already exists', pkg_info)
305 return
306
307 log.warn('Creating %s', pkg_info)
308 f = open(pkg_info, 'w')
309 try:
310 f.write(SETUPTOOLS_PKG_INFO)
311 finally:
312 f.close()
313
314 pth_file = os.path.join(placeholder, 'setuptools.pth')
315 log.warn('Creating %s', pth_file)
316 f = open(pth_file, 'w')
317 try:
318 f.write(os.path.join(os.curdir, setuptools_file))
319 finally:
320 f.close()
321
322def _patch_egg_dir(path):
323 # let's check if it's already patched
324 pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
325 if os.path.exists(pkg_info):
326 if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
327 log.warn('%s already patched.', pkg_info)
328 return False
329 _rename_path(path)
330 os.mkdir(path)
331 os.mkdir(os.path.join(path, 'EGG-INFO'))
332 pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
333 f = open(pkg_info, 'w')
334 try:
335 f.write(SETUPTOOLS_PKG_INFO)
336 finally:
337 f.close()
338 return True
339
340
341def _before_install():
342 log.warn('Before install bootstrap.')
343 _fake_setuptools()
344
345
346def _under_prefix(location):
347 if 'install' not in sys.argv:
348 return True
349 args = sys.argv[sys.argv.index('install')+1:]
350 for index, arg in enumerate(args):
351 for option in ('--root', '--prefix'):
352 if arg.startswith('%s=' % option):
353 top_dir = arg.split('root=')[-1]
354 return location.startswith(top_dir)
355 elif arg == option:
356 if len(args) > index:
357 top_dir = args[index+1]
358 return location.startswith(top_dir)
359 elif option == '--user' and USER_SITE is not None:
360 return location.startswith(USER_SITE)
361 return True
362
363
364def _fake_setuptools():
365 log.warn('Scanning installed packages')
366 try:
367 import pkg_resources
368 except ImportError:
369 # we're cool
370 log.warn('Setuptools or Distribute does not seem to be installed.')
371 return
372 ws = pkg_resources.working_set
373 try:
374 setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
375 replacement=False))
376 except TypeError:
377 # old distribute API
378 setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
379
380 if setuptools_dist is None:
381 log.warn('No setuptools distribution found')
382 return
383 # detecting if it was already faked
384 setuptools_location = setuptools_dist.location
385 log.warn('Setuptools installation detected at %s', setuptools_location)
386
387 # if --root or --preix was provided, and if
388 # setuptools is not located in them, we don't patch it
389 if not _under_prefix(setuptools_location):
390 log.warn('Not patching, --root or --prefix is installing Distribute'
391 ' in another location')
392 return
393
394 # let's see if its an egg
395 if not setuptools_location.endswith('.egg'):
396 log.warn('Non-egg installation')
397 res = _remove_flat_installation(setuptools_location)
398 if not res:
399 return
400 else:
401 log.warn('Egg installation')
402 pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
403 if (os.path.exists(pkg_info) and
404 _same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
405 log.warn('Already patched.')
406 return
407 log.warn('Patching...')
408 # let's create a fake egg replacing setuptools one
409 res = _patch_egg_dir(setuptools_location)
410 if not res:
411 return
412 log.warn('Patched done.')
413 _relaunch()
414
415
416def _relaunch():
417 log.warn('Relaunching...')
418 # we have to relaunch the process
419 args = [sys.executable] + sys.argv
420 sys.exit(subprocess.call(args))
421
422
423def _extractall(self, path=".", members=None):
424 """Extract all members from the archive to the current working
425 directory and set owner, modification time and permissions on
426 directories afterwards. `path' specifies a different directory
427 to extract to. `members' is optional and must be a subset of the
428 list returned by getmembers().
429 """
430 import copy
431 import operator
432 from tarfile import ExtractError
433 directories = []
434
435 if members is None:
436 members = self
437
438 for tarinfo in members:
439 if tarinfo.isdir():
440 # Extract directories with a safe mode.
441 directories.append(tarinfo)
442 tarinfo = copy.copy(tarinfo)
443 tarinfo.mode = 448 # decimal for oct 0700
444 self.extract(tarinfo, path)
445
446 # Reverse sort directories.
447 if sys.version_info < (2, 4):
448 def sorter(dir1, dir2):
449 return cmp(dir1.name, dir2.name)
450 directories.sort(sorter)
451 directories.reverse()
452 else:
453 directories.sort(key=operator.attrgetter('name'), reverse=True)
454
455 # Set correct owner, mtime and filemode on directories.
456 for tarinfo in directories:
457 dirpath = os.path.join(path, tarinfo.name)
458 try:
459 self.chown(tarinfo, dirpath)
460 self.utime(tarinfo, dirpath)
461 self.chmod(tarinfo, dirpath)
462 except ExtractError:
463 e = sys.exc_info()[1]
464 if self.errorlevel > 1:
465 raise
466 else:
467 self._dbg(1, "tarfile: %s" % e)
468
469
470def main(argv, version=DEFAULT_VERSION):
471 """Install or upgrade setuptools and EasyInstall"""
472 tarball = download_setuptools()
473 _install(tarball)
474
475
476if __name__ == '__main__':
477 main(sys.argv[1:])
0478
=== added file 'setup.py'
--- setup.py 1970-01-01 00:00:00 +0000
+++ setup.py 2011-11-16 16:53:24 +0000
@@ -0,0 +1,42 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4import distribute_setup
5distribute_setup.use_setuptools()
6
7from setup_helpers import (
8 description,
9 get_version,
10 )
11from setuptools import setup, find_packages
12
13
14__version__ = get_version('devportalbinary/__init__.py')
15
16setup(
17 name='pkgme-binary',
18 version=__version__,
19 packages=find_packages(),
20 include_package_data=True,
21 maintainer='pkgme developers',
22 maintainer_email='pkgme-devs@lists.launchpad.net',
23 description=description('README'),
24 license='AGPLv3',
25 url='http://launchpad.net/pkgme-binary',
26 download_url='https://launchpad.net/pkgme-binary/+download',
27 test_suite='devportalbinary.tests',
28 install_requires = [
29 'bzr',
30 'pkgme',
31 ],
32 entry_points = {
33 'console_scripts': [
34 'fetch-symbol-files=devportalbinary.database:main',
35 'guess-executable=devportalbinary.binary:print_executable',
36 'guess-deps=devportalbinary.binary:print_dependencies',
37 ],
38 'pkgme.get_backends_path': ['binary=devportalbinary:get_backends_path'],
39 },
40 # Auto-conversion to Python 3.
41 use_2to3=True,
42 )
043
=== added file 'setup_helpers.py'
--- setup_helpers.py 1970-01-01 00:00:00 +0000
+++ setup_helpers.py 2011-11-16 16:53:24 +0000
@@ -0,0 +1,147 @@
1# setup_helper.py - Some utility functions for setup.py authors.
2#
3# Copyright (C) 2009, 2010 by Barry A. Warsaw
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Lesser General Public License as published by the
7# Free Software Foundation, version 3 of the License.
8#
9# This program is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12# for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""setup.py helper functions."""
18
19from __future__ import absolute_import, unicode_literals
20from __future__ import print_function
21
22
23__metaclass__ = type
24__all__ = [
25 'description',
26 'find_doctests',
27 'get_version',
28 'long_description',
29 'require_python',
30 ]
31
32
33import os
34import re
35import sys
36
37
38DEFAULT_VERSION_RE = re.compile(r'(?P<version>\d+\.\d(?:\.\d+)?)')
39NL = '\n'
40
41
42
043
44def require_python(minimum):
45 """Require at least a minimum Python version.
46
47 The version number is expressed in terms of `sys.hexversion`. E.g. to
48 require a minimum of Python 2.6, use::
49
50 >>> require_python(0x206000f0)
51
52 :param minimum: Minimum Python version supported.
53 :type minimum: integer
54 """
55 if sys.hexversion < minimum:
56 hversion = hex(minimum)[2:]
57 if len(hversion) % 2 != 0:
58 hversion = '0' + hversion
59 split = list(hversion)
60 parts = []
61 while split:
62 parts.append(int(''.join((split.pop(0), split.pop(0))), 16))
63 major, minor, micro, release = parts
64 if release == 0xf0:
65 print('Python {0}.{1}.{2} or better is required'.format(
66 major, minor, micro))
67 else:
68 print('Python {0}.{1}.{2} ({3}) or better is required'.format(
69 major, minor, micro, hex(release)[2:]))
70 sys.exit(1)
71
72
73
174
75def get_version(filename, pattern=None):
76 """Extract the __version__ from a file without importing it.
77
78 While you could get the __version__ by importing the module, the very act
79 of importing can cause unintended consequences. For example, Distribute's
80 automatic 2to3 support will break. Instead, this searches the file for a
81 line that starts with __version__, and extract the version number by
82 regular expression matching.
83
84 By default, two or three dot-separated digits are recognized, but by
85 passing a pattern parameter, you can recognize just about anything. Use
86 the `version` group name to specify the match group.
87
88 :param filename: The name of the file to search.
89 :type filename: string
90 :param pattern: Optional alternative regular expression pattern to use.
91 :type pattern: string
92 :return: The version that was extracted.
93 :rtype: string
94 """
95 if pattern is None:
96 cre = DEFAULT_VERSION_RE
97 else:
98 cre = re.compile(pattern)
99 with open(filename) as fp:
100 for line in fp:
101 if line.startswith('__version__'):
102 mo = cre.search(line)
103 assert mo, 'No valid __version__ string found'
104 return mo.group('version')
105 raise AssertionError('No __version__ assignment found')
106
107
108
2109
110def find_doctests(start='.', extension='.txt'):
111 """Find separate-file doctests in the package.
112
113 This is useful for Distribute's automatic 2to3 conversion support. The
114 `setup()` keyword argument `convert_2to3_doctests` requires file names,
115 which may be difficult to track automatically as you add new doctests.
116
117 :param start: Directory to start searching in (default is cwd)
118 :type start: string
119 :param extension: Doctest file extension (default is .txt)
120 :type extension: string
121 :return: The doctest files found.
122 :rtype: list
123 """
124 doctests = []
125 for dirpath, dirnames, filenames in os.walk(start):
126 doctests.extend(os.path.join(dirpath, filename)
127 for filename in filenames
128 if filename.endswith(extension))
129 return doctests
130
131
132
3133
134def long_description(*filenames):
135 """Provide a long description."""
136 res = []
137 for value in filenames:
138 if value.endswith('.txt'):
139 with open(value) as fp:
140 value = fp.read()
141 res.append(value)
142 if not value.endswith(NL):
143 res.append('')
144 return NL.join(res)
145
146
147def description(filename):
148 """Provide a short description."""
149 with open(filename) as fp:
150 for line in fp:
151 return line.strip()

Subscribers

People subscribed via source and target branches