Skip to content

Commit

Permalink
Merge pull request #23055 from dpizetta/add-binding-option
Browse files Browse the repository at this point in the history
PR: Choose Qt binding to install from `SPYDER_QT_BINDING` environment variable
  • Loading branch information
ccordoba12 authored Dec 2, 2024
2 parents c34f19c + 7ad18e0 commit 42be1ff
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
53 changes: 50 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,47 @@ def get_packages():
return packages


def get_qt_requirements(qt_requirements, default='pyqt5'):
"""
Return a list of requirements for the Qt binding according to the
environment variable SPYDER_QT_BINDING. If this variable is not set
or has an unsupported value it defaults to 'pyqt5'.
Parameters
----------
qt_requirements : dict
A dictionary whose keys are supported Qt bindings and whose values are
lists of required packages to install for each binding.
default : str
Default Qt binding to use if the environment variable is not set.
Defaults to 'pyqt5'.
Raises
------
ValueError
If the environment variable SPYDER_QT_BINDING has an unsupported value.
Returns
-------
install_requires : list
A list of required packages to install for the given Qt binding.
"""
install_requires = []

# Check if a Qt binding is set in the environment and normalizes
env_qt_binding = os.environ.get('SPYDER_QT_BINDING', default)
env_qt_binding = env_qt_binding.lower()
install_requires = qt_requirements.get(env_qt_binding, None)

if install_requires is None:
raise ValueError(
f"Unsupported Qt binding: {env_qt_binding}. "
f"Supported: " + ", ".join(qt_requirements.keys())
)

return install_requires


# =============================================================================
# Make Linux detect Spyder desktop file (will not work with wheels)
# =============================================================================
Expand Down Expand Up @@ -201,8 +242,16 @@ def run(self):
cmdclass=CMDCLASS,
)

# Qt bindings requirements
qt_requirements = {
'pyqt5': ['pyqt5>=5.15,<5.16', 'pyqtwebengine>=5.15,<5.16'],
'pyqt6': ['pyqt6>=6.5,<7', 'pyqt6-webengine>=6.5,<7'],
}

# Get the proper requirements for the selected Qt binding
install_requires = get_qt_requirements(qt_requirements, default='pyqt5')

install_requires = [
install_requires += [
'aiohttp>=3.9.3',
'applaunchservices>=0.3.0;platform_system=="Darwin"',
'asyncssh>=2.14.0,<3.0.0',
Expand Down Expand Up @@ -232,8 +281,6 @@ def run(self):
'pylint>=3.1,<4',
'pylint-venv>=3.0.2',
'pyls-spyder>=0.4.0',
'pyqt5>=5.15,<5.16',
'pyqtwebengine>=5.15,<5.16',
'python-lsp-black>=2.0.0,<3.0.0',
'python-lsp-server[all]>=1.12.0,<1.13.0',
'pyuca>=1.2',
Expand Down
10 changes: 8 additions & 2 deletions spyder/tests/test_dependencies_in_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,22 @@ def parse_setup_install_requires(fpath):
start = None
end = None
for idx, line in enumerate(lines):
if line.startswith('install_requires = '):
if "'pyqt5': " in line:
idx_qt = idx

if line.startswith('install_requires += '):
start = idx + 1

if start is not None and line.startswith(']'):
end = idx
break

qt_deps = lines[idx_qt].split("'pyqt5': ")[1]
qt_deps = literal_eval(qt_deps[:qt_deps.index("]") + 1])
dep_list = literal_eval('[' + '\n'.join(lines[start:end + 1]))
dep_list = [item for item in dep_list if item[0] != '#']
for dep in dep_list:

for dep in dep_list + qt_deps:
dep = dep.split(';')[0]
name, ver = None, None

Expand Down

0 comments on commit 42be1ff

Please sign in to comment.