diff --git a/spyder/tests/test_dependencies_in_sync.py b/spyder/tests/test_dependencies_in_sync.py index 8572ab6a5a2..f12bc449bcb 100644 --- a/spyder/tests/test_dependencies_in_sync.py +++ b/spyder/tests/test_dependencies_in_sync.py @@ -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'