Show More
@@ -1,123 +1,127 b'' | |||||
1 |
|
1 | |||
2 | # Copyright (C) 2010-2023 RhodeCode GmbH |
|
2 | # Copyright (C) 2010-2023 RhodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify |
|
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | # it under the terms of the GNU Affero General Public License, version 3 | |
6 | # (only), as published by the Free Software Foundation. |
|
6 | # (only), as published by the Free Software Foundation. | |
7 | # |
|
7 | # | |
8 | # This program is distributed in the hope that it will be useful, |
|
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. |
|
11 | # GNU General Public License for more details. | |
12 | # |
|
12 | # | |
13 | # You should have received a copy of the GNU Affero General Public License |
|
13 | # You should have received a copy of the GNU Affero General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | # |
|
15 | # | |
16 | # This program is dual-licensed. If you wish to learn more about the |
|
16 | # This program is dual-licensed. If you wish to learn more about the | |
17 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | import random |
|
21 | import random | |
22 | import pytest |
|
22 | import pytest | |
23 |
|
23 | |||
24 | from rhodecode.api.utils import get_origin |
|
24 | from rhodecode.api.utils import get_origin | |
25 | from rhodecode.lib.ext_json import json |
|
25 | from rhodecode.lib.ext_json import json | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | def jsonify(obj): |
|
28 | def jsonify(obj): | |
29 | return json.loads(json.dumps(obj)) |
|
29 | return json.loads(json.dumps(obj)) | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | API_URL = '/_admin/api' |
|
32 | API_URL = '/_admin/api' | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | def assert_call_ok(id_, given): |
|
35 | def assert_call_ok(id_, given): | |
36 | expected = jsonify({ |
|
36 | expected = jsonify({ | |
37 | 'id': id_, |
|
37 | 'id': id_, | |
38 | 'error': None, |
|
38 | 'error': None, | |
39 | 'result': None |
|
39 | 'result': None | |
40 | }) |
|
40 | }) | |
41 | given = json.loads(given) |
|
41 | given = json.loads(given) | |
42 |
|
42 | |||
43 | assert expected['id'] == given['id'] |
|
43 | assert expected['id'] == given['id'] | |
44 | assert expected['error'] == given['error'] |
|
44 | assert expected['error'] == given['error'] | |
45 | return given['result'] |
|
45 | return given['result'] | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | def assert_ok(id_, expected, given): |
|
48 | def assert_ok(id_, expected, given): | |
49 | given = json.loads(given) |
|
49 | given = json.loads(given) | |
50 | if given.get('error'): |
|
50 | if given.get('error'): | |
51 | err = given['error'] |
|
51 | err = given['error'] | |
52 | pytest.fail(f"Unexpected ERROR in expected success response: `{err}`") |
|
52 | pytest.fail(f"Unexpected ERROR in expected success response: `{err}`") | |
53 |
|
53 | |||
54 | expected = jsonify({ |
|
54 | expected = jsonify({ | |
55 | 'id': id_, |
|
55 | 'id': id_, | |
56 | 'error': None, |
|
56 | 'error': None, | |
57 | 'result': expected |
|
57 | 'result': expected | |
58 | }) |
|
58 | }) | |
59 |
|
59 | |||
60 | assert expected == given |
|
60 | assert expected == given | |
61 |
|
61 | |||
62 |
|
62 | |||
63 | def assert_error(id_, expected, given): |
|
63 | def assert_error(id_, expected, given): | |
64 | expected = jsonify({ |
|
64 | expected = jsonify({ | |
65 | 'id': id_, |
|
65 | 'id': id_, | |
66 | 'error': expected, |
|
66 | 'error': expected, | |
67 | 'result': None |
|
67 | 'result': None | |
68 | }) |
|
68 | }) | |
69 | given = json.loads(given) |
|
69 | given = json.loads(given) | |
70 | assert expected == given |
|
70 | assert expected == given | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | def build_data(apikey, method, **kw): |
|
73 | def build_data(apikey, method, **kw): | |
74 | """ |
|
74 | """ | |
75 | Builds API data with given random ID |
|
75 | Builds API data with given random ID | |
76 | """ |
|
76 | """ | |
77 | random_id = random.randrange(1, 9999) |
|
77 | random_id = random.randrange(1, 9999) | |
78 | return random_id, json.dumps({ |
|
78 | return random_id, json.dumps({ | |
79 | "id": random_id, |
|
79 | "id": random_id, | |
80 | "api_key": apikey, |
|
80 | "api_key": apikey, | |
81 | "method": method, |
|
81 | "method": method, | |
82 | "args": kw |
|
82 | "args": kw | |
83 | }) |
|
83 | }) | |
84 |
|
84 | |||
85 |
|
85 | |||
86 | def api_call(app, params, status=None): |
|
86 | def api_call(app, params, status=None, assert_no_error=False): | |
87 | response = app.post( |
|
87 | response = app.post( | |
88 | API_URL, content_type='application/json', params=params, status=status, |
|
88 | API_URL, content_type='application/json', params=params, status=status, | |
89 | headers=[('Content-Type', 'application/json')]) |
|
89 | headers=[('Content-Type', 'application/json')]) | |
|
90 | if assert_no_error: | |||
|
91 | err_resp = response.json.get('error') | |||
|
92 | if err_resp: | |||
|
93 | raise AssertionError(f'ERROR in response: {err_resp}') | |||
90 | return response |
|
94 | return response | |
91 |
|
95 | |||
92 |
|
96 | |||
93 | def crash(*args, **kwargs): |
|
97 | def crash(*args, **kwargs): | |
94 | raise Exception('Total Crash !') |
|
98 | raise Exception('Total Crash !') | |
95 |
|
99 | |||
96 |
|
100 | |||
97 | def expected_permissions(object_with_permissions): |
|
101 | def expected_permissions(object_with_permissions): | |
98 | """ |
|
102 | """ | |
99 | Returns the expected permissions structure for the given object. |
|
103 | Returns the expected permissions structure for the given object. | |
100 |
|
104 | |||
101 | The object is expected to be a `Repository`, `RepositoryGroup`, |
|
105 | The object is expected to be a `Repository`, `RepositoryGroup`, | |
102 | or `UserGroup`. They all implement the same permission handling |
|
106 | or `UserGroup`. They all implement the same permission handling | |
103 | API. |
|
107 | API. | |
104 | """ |
|
108 | """ | |
105 | permissions = [] |
|
109 | permissions = [] | |
106 | for _user in object_with_permissions.permissions(): |
|
110 | for _user in object_with_permissions.permissions(): | |
107 | user_data = { |
|
111 | user_data = { | |
108 | 'name': _user.username, |
|
112 | 'name': _user.username, | |
109 | 'permission': _user.permission, |
|
113 | 'permission': _user.permission, | |
110 | 'origin': get_origin(_user), |
|
114 | 'origin': get_origin(_user), | |
111 | 'type': "user", |
|
115 | 'type': "user", | |
112 | } |
|
116 | } | |
113 | permissions.append(user_data) |
|
117 | permissions.append(user_data) | |
114 |
|
118 | |||
115 | for _user_group in object_with_permissions.permission_user_groups(): |
|
119 | for _user_group in object_with_permissions.permission_user_groups(): | |
116 | user_group_data = { |
|
120 | user_group_data = { | |
117 | 'name': _user_group.users_group_name, |
|
121 | 'name': _user_group.users_group_name, | |
118 | 'permission': _user_group.permission, |
|
122 | 'permission': _user_group.permission, | |
119 | 'origin': get_origin(_user_group), |
|
123 | 'origin': get_origin(_user_group), | |
120 | 'type': "user_group", |
|
124 | 'type': "user_group", | |
121 | } |
|
125 | } | |
122 | permissions.append(user_group_data) |
|
126 | permissions.append(user_group_data) | |
123 | return permissions |
|
127 | return permissions |
@@ -1,169 +1,169 b'' | |||||
1 | # Copyright (C) 2011-2023 RhodeCode GmbH |
|
1 | # Copyright (C) 2011-2023 RhodeCode GmbH | |
2 | # |
|
2 | # | |
3 | # This program is free software: you can redistribute it and/or modify |
|
3 | # This program is free software: you can redistribute it and/or modify | |
4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
4 | # it under the terms of the GNU Affero General Public License, version 3 | |
5 | # (only), as published by the Free Software Foundation. |
|
5 | # (only), as published by the Free Software Foundation. | |
6 | # |
|
6 | # | |
7 | # This program is distributed in the hope that it will be useful, |
|
7 | # This program is distributed in the hope that it will be useful, | |
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | # GNU General Public License for more details. |
|
10 | # GNU General Public License for more details. | |
11 | # |
|
11 | # | |
12 | # You should have received a copy of the GNU Affero General Public License |
|
12 | # You should have received a copy of the GNU Affero General Public License | |
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | # |
|
14 | # | |
15 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 | import typing |
|
19 | import typing | |
20 | import base64 |
|
20 | import base64 | |
21 | import logging |
|
21 | import logging | |
22 | from unidecode import unidecode |
|
22 | from unidecode import unidecode | |
23 |
|
23 | |||
24 | import rhodecode |
|
24 | import rhodecode | |
25 | from rhodecode.lib.type_utils import aslist |
|
25 | from rhodecode.lib.type_utils import aslist | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | log = logging.getLogger(__name__) |
|
28 | log = logging.getLogger(__name__) | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | def safe_int(val, default=None) -> int: |
|
31 | def safe_int(val, default=None) -> int: | |
32 | """ |
|
32 | """ | |
33 | Returns int() of val if val is not convertable to int use default |
|
33 | Returns int() of val if val is not convertable to int use default | |
34 | instead |
|
34 | instead | |
35 |
|
35 | |||
36 | :param val: |
|
36 | :param val: | |
37 | :param default: |
|
37 | :param default: | |
38 | """ |
|
38 | """ | |
39 |
|
39 | |||
40 | try: |
|
40 | try: | |
41 | val = int(val) |
|
41 | val = int(val) | |
42 | except (ValueError, TypeError): |
|
42 | except (ValueError, TypeError): | |
43 | val = default |
|
43 | val = default | |
44 |
|
44 | |||
45 | return val |
|
45 | return val | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | def safe_float(val, default=None) -> float: |
|
48 | def safe_float(val, default=None) -> float: | |
49 | """ |
|
49 | """ | |
50 | Returns float() of val if val is not convertable to float use default |
|
50 | Returns float() of val if val is not convertable to float use default | |
51 | instead |
|
51 | instead | |
52 |
|
52 | |||
53 | :param val: |
|
53 | :param val: | |
54 | :param default: |
|
54 | :param default: | |
55 | """ |
|
55 | """ | |
56 |
|
56 | |||
57 | try: |
|
57 | try: | |
58 | val = float(val) |
|
58 | val = float(val) | |
59 | except (ValueError, TypeError): |
|
59 | except (ValueError, TypeError): | |
60 | val = default |
|
60 | val = default | |
61 |
|
61 | |||
62 | return val |
|
62 | return val | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | def base64_to_str(text) -> str: |
|
65 | def base64_to_str(text: str | bytes) -> str: | |
66 | return safe_str(base64.encodebytes(safe_bytes(text))).strip() |
|
66 | return safe_str(base64.encodebytes(safe_bytes(text))).strip() | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | def get_default_encodings() -> list[str]: |
|
69 | def get_default_encodings() -> list[str]: | |
70 | return aslist(rhodecode.CONFIG.get('default_encoding', 'utf8'), sep=',') |
|
70 | return aslist(rhodecode.CONFIG.get('default_encoding', 'utf8'), sep=',') | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | DEFAULT_ENCODINGS = get_default_encodings() |
|
73 | DEFAULT_ENCODINGS = get_default_encodings() | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | def safe_str(str_, to_encoding=None) -> str: |
|
76 | def safe_str(str_, to_encoding=None) -> str: | |
77 | """ |
|
77 | """ | |
78 | safe str function. Does few trick to turn unicode_ into string |
|
78 | safe str function. Does few trick to turn unicode_ into string | |
79 |
|
79 | |||
80 | :param str_: str to encode |
|
80 | :param str_: str to encode | |
81 | :param to_encoding: encode to this type UTF8 default |
|
81 | :param to_encoding: encode to this type UTF8 default | |
82 | """ |
|
82 | """ | |
83 | if isinstance(str_, str): |
|
83 | if isinstance(str_, str): | |
84 | return str_ |
|
84 | return str_ | |
85 |
|
85 | |||
86 | # if it's bytes cast to str |
|
86 | # if it's bytes cast to str | |
87 | if not isinstance(str_, bytes): |
|
87 | if not isinstance(str_, bytes): | |
88 | return str(str_) |
|
88 | return str(str_) | |
89 |
|
89 | |||
90 | to_encoding = to_encoding or DEFAULT_ENCODINGS |
|
90 | to_encoding = to_encoding or DEFAULT_ENCODINGS | |
91 | if not isinstance(to_encoding, (list, tuple)): |
|
91 | if not isinstance(to_encoding, (list, tuple)): | |
92 | to_encoding = [to_encoding] |
|
92 | to_encoding = [to_encoding] | |
93 |
|
93 | |||
94 | for enc in to_encoding: |
|
94 | for enc in to_encoding: | |
95 | try: |
|
95 | try: | |
96 | return str(str_, enc) |
|
96 | return str(str_, enc) | |
97 | except UnicodeDecodeError: |
|
97 | except UnicodeDecodeError: | |
98 | pass |
|
98 | pass | |
99 |
|
99 | |||
100 | return str(str_, to_encoding[0], 'replace') |
|
100 | return str(str_, to_encoding[0], 'replace') | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | def safe_bytes(str_, from_encoding=None) -> bytes: |
|
103 | def safe_bytes(str_, from_encoding=None) -> bytes: | |
104 | """ |
|
104 | """ | |
105 | safe bytes function. Does few trick to turn str_ into bytes string: |
|
105 | safe bytes function. Does few trick to turn str_ into bytes string: | |
106 |
|
106 | |||
107 | :param str_: string to decode |
|
107 | :param str_: string to decode | |
108 | :param from_encoding: encode from this type UTF8 default |
|
108 | :param from_encoding: encode from this type UTF8 default | |
109 | """ |
|
109 | """ | |
110 | if isinstance(str_, bytes): |
|
110 | if isinstance(str_, bytes): | |
111 | return str_ |
|
111 | return str_ | |
112 |
|
112 | |||
113 | if not isinstance(str_, str): |
|
113 | if not isinstance(str_, str): | |
114 | raise ValueError(f'safe_bytes cannot convert other types than str: got: {type(str_)}') |
|
114 | raise ValueError(f'safe_bytes cannot convert other types than str: got: {type(str_)}') | |
115 |
|
115 | |||
116 | from_encoding = from_encoding or get_default_encodings() |
|
116 | from_encoding = from_encoding or get_default_encodings() | |
117 | if not isinstance(from_encoding, (list, tuple)): |
|
117 | if not isinstance(from_encoding, (list, tuple)): | |
118 | from_encoding = [from_encoding] |
|
118 | from_encoding = [from_encoding] | |
119 |
|
119 | |||
120 | for enc in from_encoding: |
|
120 | for enc in from_encoding: | |
121 | try: |
|
121 | try: | |
122 | return str_.encode(enc) |
|
122 | return str_.encode(enc) | |
123 | except UnicodeDecodeError: |
|
123 | except UnicodeDecodeError: | |
124 | pass |
|
124 | pass | |
125 |
|
125 | |||
126 | return str_.encode(from_encoding[0], 'replace') |
|
126 | return str_.encode(from_encoding[0], 'replace') | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | def ascii_bytes(str_, allow_bytes=False) -> bytes: |
|
129 | def ascii_bytes(str_, allow_bytes=False) -> bytes: | |
130 | """ |
|
130 | """ | |
131 | Simple conversion from str to bytes, with assumption that str_ is pure ASCII. |
|
131 | Simple conversion from str to bytes, with assumption that str_ is pure ASCII. | |
132 | Fails with UnicodeError on invalid input. |
|
132 | Fails with UnicodeError on invalid input. | |
133 | This should be used where encoding and "safe" ambiguity should be avoided. |
|
133 | This should be used where encoding and "safe" ambiguity should be avoided. | |
134 | Where strings already have been encoded in other ways but still are unicode |
|
134 | Where strings already have been encoded in other ways but still are unicode | |
135 | string - for example to hex, base64, json, urlencoding, or are known to be |
|
135 | string - for example to hex, base64, json, urlencoding, or are known to be | |
136 | identifiers. |
|
136 | identifiers. | |
137 | """ |
|
137 | """ | |
138 | if allow_bytes and isinstance(str_, bytes): |
|
138 | if allow_bytes and isinstance(str_, bytes): | |
139 | return str_ |
|
139 | return str_ | |
140 |
|
140 | |||
141 | if not isinstance(str_, str): |
|
141 | if not isinstance(str_, str): | |
142 | raise ValueError(f'ascii_bytes cannot convert other types than str: got: {type(str_)}') |
|
142 | raise ValueError(f'ascii_bytes cannot convert other types than str: got: {type(str_)}') | |
143 | return str_.encode('ascii') |
|
143 | return str_.encode('ascii') | |
144 |
|
144 | |||
145 |
|
145 | |||
146 | def ascii_str(str_) -> str: |
|
146 | def ascii_str(str_) -> str: | |
147 | """ |
|
147 | """ | |
148 | Simple conversion from bytes to str, with assumption that str_ is pure ASCII. |
|
148 | Simple conversion from bytes to str, with assumption that str_ is pure ASCII. | |
149 | Fails with UnicodeError on invalid input. |
|
149 | Fails with UnicodeError on invalid input. | |
150 | This should be used where encoding and "safe" ambiguity should be avoided. |
|
150 | This should be used where encoding and "safe" ambiguity should be avoided. | |
151 | Where strings are encoded but also in other ways are known to be ASCII, and |
|
151 | Where strings are encoded but also in other ways are known to be ASCII, and | |
152 | where a unicode string is wanted without caring about encoding. For example |
|
152 | where a unicode string is wanted without caring about encoding. For example | |
153 | to hex, base64, urlencoding, or are known to be identifiers. |
|
153 | to hex, base64, urlencoding, or are known to be identifiers. | |
154 | """ |
|
154 | """ | |
155 |
|
155 | |||
156 | if not isinstance(str_, bytes): |
|
156 | if not isinstance(str_, bytes): | |
157 | raise ValueError(f'ascii_str cannot convert other types than bytes: got: {type(str_)}') |
|
157 | raise ValueError(f'ascii_str cannot convert other types than bytes: got: {type(str_)}') | |
158 | return str_.decode('ascii') |
|
158 | return str_.decode('ascii') | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | def convert_special_chars(str_) -> str: |
|
161 | def convert_special_chars(str_) -> str: | |
162 | """ |
|
162 | """ | |
163 | trie to replace non-ascii letters to their ascii representation eg:: |
|
163 | trie to replace non-ascii letters to their ascii representation eg:: | |
164 |
|
164 | |||
165 | `ΕΌoΕw` converts into `zolw` |
|
165 | `ΕΌoΕw` converts into `zolw` | |
166 | """ |
|
166 | """ | |
167 | value = safe_str(str_) |
|
167 | value = safe_str(str_) | |
168 | converted_value = unidecode(value) |
|
168 | converted_value = unidecode(value) | |
169 | return converted_value |
|
169 | return converted_value |
@@ -1,203 +1,202 b'' | |||||
1 |
|
||||
2 |
|
|
1 | # Copyright (C) 2010-2023 RhodeCode GmbH | |
3 | # |
|
2 | # | |
4 | # This program is free software: you can redistribute it and/or modify |
|
3 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License, version 3 |
|
4 | # it under the terms of the GNU Affero General Public License, version 3 | |
6 | # (only), as published by the Free Software Foundation. |
|
5 | # (only), as published by the Free Software Foundation. | |
7 | # |
|
6 | # | |
8 | # This program is distributed in the hope that it will be useful, |
|
7 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. |
|
10 | # GNU General Public License for more details. | |
12 | # |
|
11 | # | |
13 | # You should have received a copy of the GNU Affero General Public License |
|
12 | # You should have received a copy of the GNU Affero General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | # |
|
14 | # | |
16 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
17 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
19 |
|
18 | |||
20 | # Import early to make sure things are patched up properly |
|
19 | # Import early to make sure things are patched up properly | |
21 | from setuptools import setup, find_packages, Extension |
|
20 | from setuptools import setup, find_packages, Extension | |
22 |
|
21 | |||
23 | import os |
|
22 | import os | |
24 | import re |
|
23 | import re | |
25 | import sys |
|
24 | import sys | |
26 | import pkgutil |
|
25 | import pkgutil | |
27 | import platform |
|
26 | import platform | |
28 | import codecs |
|
27 | import codecs | |
29 |
|
28 | |||
30 | import pip |
|
29 | import pip | |
31 |
|
30 | |||
32 | pip_major_version = int(pip.__version__.split(".")[0]) |
|
31 | pip_major_version = int(pip.__version__.split(".")[0]) | |
33 | if pip_major_version >= 20: |
|
32 | if pip_major_version >= 20: | |
34 | from pip._internal.req import parse_requirements |
|
33 | from pip._internal.req import parse_requirements | |
35 | from pip._internal.network.session import PipSession |
|
34 | from pip._internal.network.session import PipSession | |
36 | elif pip_major_version >= 10: |
|
35 | elif pip_major_version >= 10: | |
37 | from pip._internal.req import parse_requirements |
|
36 | from pip._internal.req import parse_requirements | |
38 | from pip._internal.download import PipSession |
|
37 | from pip._internal.download import PipSession | |
39 | else: |
|
38 | else: | |
40 | from pip.req import parse_requirements |
|
39 | from pip.req import parse_requirements | |
41 | from pip.download import PipSession |
|
40 | from pip.download import PipSession | |
42 |
|
41 | |||
43 |
|
42 | |||
44 | def get_package_name(req_object): |
|
43 | def get_package_name(req_object): | |
45 | package_name = None |
|
44 | package_name = None | |
46 | try: |
|
45 | try: | |
47 | from pip._internal.req.constructors import install_req_from_parsed_requirement |
|
46 | from pip._internal.req.constructors import install_req_from_parsed_requirement | |
48 | except ImportError: |
|
47 | except ImportError: | |
49 | install_req_from_parsed_requirement = None |
|
48 | install_req_from_parsed_requirement = None | |
50 |
|
49 | |||
51 | # In 20.1 of pip, the requirements object changed |
|
50 | # In 20.1 of pip, the requirements object changed | |
52 | if hasattr(req_object, 'req'): |
|
51 | if hasattr(req_object, 'req'): | |
53 | package_name = req_object.req.name |
|
52 | package_name = req_object.req.name | |
54 |
|
53 | |||
55 | if package_name is None: |
|
54 | if package_name is None: | |
56 | if install_req_from_parsed_requirement: |
|
55 | if install_req_from_parsed_requirement: | |
57 | package = install_req_from_parsed_requirement(req_object) |
|
56 | package = install_req_from_parsed_requirement(req_object) | |
58 | package_name = package.req.name |
|
57 | package_name = package.req.name | |
59 |
|
58 | |||
60 | if package_name is None: |
|
59 | if package_name is None: | |
61 | # fallback for older pip |
|
60 | # fallback for older pip | |
62 | package_name = re.split('===|<=|!=|==|>=|~=|<|>', req_object.requirement)[0] |
|
61 | package_name = re.split('===|<=|!=|==|>=|~=|<|>', req_object.requirement)[0] | |
63 |
|
62 | |||
64 | return package_name |
|
63 | return package_name | |
65 |
|
64 | |||
66 |
|
65 | |||
67 | if sys.version_info < (3, 10): |
|
66 | if sys.version_info < (3, 10): | |
68 | raise Exception('RhodeCode requires Python 3.10 or later') |
|
67 | raise Exception('RhodeCode requires Python 3.10 or later') | |
69 |
|
68 | |||
70 | here = os.path.abspath(os.path.dirname(__file__)) |
|
69 | here = os.path.abspath(os.path.dirname(__file__)) | |
71 |
|
70 | |||
72 | # defines current platform |
|
71 | # defines current platform | |
73 | __platform__ = platform.system() |
|
72 | __platform__ = platform.system() | |
74 | __license__ = 'AGPLv3, and Commercial License' |
|
73 | __license__ = 'AGPLv3, and Commercial License' | |
75 | __author__ = 'RhodeCode GmbH' |
|
74 | __author__ = 'RhodeCode GmbH' | |
76 | __url__ = 'https://code.rhodecode.com' |
|
75 | __url__ = 'https://code.rhodecode.com' | |
77 | is_windows = __platform__ in ('Windows',) |
|
76 | is_windows = __platform__ in ('Windows',) | |
78 |
|
77 | |||
79 |
|
78 | |||
80 | def _get_requirements(req_filename, exclude=None, extras=None): |
|
79 | def _get_requirements(req_filename, exclude=None, extras=None): | |
81 | extras = extras or [] |
|
80 | extras = extras or [] | |
82 | exclude = exclude or [] |
|
81 | exclude = exclude or [] | |
83 |
|
82 | |||
84 | try: |
|
83 | try: | |
85 | parsed = parse_requirements( |
|
84 | parsed = parse_requirements( | |
86 | os.path.join(here, req_filename), session=PipSession()) |
|
85 | os.path.join(here, req_filename), session=PipSession()) | |
87 | except TypeError: |
|
86 | except TypeError: | |
88 | # try pip < 6.0.0, that doesn't support session |
|
87 | # try pip < 6.0.0, that doesn't support session | |
89 | parsed = parse_requirements(os.path.join(here, req_filename)) |
|
88 | parsed = parse_requirements(os.path.join(here, req_filename)) | |
90 |
|
89 | |||
91 | requirements = [] |
|
90 | requirements = [] | |
92 | for int_req in parsed: |
|
91 | for int_req in parsed: | |
93 | req_name = get_package_name(int_req) |
|
92 | req_name = get_package_name(int_req) | |
94 | if req_name not in exclude: |
|
93 | if req_name not in exclude: | |
95 | requirements.append(req_name) |
|
94 | requirements.append(req_name) | |
96 | return requirements + extras |
|
95 | return requirements + extras | |
97 |
|
96 | |||
98 |
|
97 | |||
99 | # requirements extract |
|
98 | # requirements extract | |
100 | setup_requirements = ['PasteScript'] |
|
99 | setup_requirements = ['PasteScript'] | |
101 | install_requirements = _get_requirements( |
|
100 | install_requirements = _get_requirements( | |
102 | 'requirements.txt', exclude=['setuptools', 'entrypoints']) |
|
101 | 'requirements.txt', exclude=['setuptools', 'entrypoints']) | |
103 | test_requirements = _get_requirements( |
|
102 | test_requirements = _get_requirements( | |
104 | 'requirements_test.txt') |
|
103 | 'requirements_test.txt') | |
105 |
|
104 | |||
106 |
|
105 | |||
107 | def get_version(): |
|
106 | def get_version(): | |
108 | version = pkgutil.get_data('rhodecode', 'VERSION') |
|
107 | version = pkgutil.get_data('rhodecode', 'VERSION') | |
109 | return version.decode().strip() |
|
108 | return version.decode().strip() | |
110 |
|
109 | |||
111 |
|
110 | |||
112 | # additional files that goes into package itself |
|
111 | # additional files that goes into package itself | |
113 | package_data = { |
|
112 | package_data = { | |
114 | '': ['*.txt', '*.rst'], |
|
113 | '': ['*.txt', '*.rst'], | |
115 | 'configs': ['*.ini'], |
|
114 | 'configs': ['*.ini'], | |
116 | 'rhodecode': ['VERSION', 'i18n/*/LC_MESSAGES/*.mo', ], |
|
115 | 'rhodecode': ['VERSION', 'i18n/*/LC_MESSAGES/*.mo', ], | |
117 | } |
|
116 | } | |
118 |
|
117 | |||
119 | description = 'Source Code Management Platform' |
|
118 | description = 'Source Code Management Platform' | |
120 | keywords = ' '.join([ |
|
119 | keywords = ' '.join([ | |
121 | 'rhodecode', 'mercurial', 'git', 'svn', |
|
120 | 'rhodecode', 'mercurial', 'git', 'svn', | |
122 | 'code review', |
|
121 | 'code review', | |
123 | 'repo groups', 'ldap', 'repository management', 'hgweb', |
|
122 | 'repo groups', 'ldap', 'repository management', 'hgweb', | |
124 | 'hgwebdir', 'gitweb', 'serving hgweb', |
|
123 | 'hgwebdir', 'gitweb', 'serving hgweb', | |
125 | ]) |
|
124 | ]) | |
126 |
|
125 | |||
127 |
|
126 | |||
128 | # README/DESCRIPTION generation |
|
127 | # README/DESCRIPTION generation | |
129 | readme_file = 'README.rst' |
|
128 | readme_file = 'README.rst' | |
130 | changelog_file = 'CHANGES.rst' |
|
129 | changelog_file = 'CHANGES.rst' | |
131 | try: |
|
130 | try: | |
132 | long_description = codecs.open(readme_file).read() + '\n\n' + \ |
|
131 | long_description = codecs.open(readme_file).read() + '\n\n' + \ | |
133 | codecs.open(changelog_file).read() |
|
132 | codecs.open(changelog_file).read() | |
134 | except IOError as err: |
|
133 | except IOError as err: | |
135 | sys.stderr.write( |
|
134 | sys.stderr.write( | |
136 | "[WARNING] Cannot find file specified as long_description (%s)\n " |
|
135 | "[WARNING] Cannot find file specified as long_description (%s)\n " | |
137 | "or changelog (%s) skipping that file" % (readme_file, changelog_file)) |
|
136 | "or changelog (%s) skipping that file" % (readme_file, changelog_file)) | |
138 | long_description = description |
|
137 | long_description = description | |
139 |
|
138 | |||
140 |
|
139 | |||
141 | setup( |
|
140 | setup( | |
142 | name='rhodecode-enterprise-ce', |
|
141 | name='rhodecode-enterprise-ce', | |
143 | version=get_version(), |
|
142 | version=get_version(), | |
144 | description=description, |
|
143 | description=description, | |
145 | long_description=long_description, |
|
144 | long_description=long_description, | |
146 | keywords=keywords, |
|
145 | keywords=keywords, | |
147 | license=__license__, |
|
146 | license=__license__, | |
148 | author=__author__, |
|
147 | author=__author__, | |
149 | author_email='support@rhodecode.com', |
|
148 | author_email='support@rhodecode.com', | |
150 | url=__url__, |
|
149 | url=__url__, | |
151 | setup_requires=setup_requirements, |
|
150 | setup_requires=setup_requirements, | |
152 | install_requires=install_requirements, |
|
151 | install_requires=install_requirements, | |
153 | tests_require=test_requirements, |
|
152 | tests_require=test_requirements, | |
154 | zip_safe=False, |
|
153 | zip_safe=False, | |
155 | packages=find_packages(exclude=["docs", "tests*"]), |
|
154 | packages=find_packages(exclude=["docs", "tests*"]), | |
156 | package_data=package_data, |
|
155 | package_data=package_data, | |
157 | include_package_data=True, |
|
156 | include_package_data=True, | |
158 | classifiers=[ |
|
157 | classifiers=[ | |
159 | 'Development Status :: 6 - Mature', |
|
158 | 'Development Status :: 6 - Mature', | |
160 | 'Environment :: Web Environment', |
|
159 | 'Environment :: Web Environment', | |
161 | 'Intended Audience :: Developers', |
|
160 | 'Intended Audience :: Developers', | |
162 | 'Operating System :: OS Independent', |
|
161 | 'Operating System :: OS Independent', | |
163 | 'Topic :: Software Development :: Version Control', |
|
162 | 'Topic :: Software Development :: Version Control', | |
164 | 'License :: OSI Approved :: Affero GNU General Public License v3 or later (AGPLv3+)', |
|
163 | 'License :: OSI Approved :: Affero GNU General Public License v3 or later (AGPLv3+)', | |
165 | 'Programming Language :: Python :: 3.10', |
|
164 | 'Programming Language :: Python :: 3.10', | |
166 | ], |
|
165 | ], | |
167 | message_extractors={ |
|
166 | message_extractors={ | |
168 | 'rhodecode': [ |
|
167 | 'rhodecode': [ | |
169 | ('**.py', 'python', None), |
|
168 | ('**.py', 'python', None), | |
170 | ('**.js', 'javascript', None), |
|
169 | ('**.js', 'javascript', None), | |
171 | ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}), |
|
170 | ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}), | |
172 | ('templates/**.html', 'mako', {'input_encoding': 'utf-8'}), |
|
171 | ('templates/**.html', 'mako', {'input_encoding': 'utf-8'}), | |
173 | ('public/**', 'ignore', None), |
|
172 | ('public/**', 'ignore', None), | |
174 | ] |
|
173 | ] | |
175 | }, |
|
174 | }, | |
176 | paster_plugins=['PasteScript'], |
|
175 | paster_plugins=['PasteScript'], | |
177 | entry_points={ |
|
176 | entry_points={ | |
178 | 'paste.app_factory': [ |
|
177 | 'paste.app_factory': [ | |
179 | 'main=rhodecode.config.middleware:make_pyramid_app', |
|
178 | 'main=rhodecode.config.middleware:make_pyramid_app', | |
180 | ], |
|
179 | ], | |
181 | 'paste.global_paster_command': [ |
|
180 | 'paste.global_paster_command': [ | |
182 | 'ishell=rhodecode.lib.paster_commands.ishell:Command', |
|
181 | 'ishell=rhodecode.lib.paster_commands.ishell:Command', | |
183 | 'upgrade-db=rhodecode.lib.paster_commands.upgrade_db:UpgradeDb', |
|
182 | 'upgrade-db=rhodecode.lib.paster_commands.upgrade_db:UpgradeDb', | |
184 |
|
183 | |||
185 | 'setup-rhodecode=rhodecode.lib.paster_commands.deprecated.setup_rhodecode:Command', |
|
184 | 'setup-rhodecode=rhodecode.lib.paster_commands.deprecated.setup_rhodecode:Command', | |
186 | 'celeryd=rhodecode.lib.paster_commands.deprecated.celeryd:Command', |
|
185 | 'celeryd=rhodecode.lib.paster_commands.deprecated.celeryd:Command', | |
187 | ], |
|
186 | ], | |
188 | 'pyramid.pshell_runner': [ |
|
187 | 'pyramid.pshell_runner': [ | |
189 | 'ipython = rhodecode.lib.pyramid_shell:ipython_shell_runner', |
|
188 | 'ipython = rhodecode.lib.pyramid_shell:ipython_shell_runner', | |
190 | ], |
|
189 | ], | |
191 | 'console_scripts': [ |
|
190 | 'console_scripts': [ | |
192 | 'rc-setup-app=rhodecode.lib.rc_commands.setup_rc:main', |
|
191 | 'rc-setup-app=rhodecode.lib.rc_commands.setup_rc:main', | |
193 | 'rc-upgrade-db=rhodecode.lib.rc_commands.upgrade_db:main', |
|
192 | 'rc-upgrade-db=rhodecode.lib.rc_commands.upgrade_db:main', | |
194 | 'rc-ishell=rhodecode.lib.rc_commands.ishell:main', |
|
193 | 'rc-ishell=rhodecode.lib.rc_commands.ishell:main', | |
195 | 'rc-add-artifact=rhodecode.lib.rc_commands.add_artifact:main', |
|
194 | 'rc-add-artifact=rhodecode.lib.rc_commands.add_artifact:main', | |
196 | 'rc-ssh-wrapper=rhodecode.apps.ssh_support.lib.ssh_wrapper:main', |
|
195 | 'rc-ssh-wrapper=rhodecode.apps.ssh_support.lib.ssh_wrapper:main', | |
197 | ], |
|
196 | ], | |
198 | 'beaker.backends': [ |
|
197 | 'beaker.backends': [ | |
199 | 'memorylru_base=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerBase', |
|
198 | 'memorylru_base=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerBase', | |
200 | 'memorylru_debug=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerDebug' |
|
199 | 'memorylru_debug=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerDebug' | |
201 | ] |
|
200 | ] | |
202 | }, |
|
201 | }, | |
203 | ) |
|
202 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now