Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/setuptools/__init__.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 """Extensions to the 'distutils' for large or complex distributions""" | |
2 | |
3 import os | |
4 import distutils.core | |
5 import distutils.filelist | |
6 from distutils.core import Command as _Command | |
7 from distutils.util import convert_path | |
8 from fnmatch import fnmatchcase | |
9 | |
10 import setuptools.version | |
11 from setuptools.extension import Extension | |
12 from setuptools.dist import Distribution, Feature, _get_unpatched | |
13 from setuptools.depends import Require | |
14 from setuptools.compat import filterfalse | |
15 | |
16 __all__ = [ | |
17 'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require', | |
18 'find_packages' | |
19 ] | |
20 | |
21 __version__ = setuptools.version.__version__ | |
22 | |
23 bootstrap_install_from = None | |
24 | |
25 # If we run 2to3 on .py files, should we also convert docstrings? | |
26 # Default: yes; assume that we can detect doctests reliably | |
27 run_2to3_on_doctests = True | |
28 # Standard package names for fixer packages | |
29 lib2to3_fixer_packages = ['lib2to3.fixes'] | |
30 | |
31 | |
32 class PackageFinder(object): | |
33 @classmethod | |
34 def find(cls, where='.', exclude=(), include=('*',)): | |
35 """Return a list all Python packages found within directory 'where' | |
36 | |
37 'where' should be supplied as a "cross-platform" (i.e. URL-style) | |
38 path; it will be converted to the appropriate local path syntax. | |
39 'exclude' is a sequence of package names to exclude; '*' can be used | |
40 as a wildcard in the names, such that 'foo.*' will exclude all | |
41 subpackages of 'foo' (but not 'foo' itself). | |
42 | |
43 'include' is a sequence of package names to include. If it's | |
44 specified, only the named packages will be included. If it's not | |
45 specified, all found packages will be included. 'include' can contain | |
46 shell style wildcard patterns just like 'exclude'. | |
47 | |
48 The list of included packages is built up first and then any | |
49 explicitly excluded packages are removed from it. | |
50 """ | |
51 out = cls._find_packages_iter(convert_path(where)) | |
52 out = cls.require_parents(out) | |
53 includes = cls._build_filter(*include) | |
54 excludes = cls._build_filter('ez_setup', '*__pycache__', *exclude) | |
55 out = filter(includes, out) | |
56 out = filterfalse(excludes, out) | |
57 return list(out) | |
58 | |
59 @staticmethod | |
60 def require_parents(packages): | |
61 """ | |
62 Exclude any apparent package that apparently doesn't include its | |
63 parent. | |
64 | |
65 For example, exclude 'foo.bar' if 'foo' is not present. | |
66 """ | |
67 found = [] | |
68 for pkg in packages: | |
69 base, sep, child = pkg.rpartition('.') | |
70 if base and base not in found: | |
71 continue | |
72 found.append(pkg) | |
73 yield pkg | |
74 | |
75 @staticmethod | |
76 def _all_dirs(base_path): | |
77 """ | |
78 Return all dirs in base_path, relative to base_path | |
79 """ | |
80 for root, dirs, files in os.walk(base_path, followlinks=True): | |
81 for dir in dirs: | |
82 yield os.path.relpath(os.path.join(root, dir), base_path) | |
83 | |
84 @classmethod | |
85 def _find_packages_iter(cls, base_path): | |
86 dirs = cls._all_dirs(base_path) | |
87 suitable = filterfalse(lambda n: '.' in n, dirs) | |
88 return ( | |
89 path.replace(os.path.sep, '.') | |
90 for path in suitable | |
91 if cls._looks_like_package(os.path.join(base_path, path)) | |
92 ) | |
93 | |
94 @staticmethod | |
95 def _looks_like_package(path): | |
96 return os.path.isfile(os.path.join(path, '__init__.py')) | |
97 | |
98 @staticmethod | |
99 def _build_filter(*patterns): | |
100 """ | |
101 Given a list of patterns, return a callable that will be true only if | |
102 the input matches one of the patterns. | |
103 """ | |
104 return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns) | |
105 | |
106 class PEP420PackageFinder(PackageFinder): | |
107 @staticmethod | |
108 def _looks_like_package(path): | |
109 return True | |
110 | |
111 find_packages = PackageFinder.find | |
112 | |
113 setup = distutils.core.setup | |
114 | |
115 _Command = _get_unpatched(_Command) | |
116 | |
117 class Command(_Command): | |
118 __doc__ = _Command.__doc__ | |
119 | |
120 command_consumes_arguments = False | |
121 | |
122 def __init__(self, dist, **kw): | |
123 # Add support for keyword arguments | |
124 _Command.__init__(self,dist) | |
125 for k,v in kw.items(): | |
126 setattr(self,k,v) | |
127 | |
128 def reinitialize_command(self, command, reinit_subcommands=0, **kw): | |
129 cmd = _Command.reinitialize_command(self, command, reinit_subcommands) | |
130 for k,v in kw.items(): | |
131 setattr(cmd,k,v) # update command with keywords | |
132 return cmd | |
133 | |
134 distutils.core.Command = Command # we can't patch distutils.cmd, alas | |
135 | |
136 def findall(dir = os.curdir): | |
137 """Find all files under 'dir' and return the list of full filenames | |
138 (relative to 'dir'). | |
139 """ | |
140 all_files = [] | |
141 for base, dirs, files in os.walk(dir, followlinks=True): | |
142 if base==os.curdir or base.startswith(os.curdir+os.sep): | |
143 base = base[2:] | |
144 if base: | |
145 files = [os.path.join(base, f) for f in files] | |
146 all_files.extend(filter(os.path.isfile, files)) | |
147 return all_files | |
148 | |
149 distutils.filelist.findall = findall # fix findall bug in distutils. |