Skip to content

Instantly share code, notes, and snippets.

@hoefling
Created May 29, 2018 10:51
Show Gist options
  • Save hoefling/314565368a66c308b4d7d407a3028cb7 to your computer and use it in GitHub Desktop.
Save hoefling/314565368a66c308b4d7d407a3028cb7 to your computer and use it in GitHub Desktop.
List python packages with Pacman package owners, see https://unix.stackexchange.com/questions/444195/
#!/usr/bin/env python3
import operator
import subprocess
import sys
import pkg_resources
try:
from pip._internal.commands.list import tabulate
except ImportError:
from pip.commands.list import tabulate
def query(file):
proc = subprocess.Popen(['pacman', '-Qqo', file], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True)
out, err = proc.communicate()
return out.strip()
def main():
packages = sorted(pkg_resources.WorkingSet(), key=operator.attrgetter('project_name'))
if not packages:
return 0
data = [(pkg.project_name, pkg.version, query(pkg.egg_info or pkg.path), ) for pkg in packages]
data.insert(0, ('Package', 'Version', 'Owner', ))
rows, sizes = tabulate(data)
rows.insert(1, ' '.join(map(lambda x: '-' * x, sizes)))
for row in rows:
print(row)
return 0
if __name__ == '__main__':
sys.exit(main())
@hoefling
Copy link
Author

Usage example:

$ sudo pacman -S python-pip wheel  # install some python packages with pacman
$ sudo pip install tqdm  # install some python packages with pip
$ ./pip-query
    Package    Version Owner
    ---------- ------- -----------------
    appdirs    1.4.3   python-appdirs
    packaging  17.1    python-packaging
    pip        9.0.1   python-pip
    pyparsing  2.2.0   python-pyparsing
    setuptools 39.2.0  python-setuptools
    six        1.11.0  python-six
    tqdm       4.23.4
    wheel      0.31.1  python-wheel

tqdm has no Owner, as expected.

For more info, check out this answer on Unix & Linux SO site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment