Line 0
Link Here
|
|
|
1 |
Backported from 8.0 to make it work with devel/py-setuptools >= 41.4.0 |
2 |
|
3 |
--- setup.py.orig 2019-08-18 22:26:46 UTC |
4 |
+++ setup.py |
5 |
@@ -1,138 +1,8 @@ |
6 |
-#! /usr/bin/env python |
7 |
+#!/usr/bin/env python |
8 |
+ |
9 |
"""Cheroot package setuptools installer.""" |
10 |
|
11 |
import setuptools |
12 |
|
13 |
- |
14 |
-try: |
15 |
- from setuptools.config import read_configuration, ConfigOptionsHandler |
16 |
- import setuptools.config |
17 |
- import setuptools.dist |
18 |
- |
19 |
- # Set default value for 'use_scm_version' |
20 |
- setattr(setuptools.dist.Distribution, 'use_scm_version', False) |
21 |
- |
22 |
- # Attach bool parser to 'use_scm_version' option |
23 |
- class ShimConfigOptionsHandler(ConfigOptionsHandler): |
24 |
- """Extension class for ConfigOptionsHandler.""" |
25 |
- |
26 |
- @property |
27 |
- def parsers(self): |
28 |
- """Return an option mapping with default data type parsers.""" |
29 |
- _orig_parsers = super(ShimConfigOptionsHandler, self).parsers |
30 |
- return dict(use_scm_version=self._parse_bool, **_orig_parsers) |
31 |
- |
32 |
- setuptools.config.ConfigOptionsHandler = ShimConfigOptionsHandler |
33 |
-except ImportError: |
34 |
- """This is a shim for setuptools<30.3.""" |
35 |
- import io |
36 |
- import json |
37 |
- |
38 |
- try: |
39 |
- from configparser import ConfigParser, NoSectionError |
40 |
- except ImportError: |
41 |
- from ConfigParser import ConfigParser, NoSectionError |
42 |
- ConfigParser.read_file = ConfigParser.readfp |
43 |
- |
44 |
- def maybe_read_files(d): |
45 |
- """Read files if the string starts with `file:` marker.""" |
46 |
- d = d.strip() |
47 |
- if not d.startswith('file:'): |
48 |
- return d |
49 |
- descs = [] |
50 |
- for fname in map(str.strip, d[5:].split(',')): |
51 |
- with io.open(fname, encoding='utf-8') as f: |
52 |
- descs.append(f.read()) |
53 |
- return ''.join(descs) |
54 |
- |
55 |
- def cfg_val_to_list(v): |
56 |
- """Turn config val to list and filter out empty lines.""" |
57 |
- return list(filter(bool, map(str.strip, v.strip().splitlines()))) |
58 |
- |
59 |
- def cfg_val_to_dict(v): |
60 |
- """Turn config val to dict and filter out empty lines.""" |
61 |
- return dict( |
62 |
- map( |
63 |
- lambda l: list(map(str.strip, l.split('=', 1))), |
64 |
- filter(bool, map(str.strip, v.strip().splitlines())), |
65 |
- ), |
66 |
- ) |
67 |
- |
68 |
- def cfg_val_to_primitive(v): |
69 |
- """Parse primitive config val to appropriate data type.""" |
70 |
- return json.loads(v.strip().lower()) |
71 |
- |
72 |
- def read_configuration(filepath): |
73 |
- """Read metadata and options from setup.cfg located at filepath.""" |
74 |
- cfg = ConfigParser() |
75 |
- with io.open(filepath, encoding='utf-8') as f: |
76 |
- cfg.read_file(f) |
77 |
- |
78 |
- md = dict(cfg.items('metadata')) |
79 |
- for list_key in 'classifiers', 'keywords': |
80 |
- try: |
81 |
- md[list_key] = cfg_val_to_list(md[list_key]) |
82 |
- except KeyError: |
83 |
- pass |
84 |
- try: |
85 |
- md['long_description'] = maybe_read_files(md['long_description']) |
86 |
- except KeyError: |
87 |
- pass |
88 |
- opt = dict(cfg.items('options')) |
89 |
- for list_key in 'use_scm_version', 'zip_safe': |
90 |
- try: |
91 |
- opt[list_key] = cfg_val_to_primitive(opt[list_key]) |
92 |
- except KeyError: |
93 |
- pass |
94 |
- for list_key in 'scripts', 'install_requires', 'setup_requires': |
95 |
- try: |
96 |
- opt[list_key] = cfg_val_to_list(opt[list_key]) |
97 |
- except KeyError: |
98 |
- pass |
99 |
- try: |
100 |
- opt['package_dir'] = cfg_val_to_dict(opt['package_dir']) |
101 |
- except KeyError: |
102 |
- pass |
103 |
- opt_package_data = dict(cfg.items('options.package_data')) |
104 |
- try: |
105 |
- if not opt_package_data.get('', '').strip(): |
106 |
- opt_package_data[''] = opt_package_data['*'] |
107 |
- del opt_package_data['*'] |
108 |
- except KeyError: |
109 |
- pass |
110 |
- try: |
111 |
- opt_extras_require = dict(cfg.items('options.extras_require')) |
112 |
- opt['extras_require'] = {} |
113 |
- for k, v in opt_extras_require.items(): |
114 |
- opt['extras_require'][k] = cfg_val_to_list(v) |
115 |
- except NoSectionError: |
116 |
- pass |
117 |
- opt['package_data'] = {} |
118 |
- for k, v in opt_package_data.items(): |
119 |
- opt['package_data'][k] = cfg_val_to_list(v) |
120 |
- cur_pkgs = opt.get('packages', '').strip() |
121 |
- if '\n' in cur_pkgs: |
122 |
- opt['packages'] = cfg_val_to_list(opt['packages']) |
123 |
- elif cur_pkgs.startswith('find:'): |
124 |
- opt_packages_find = dict(cfg.items('options.packages.find')) |
125 |
- opt['packages'] = setuptools.find_packages(**opt_packages_find) |
126 |
- return {'metadata': md, 'options': opt} |
127 |
- |
128 |
- |
129 |
-setup_params = {} |
130 |
-declarative_setup_params = read_configuration('setup.cfg') |
131 |
- |
132 |
-# Patch incorrectly decoded package_dir option |
133 |
-# ``egg_info`` demands native strings failing with unicode under Python 2 |
134 |
-# Ref https://github.com/pypa/setuptools/issues/1136 |
135 |
-if 'package_dir' in declarative_setup_params['options']: |
136 |
- declarative_setup_params['options']['package_dir'] = { |
137 |
- str(k): str(v) |
138 |
- for k, v in declarative_setup_params['options']['package_dir'].items() |
139 |
- } |
140 |
- |
141 |
-setup_params = dict(setup_params, **declarative_setup_params['metadata']) |
142 |
-setup_params = dict(setup_params, **declarative_setup_params['options']) |
143 |
- |
144 |
- |
145 |
-__name__ == '__main__' and setuptools.setup(**setup_params) |
146 |
+if __name__ == '__main__': |
147 |
+ setuptools.setup(use_scm_version=True) |