2
2
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
3
from __future__ import annotations
4
4
5
+ import os
5
6
import sys
6
- from .log import log , LogLevel
7
7
from pathlib import Path
8
+ from typing import Any
8
9
9
- from . import PYSIDE , PYSIDE_MODULE , SHIBOKEN , PYPROJECT_PATH
10
- from .utils import available_pyside_tools
10
+ from . import PYPROJECT_PATH , PYSIDE , PYSIDE_MODULE , SHIBOKEN
11
+ from .log import LogLevel , log
12
+ from .utils import available_pyside_tools , Singleton
11
13
12
14
try :
13
15
import tomllib
14
16
except ModuleNotFoundError :
15
17
import tomli as tomllib
16
18
17
19
18
- class Config (object ):
20
+ class Config (object , metaclass = Singleton ):
19
21
def __init__ (self ):
20
22
# Constants
21
23
self ._build_type_all = "all"
@@ -28,19 +30,19 @@ def __init__(self):
28
30
# The setup.py invocation type.
29
31
# top-level
30
32
# internal
31
- self .invocation_type = None
33
+ self .invocation_type : str = ""
32
34
33
35
# The type of the top-level build.
34
36
# all - build shiboken6 module, shiboken6-generator and PySide6
35
37
# modules
36
38
# shiboken6 - build only shiboken6 module
37
39
# shiboken6-generator - build only the shiboken6-generator
38
40
# pyside6 - build only PySide6 modules
39
- self .build_type = None
41
+ self .build_type : str = ""
40
42
41
43
# The internal build type, used for internal invocations of
42
44
# setup.py to build a specific module only.
43
- self .internal_build_type = None
45
+ self .internal_build_type : str = ""
44
46
45
47
# Options that can be given to --build-type and
46
48
# --internal-build-type
@@ -51,18 +53,18 @@ def __init__(self):
51
53
# Names to be passed to setuptools.setup() name key,
52
54
# so not package name, but rather project name as it appears
53
55
# in the wheel name and on PyPi.
54
- self .shiboken_module_st_name = SHIBOKEN
55
- self .shiboken_generator_st_name = f"{ SHIBOKEN } -generator"
56
- self .pyside_st_name = PYSIDE_MODULE
56
+ self .shiboken_module_st_name : str = SHIBOKEN
57
+ self .shiboken_generator_st_name : str = f"{ SHIBOKEN } -generator"
58
+ self .pyside_st_name : str = PYSIDE_MODULE
57
59
58
60
# Path to CMake toolchain file when intending to cross compile
59
61
# the project.
60
- self .cmake_toolchain_file = None
62
+ self .cmake_toolchain_file : str | os . PathLike = ""
61
63
62
64
# Store where host shiboken is built during a cross-build.
63
- self .shiboken_host_query_path = None
65
+ self .shiboken_host_query_path : str = ""
64
66
65
- self .setup_script_dir = None
67
+ self .setup_script_dir : str | os . PathLike = ""
66
68
67
69
# Getting data from base pyproject.toml file to be consistent
68
70
@@ -72,7 +74,7 @@ def __init__(self):
72
74
with open (PYPROJECT_PATH , "rb" ) as f :
73
75
_pyproject_data = tomllib .load (f )["project" ]
74
76
75
- self .setup_kwargs = {}
77
+ self .setup_kwargs : dict [ str , Any ] = {}
76
78
self .setup_kwargs ['long_description_content_type' ] = 'text/markdown'
77
79
78
80
self .setup_kwargs ['keywords' ] = _pyproject_data ["keywords" ]
@@ -87,15 +89,15 @@ def __init__(self):
87
89
self .setup_kwargs ['classifiers' ] = self .classifiers
88
90
89
91
def init_config (self ,
90
- build_type = None ,
91
- internal_build_type = None ,
92
+ build_type = "" ,
93
+ internal_build_type = "" ,
92
94
cmd_class_dict = None ,
93
95
package_version = None ,
94
96
ext_modules = None ,
95
- setup_script_dir = None ,
96
- cmake_toolchain_file = None ,
97
+ setup_script_dir : str | os . PathLike = "" ,
98
+ cmake_toolchain_file : str | os . PathLike = "" ,
97
99
log_level = LogLevel .INFO ,
98
- qt_install_path : Path = None ):
100
+ qt_install_dir : str | os . PathLike = "" ):
99
101
"""
100
102
Sets up the global singleton config which is used in many parts
101
103
of the setup process.
@@ -182,8 +184,8 @@ def init_config(self,
182
184
self .setup_kwargs ['install_requires' ] = [
183
185
f"{ self .shiboken_module_st_name } =={ package_version } "
184
186
]
185
- if qt_install_path :
186
- _pyside_tools = available_pyside_tools (qt_tools_path = qt_install_path )
187
+ if qt_install_dir :
188
+ _pyside_tools = available_pyside_tools (qt_tools_path = Path ( qt_install_dir ) )
187
189
188
190
# replacing pyside6-android_deploy by pyside6-android-deploy for consistency
189
191
# Also, the tool should not exist in any other platform than Linux and macOS
@@ -209,31 +211,23 @@ def get_long_description(self):
209
211
elif self .is_internal_pyside_build ():
210
212
readme_filename = f'README.{ PYSIDE } .md'
211
213
212
- content = ''
213
- changes = ''
214
- try :
215
- with open (self .setup_script_dir / readme_filename ) as f :
216
- readme = f .read ()
217
- except Exception as e :
218
- log .error (f"Couldn't read contents of { readme_filename } . { e } " )
219
- raise
214
+ with open (Path (self .setup_script_dir ) / readme_filename ) as f :
215
+ readme = f .read ()
220
216
221
217
# Don't include CHANGES.rst for now, because we have not decided
222
218
# how to handle change files yet.
223
219
include_changes = False
224
220
if include_changes :
225
221
try :
226
- with open (self .setup_script_dir / changes_filename ) as f :
222
+ changes = ''
223
+ with open (Path (self .setup_script_dir ) / changes_filename ) as f :
227
224
changes = f .read ()
228
225
except Exception as e :
229
226
log .error (f"Couldn't read contents of { changes_filename } . { e } " )
230
227
raise
231
- content += readme
232
-
233
- if changes :
234
- content += f"\n \n { changes } "
228
+ return f"{ readme } \n \n { changes } "
235
229
236
- return content
230
+ return readme
237
231
238
232
def package_name (self ):
239
233
"""
0 commit comments