Mercurial > repos > guerler > hhblits
annotate lib/python3.8/site-packages/setuptools/config.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
rev | line source |
---|---|
0
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
1 from __future__ import absolute_import, unicode_literals |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
2 import io |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
3 import os |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
4 import sys |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
5 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
6 import warnings |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
7 import functools |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
8 from collections import defaultdict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
9 from functools import partial |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
10 from functools import wraps |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
11 from importlib import import_module |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
12 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
13 from distutils.errors import DistutilsOptionError, DistutilsFileError |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
14 from setuptools.extern.packaging.version import LegacyVersion, parse |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
15 from setuptools.extern.packaging.specifiers import SpecifierSet |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
16 from setuptools.extern.six import string_types, PY3 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
17 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
18 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
19 __metaclass__ = type |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
20 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
21 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
22 def read_configuration( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
23 filepath, find_others=False, ignore_option_errors=False): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
24 """Read given configuration file and returns options from it as a dict. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
25 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
26 :param str|unicode filepath: Path to configuration file |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
27 to get options from. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
28 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
29 :param bool find_others: Whether to search for other configuration files |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
30 which could be on in various places. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
31 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
32 :param bool ignore_option_errors: Whether to silently ignore |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
33 options, values of which could not be resolved (e.g. due to exceptions |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
34 in directives such as file:, attr:, etc.). |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
35 If False exceptions are propagated as expected. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
36 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
37 :rtype: dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
38 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
39 from setuptools.dist import Distribution, _Distribution |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
40 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
41 filepath = os.path.abspath(filepath) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
42 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
43 if not os.path.isfile(filepath): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
44 raise DistutilsFileError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
45 'Configuration file %s does not exist.' % filepath) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
46 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
47 current_directory = os.getcwd() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
48 os.chdir(os.path.dirname(filepath)) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
49 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
50 try: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
51 dist = Distribution() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
52 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
53 filenames = dist.find_config_files() if find_others else [] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
54 if filepath not in filenames: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
55 filenames.append(filepath) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
56 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
57 _Distribution.parse_config_files(dist, filenames=filenames) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
58 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
59 handlers = parse_configuration( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
60 dist, dist.command_options, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
61 ignore_option_errors=ignore_option_errors) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
62 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
63 finally: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
64 os.chdir(current_directory) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
65 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
66 return configuration_to_dict(handlers) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
67 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
68 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
69 def _get_option(target_obj, key): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
70 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
71 Given a target object and option key, get that option from |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
72 the target object, either through a get_{key} method or |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
73 from an attribute directly. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
74 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
75 getter_name = 'get_{key}'.format(**locals()) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
76 by_attribute = functools.partial(getattr, target_obj, key) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
77 getter = getattr(target_obj, getter_name, by_attribute) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
78 return getter() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
79 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
80 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
81 def configuration_to_dict(handlers): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
82 """Returns configuration data gathered by given handlers as a dict. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
83 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
84 :param list[ConfigHandler] handlers: Handlers list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
85 usually from parse_configuration() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
86 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
87 :rtype: dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
88 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
89 config_dict = defaultdict(dict) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
90 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
91 for handler in handlers: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
92 for option in handler.set_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
93 value = _get_option(handler.target_obj, option) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
94 config_dict[handler.section_prefix][option] = value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
95 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
96 return config_dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
97 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
98 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
99 def parse_configuration( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
100 distribution, command_options, ignore_option_errors=False): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
101 """Performs additional parsing of configuration options |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
102 for a distribution. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
103 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
104 Returns a list of used option handlers. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
105 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
106 :param Distribution distribution: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
107 :param dict command_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
108 :param bool ignore_option_errors: Whether to silently ignore |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
109 options, values of which could not be resolved (e.g. due to exceptions |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
110 in directives such as file:, attr:, etc.). |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
111 If False exceptions are propagated as expected. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
112 :rtype: list |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
113 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
114 options = ConfigOptionsHandler( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
115 distribution, command_options, ignore_option_errors) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
116 options.parse() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
117 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
118 meta = ConfigMetadataHandler( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
119 distribution.metadata, command_options, ignore_option_errors, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
120 distribution.package_dir) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
121 meta.parse() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
122 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
123 return meta, options |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
124 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
125 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
126 class ConfigHandler: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
127 """Handles metadata supplied in configuration files.""" |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
128 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
129 section_prefix = None |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
130 """Prefix for config sections handled by this handler. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
131 Must be provided by class heirs. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
132 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
133 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
134 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
135 aliases = {} |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
136 """Options aliases. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
137 For compatibility with various packages. E.g.: d2to1 and pbr. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
138 Note: `-` in keys is replaced with `_` by config parser. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
139 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
140 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
141 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
142 def __init__(self, target_obj, options, ignore_option_errors=False): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
143 sections = {} |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
144 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
145 section_prefix = self.section_prefix |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
146 for section_name, section_options in options.items(): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
147 if not section_name.startswith(section_prefix): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
148 continue |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
149 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
150 section_name = section_name.replace(section_prefix, '').strip('.') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
151 sections[section_name] = section_options |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
152 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
153 self.ignore_option_errors = ignore_option_errors |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
154 self.target_obj = target_obj |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
155 self.sections = sections |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
156 self.set_options = [] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
157 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
158 @property |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
159 def parsers(self): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
160 """Metadata item name to parser function mapping.""" |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
161 raise NotImplementedError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
162 '%s must provide .parsers property' % self.__class__.__name__) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
163 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
164 def __setitem__(self, option_name, value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
165 unknown = tuple() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
166 target_obj = self.target_obj |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
167 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
168 # Translate alias into real name. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
169 option_name = self.aliases.get(option_name, option_name) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
170 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
171 current_value = getattr(target_obj, option_name, unknown) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
172 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
173 if current_value is unknown: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
174 raise KeyError(option_name) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
175 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
176 if current_value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
177 # Already inhabited. Skipping. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
178 return |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
179 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
180 skip_option = False |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
181 parser = self.parsers.get(option_name) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
182 if parser: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
183 try: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
184 value = parser(value) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
185 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
186 except Exception: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
187 skip_option = True |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
188 if not self.ignore_option_errors: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
189 raise |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
190 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
191 if skip_option: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
192 return |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
193 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
194 setter = getattr(target_obj, 'set_%s' % option_name, None) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
195 if setter is None: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
196 setattr(target_obj, option_name, value) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
197 else: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
198 setter(value) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
199 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
200 self.set_options.append(option_name) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
201 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
202 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
203 def _parse_list(cls, value, separator=','): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
204 """Represents value as a list. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
205 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
206 Value is split either by separator (defaults to comma) or by lines. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
207 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
208 :param value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
209 :param separator: List items separator character. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
210 :rtype: list |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
211 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
212 if isinstance(value, list): # _get_parser_compound case |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
213 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
214 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
215 if '\n' in value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
216 value = value.splitlines() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
217 else: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
218 value = value.split(separator) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
219 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
220 return [chunk.strip() for chunk in value if chunk.strip()] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
221 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
222 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
223 def _parse_dict(cls, value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
224 """Represents value as a dict. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
225 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
226 :param value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
227 :rtype: dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
228 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
229 separator = '=' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
230 result = {} |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
231 for line in cls._parse_list(value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
232 key, sep, val = line.partition(separator) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
233 if sep != separator: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
234 raise DistutilsOptionError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
235 'Unable to parse option value to dict: %s' % value) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
236 result[key.strip()] = val.strip() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
237 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
238 return result |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
239 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
240 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
241 def _parse_bool(cls, value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
242 """Represents value as boolean. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
243 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
244 :param value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
245 :rtype: bool |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
246 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
247 value = value.lower() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
248 return value in ('1', 'true', 'yes') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
249 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
250 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
251 def _exclude_files_parser(cls, key): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
252 """Returns a parser function to make sure field inputs |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
253 are not files. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
254 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
255 Parses a value after getting the key so error messages are |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
256 more informative. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
257 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
258 :param key: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
259 :rtype: callable |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
260 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
261 def parser(value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
262 exclude_directive = 'file:' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
263 if value.startswith(exclude_directive): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
264 raise ValueError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
265 'Only strings are accepted for the {0} field, ' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
266 'files are not accepted'.format(key)) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
267 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
268 return parser |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
269 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
270 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
271 def _parse_file(cls, value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
272 """Represents value as a string, allowing including text |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
273 from nearest files using `file:` directive. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
274 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
275 Directive is sandboxed and won't reach anything outside |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
276 directory with setup.py. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
277 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
278 Examples: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
279 file: README.rst, CHANGELOG.md, src/file.txt |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
280 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
281 :param str value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
282 :rtype: str |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
283 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
284 include_directive = 'file:' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
285 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
286 if not isinstance(value, string_types): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
287 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
288 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
289 if not value.startswith(include_directive): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
290 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
291 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
292 spec = value[len(include_directive):] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
293 filepaths = (os.path.abspath(path.strip()) for path in spec.split(',')) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
294 return '\n'.join( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
295 cls._read_file(path) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
296 for path in filepaths |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
297 if (cls._assert_local(path) or True) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
298 and os.path.isfile(path) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
299 ) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
300 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
301 @staticmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
302 def _assert_local(filepath): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
303 if not filepath.startswith(os.getcwd()): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
304 raise DistutilsOptionError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
305 '`file:` directive can not access %s' % filepath) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
306 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
307 @staticmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
308 def _read_file(filepath): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
309 with io.open(filepath, encoding='utf-8') as f: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
310 return f.read() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
311 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
312 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
313 def _parse_attr(cls, value, package_dir=None): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
314 """Represents value as a module attribute. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
315 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
316 Examples: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
317 attr: package.attr |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
318 attr: package.module.attr |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
319 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
320 :param str value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
321 :rtype: str |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
322 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
323 attr_directive = 'attr:' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
324 if not value.startswith(attr_directive): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
325 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
326 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
327 attrs_path = value.replace(attr_directive, '').strip().split('.') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
328 attr_name = attrs_path.pop() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
329 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
330 module_name = '.'.join(attrs_path) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
331 module_name = module_name or '__init__' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
332 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
333 parent_path = os.getcwd() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
334 if package_dir: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
335 if attrs_path[0] in package_dir: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
336 # A custom path was specified for the module we want to import |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
337 custom_path = package_dir[attrs_path[0]] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
338 parts = custom_path.rsplit('/', 1) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
339 if len(parts) > 1: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
340 parent_path = os.path.join(os.getcwd(), parts[0]) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
341 module_name = parts[1] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
342 else: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
343 module_name = custom_path |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
344 elif '' in package_dir: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
345 # A custom parent directory was specified for all root modules |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
346 parent_path = os.path.join(os.getcwd(), package_dir['']) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
347 sys.path.insert(0, parent_path) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
348 try: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
349 module = import_module(module_name) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
350 value = getattr(module, attr_name) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
351 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
352 finally: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
353 sys.path = sys.path[1:] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
354 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
355 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
356 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
357 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
358 def _get_parser_compound(cls, *parse_methods): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
359 """Returns parser function to represents value as a list. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
360 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
361 Parses a value applying given methods one after another. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
362 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
363 :param parse_methods: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
364 :rtype: callable |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
365 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
366 def parse(value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
367 parsed = value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
368 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
369 for method in parse_methods: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
370 parsed = method(parsed) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
371 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
372 return parsed |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
373 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
374 return parse |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
375 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
376 @classmethod |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
377 def _parse_section_to_dict(cls, section_options, values_parser=None): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
378 """Parses section options into a dictionary. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
379 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
380 Optionally applies a given parser to values. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
381 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
382 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
383 :param callable values_parser: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
384 :rtype: dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
385 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
386 value = {} |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
387 values_parser = values_parser or (lambda val: val) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
388 for key, (_, val) in section_options.items(): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
389 value[key] = values_parser(val) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
390 return value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
391 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
392 def parse_section(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
393 """Parses configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
394 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
395 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
396 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
397 for (name, (_, value)) in section_options.items(): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
398 try: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
399 self[name] = value |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
400 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
401 except KeyError: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
402 pass # Keep silent for a new option may appear anytime. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
403 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
404 def parse(self): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
405 """Parses configuration file items from one |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
406 or more related sections. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
407 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
408 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
409 for section_name, section_options in self.sections.items(): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
410 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
411 method_postfix = '' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
412 if section_name: # [section.option] variant |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
413 method_postfix = '_%s' % section_name |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
414 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
415 section_parser_method = getattr( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
416 self, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
417 # Dots in section names are translated into dunderscores. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
418 ('parse_section%s' % method_postfix).replace('.', '__'), |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
419 None) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
420 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
421 if section_parser_method is None: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
422 raise DistutilsOptionError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
423 'Unsupported distribution option section: [%s.%s]' % ( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
424 self.section_prefix, section_name)) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
425 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
426 section_parser_method(section_options) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
427 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
428 def _deprecated_config_handler(self, func, msg, warning_class): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
429 """ this function will wrap around parameters that are deprecated |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
430 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
431 :param msg: deprecation message |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
432 :param warning_class: class of warning exception to be raised |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
433 :param func: function to be wrapped around |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
434 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
435 @wraps(func) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
436 def config_handler(*args, **kwargs): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
437 warnings.warn(msg, warning_class) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
438 return func(*args, **kwargs) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
439 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
440 return config_handler |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
441 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
442 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
443 class ConfigMetadataHandler(ConfigHandler): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
444 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
445 section_prefix = 'metadata' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
446 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
447 aliases = { |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
448 'home_page': 'url', |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
449 'summary': 'description', |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
450 'classifier': 'classifiers', |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
451 'platform': 'platforms', |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
452 } |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
453 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
454 strict_mode = False |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
455 """We need to keep it loose, to be partially compatible with |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
456 `pbr` and `d2to1` packages which also uses `metadata` section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
457 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
458 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
459 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
460 def __init__(self, target_obj, options, ignore_option_errors=False, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
461 package_dir=None): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
462 super(ConfigMetadataHandler, self).__init__(target_obj, options, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
463 ignore_option_errors) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
464 self.package_dir = package_dir |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
465 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
466 @property |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
467 def parsers(self): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
468 """Metadata item name to parser function mapping.""" |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
469 parse_list = self._parse_list |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
470 parse_file = self._parse_file |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
471 parse_dict = self._parse_dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
472 exclude_files_parser = self._exclude_files_parser |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
473 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
474 return { |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
475 'platforms': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
476 'keywords': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
477 'provides': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
478 'requires': self._deprecated_config_handler( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
479 parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
480 "The requires parameter is deprecated, please use " |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
481 "install_requires for runtime dependencies.", |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
482 DeprecationWarning), |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
483 'obsoletes': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
484 'classifiers': self._get_parser_compound(parse_file, parse_list), |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
485 'license': exclude_files_parser('license'), |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
486 'license_files': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
487 'description': parse_file, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
488 'long_description': parse_file, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
489 'version': self._parse_version, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
490 'project_urls': parse_dict, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
491 } |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
492 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
493 def _parse_version(self, value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
494 """Parses `version` option value. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
495 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
496 :param value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
497 :rtype: str |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
498 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
499 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
500 version = self._parse_file(value) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
501 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
502 if version != value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
503 version = version.strip() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
504 # Be strict about versions loaded from file because it's easy to |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
505 # accidentally include newlines and other unintended content |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
506 if isinstance(parse(version), LegacyVersion): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
507 tmpl = ( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
508 'Version loaded from {value} does not ' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
509 'comply with PEP 440: {version}' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
510 ) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
511 raise DistutilsOptionError(tmpl.format(**locals())) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
512 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
513 return version |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
514 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
515 version = self._parse_attr(value, self.package_dir) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
516 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
517 if callable(version): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
518 version = version() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
519 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
520 if not isinstance(version, string_types): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
521 if hasattr(version, '__iter__'): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
522 version = '.'.join(map(str, version)) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
523 else: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
524 version = '%s' % version |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
525 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
526 return version |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
527 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
528 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
529 class ConfigOptionsHandler(ConfigHandler): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
530 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
531 section_prefix = 'options' |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
532 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
533 @property |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
534 def parsers(self): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
535 """Metadata item name to parser function mapping.""" |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
536 parse_list = self._parse_list |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
537 parse_list_semicolon = partial(self._parse_list, separator=';') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
538 parse_bool = self._parse_bool |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
539 parse_dict = self._parse_dict |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
540 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
541 return { |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
542 'zip_safe': parse_bool, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
543 'use_2to3': parse_bool, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
544 'include_package_data': parse_bool, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
545 'package_dir': parse_dict, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
546 'use_2to3_fixers': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
547 'use_2to3_exclude_fixers': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
548 'convert_2to3_doctests': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
549 'scripts': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
550 'eager_resources': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
551 'dependency_links': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
552 'namespace_packages': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
553 'install_requires': parse_list_semicolon, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
554 'setup_requires': parse_list_semicolon, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
555 'tests_require': parse_list_semicolon, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
556 'packages': self._parse_packages, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
557 'entry_points': self._parse_file, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
558 'py_modules': parse_list, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
559 'python_requires': SpecifierSet, |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
560 } |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
561 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
562 def _parse_packages(self, value): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
563 """Parses `packages` option value. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
564 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
565 :param value: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
566 :rtype: list |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
567 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
568 find_directives = ['find:', 'find_namespace:'] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
569 trimmed_value = value.strip() |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
570 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
571 if trimmed_value not in find_directives: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
572 return self._parse_list(value) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
573 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
574 findns = trimmed_value == find_directives[1] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
575 if findns and not PY3: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
576 raise DistutilsOptionError( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
577 'find_namespace: directive is unsupported on Python < 3.3') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
578 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
579 # Read function arguments from a dedicated section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
580 find_kwargs = self.parse_section_packages__find( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
581 self.sections.get('packages.find', {})) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
582 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
583 if findns: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
584 from setuptools import find_namespace_packages as find_packages |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
585 else: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
586 from setuptools import find_packages |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
587 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
588 return find_packages(**find_kwargs) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
589 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
590 def parse_section_packages__find(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
591 """Parses `packages.find` configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
592 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
593 To be used in conjunction with _parse_packages(). |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
594 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
595 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
596 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
597 section_data = self._parse_section_to_dict( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
598 section_options, self._parse_list) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
599 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
600 valid_keys = ['where', 'include', 'exclude'] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
601 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
602 find_kwargs = dict( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
603 [(k, v) for k, v in section_data.items() if k in valid_keys and v]) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
604 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
605 where = find_kwargs.get('where') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
606 if where is not None: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
607 find_kwargs['where'] = where[0] # cast list to single val |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
608 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
609 return find_kwargs |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
610 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
611 def parse_section_entry_points(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
612 """Parses `entry_points` configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
613 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
614 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
615 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
616 parsed = self._parse_section_to_dict(section_options, self._parse_list) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
617 self['entry_points'] = parsed |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
618 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
619 def _parse_package_data(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
620 parsed = self._parse_section_to_dict(section_options, self._parse_list) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
621 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
622 root = parsed.get('*') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
623 if root: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
624 parsed[''] = root |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
625 del parsed['*'] |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
626 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
627 return parsed |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
628 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
629 def parse_section_package_data(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
630 """Parses `package_data` configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
631 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
632 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
633 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
634 self['package_data'] = self._parse_package_data(section_options) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
635 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
636 def parse_section_exclude_package_data(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
637 """Parses `exclude_package_data` configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
638 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
639 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
640 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
641 self['exclude_package_data'] = self._parse_package_data( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
642 section_options) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
643 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
644 def parse_section_extras_require(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
645 """Parses `extras_require` configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
646 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
647 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
648 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
649 parse_list = partial(self._parse_list, separator=';') |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
650 self['extras_require'] = self._parse_section_to_dict( |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
651 section_options, parse_list) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
652 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
653 def parse_section_data_files(self, section_options): |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
654 """Parses `data_files` configuration file section. |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
655 |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
656 :param dict section_options: |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
657 """ |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
658 parsed = self._parse_section_to_dict(section_options, self._parse_list) |
9e54283cc701
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
guerler
parents:
diff
changeset
|
659 self['data_files'] = [(k, v) for k, v in parsed.items()] |