Skip to content

Commit

Permalink
New format of setup.py required revising parse_setup_install_requires…
Browse files Browse the repository at this point in the history
…. Clarified and streamlined.
  • Loading branch information
mrclary committed Dec 9, 2024
1 parent 203f784 commit 0de2e28
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions spyder/tests/test_dependencies_in_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,45 +80,41 @@ def parse_setup_install_requires(fpath):
"""
Parse Spyder setup.py and return a dict of deps and versions.
"""
deps = {}
with open(fpath, 'r') as fh:
data = fh.read()

# Extract dependencies
lines = data.split('\n')
start = None
end = None
for idx, line in enumerate(lines):
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 + qt_deps:
is_dep_line = False
deps_list = []
for line in lines:
if is_dep_line:
if line.strip() in ('],', ']'):
# End of dependency lines
is_dep_line = False
elif not line.strip().startswith('#'):
# Add dependency
deps_list.append(line.strip().strip(',').strip("'"))
if (
line.strip() in ("'pyqt5': [", "install_requires += [")
and not is_dep_line
):
# Depencies begin on next line
is_dep_line = True

# Process dependencies
deps = {}
for dep in deps_list:
dep = dep.split(';')[0]
name, ver = None, None

for sep in ['>=', '==', '<=', '<', '>']:
if sep in dep:
idx = dep.index(sep)
name = dep[:idx]
ver = dep[idx:]
name, ver = dep.split(sep)
name = name.split('[')[0] # Discard e.g. [all]
ver = sep + ver # Include comparator
break

if name is not None:
name = name.split('[')[0]
else:
name = dep.split('[')[0]

# Transform pypi to conda name
if name == 'pyqt5':
name = 'pyqt'
Expand Down

0 comments on commit 0de2e28

Please sign in to comment.