Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop usage of unsupported pip api #680

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Create a [minimal, complete, verifiable example

#### Expected Output

#### Output of `cobra.show_versions()`
#### Version information

<details>
# Paste the output of `import cobra;cobra.show_versions()` here.
Paste the output of the following commands here:

</details>
* `import cobra;cobra.show_versions()`
* `pip list --format=columns`
30 changes: 2 additions & 28 deletions cobra/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from six.moves import range

from cobra import DictList, Object
from cobra.util.version_info import (
get_sys_info, get_pkg_info, show_versions, SYS_ORDER, PKG_ORDER)
from cobra.util.version_info import get_sys_info, show_versions, SYS_ORDER


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -306,10 +305,6 @@ class TestVersionInfo:
def sys_info(self):
return get_sys_info()

@pytest.fixture(scope="module")
def pkg_info(self):
return get_pkg_info()

@pytest.mark.parametrize("key", SYS_ORDER)
def test_sys_info_key(self, key, sys_info):
assert key in sys_info
Expand All @@ -318,19 +313,7 @@ def test_sys_info_key(self, key, sys_info):
def test_sys_info_value(self, key, sys_info):
assert len(sys_info[key]) > 0

@pytest.mark.parametrize("key", PKG_ORDER)
def test_pkg_info_key(self, key, pkg_info):
if key in self.SKIP_OPTIONAL:
pytest.skip()
assert key in pkg_info

@pytest.mark.parametrize("key", PKG_ORDER)
def test_pkg_info_value(self, key, pkg_info):
if key in self.SKIP_OPTIONAL:
pytest.skip()
assert len(pkg_info[key]) > 0

def test_show_versions(self, sys_info, pkg_info, capsys):
def test_show_versions(self, sys_info, capsys):
show_versions()
out, err = capsys.readouterr()
lines = out.split("\n")
Expand All @@ -341,12 +324,3 @@ def test_show_versions(self, sys_info, pkg_info, capsys):
assert line.endswith(sys_info[key])
i += 1
i += 3
for key in PKG_ORDER:
line = lines[i]
if key in self.SKIP_OPTIONAL:
if line.startswith(key):
i += 1
continue
assert line.startswith(key)
assert line.endswith(pkg_info[key])
i += 1
40 changes: 0 additions & 40 deletions cobra/util/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,13 @@

import platform

import pip

__all__ = ("show_versions",)

SYS_ORDER = [
"OS",
"OS-release",
"Python"
]
PKG_ORDER = [
"pip",
"setuptools",
"cobra",
"future",
"swiglpk",
"optlang",
"ruamel.yaml",
"pandas",
"numpy",
"tabulate",
"python-libsbml",
"lxml",
"scipy",
"matplotlib",
"palettable",
"pymatbridge"
]


def get_sys_info():
Expand All @@ -48,32 +28,12 @@ def get_sys_info():
return blob


def get_pkg_info():
"""Returns Python package information as a dict."""
# TODO: Basically copying the requirements from setup.py is brittle,
# should come up with a better way in future, for example,
# using requirements files that can be read in.
dependencies = frozenset(PKG_ORDER)
blob = dict()
for dist in pip.get_installed_distributions():
if dist.project_name in dependencies:
blob[dist.project_name] = dist.version
return blob


def show_versions():
"""Print the formatted information to standard out."""
info = get_sys_info()
info.update(get_pkg_info())
format_str = "{:<%d} {:>%d}" % (max(map(len, info)),
max(map(len, info.values())))
print("\nSystem Information")
print("==================")
for name in SYS_ORDER:
print(format_str.format(name, info[name]))

print("\nPackage Versions")
print("================")
for name in PKG_ORDER:
if name in info:
print(format_str.format(name, info[name]))