GithubHelp home page GithubHelp logo

balzss / yip Goto Github PK

View Code? Open in Web Editor NEW
90.0 11.0 5.0 60 KB

Frontend for searching PyPI, a feature rich alternative to pip search

License: GNU General Public License v3.0

Python 100.00%

yip's Introduction

Intro

If you have ever tried to search PyPI via pip you know how difficult it can be. Yip is an attempt to resolve that frustration and create a beautiful and feature rich alternative. Here is an article I wrote about yip on medium.com

Features

  • configurable: every option can be set either explicitly or in a config file
  • looks better: with saner result formatting and coloring (which you can turn off)
  • supports regex: one of the caveat of pip search is the lack of regex support
  • more info: apart from the description it can show you the package size, date of last upload, homepage url or package license
  • limits results: want only the 10 most relevant result? No problem!

Usage example

Normal search:

yip <name of package>

Normal search with size and license information:

yip <name of package> --size --license

Regex search with the homepage of the package:

yip <regex search query> --regex --homepage

Normal search with the 10 most relevant results:

yip <name of package> --limit 10

List of flags

-h, --help

shows information on usage and available flags

-d, --date

shows the upload date of the latest version

-s, --size

shows the size in a human readable format

-L, --license

shows the license of the package

-H, --homepage

shows the homepage (if has any) of the package

-l <number>, --limit <number>

limits to the most relevant result

-r, --regex

allows you to use regex in your search query important: if you use this flag, it will only search in the title, and not in the summary or in the keyword and you cannot combine it with the -limit flag

See it in action

IMPORTANT: This gif is using the outdated flags which won't work anymore. I will update it as soon as I can. The usage example/flaglist however updated and should be used as a reference. yip in action

Config file usage

If you want to make some flags default, automatically sudo install or turn off the colors you can use a config file for that. You have to create a .yiprc file in your home directory and paste the example config from this repo. It is heavily commented and lists all the options you can set. You have to include all the options or it won't work!

Requirements

  • OS-wise: Developed and tested on Linux however it should work on OSX
  • software-wise: Python 3, pip and requests(will switch to xmlrpc, this is only temporary)

Other

  • Licensed under the GPL3
  • Suggestions and pull requests are very welcome! See GitHub's project page for TODO-s if you want to contribute. :)
  • If you encounter any bug or have any questions you can post it here or send an e-mail to [email protected]

yip's People

Contributors

balzss avatar mozillazg avatar qwhex avatar singularitti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yip's Issues

Long flags with 2 dashes

From the examples provided in README, it seems you are using long flags/switches like -size. Would you consider changing it to allow 2 dashes in long flags and one dash for shorts? Such as - -size would equal -s, etc.? That would make the interface more standard looking. Thanks

Doesn't work on Windows

I've tried to run it on Windows, but it doesn't work at all.

In PowerShell it tries to open an external text editor to display the output, but instead of the expected output I get the source code (!), like this:

#!c:\anaconda\python.exe

import io
from contextlib import redirect_stdout
import pip
import sys
import re
import signal
import subprocess

# when user exits with Ctrl-C, don't show error msg
signal.signal(signal.SIGINT, lambda x,y: sys.exit())

colors = {'red': '\033[91m',
        'green': '\033[92m',
        'yellow': '\033[93m',
        'blue': '\033[94m',
        'purple': '\033[95m',
        'endc': '\033[0m'}


def color(color, string):
    return colors.get(color) + string + colors.get('endc')


def pip_search(s_term):
    with io.StringIO() as buf, redirect_stdout(buf):
        pip.main(['search', s_term])
        output = buf.getvalue().replace('\n  INSTALLED', ')  - INSTALLED')
        output = output.replace('\n  LATEST', ' | LATEST')
        return output.split('\n')[:-1]


def search(term=None):
    if not term:
        term = input(color('yellow', 'Enter search term: '))

    formatted = pip_search(term)
    option_list = {}

    for i, f in enumerate(formatted):
        spl = re.split('\) + - ', f)


        if len(spl) < 2:
            print('  ' + f)
            continue
        else:
            if spl[1] == '':
                spl[1] = '---'
            else:
                ' '.join(spl[1].split())

            option_list[str(i)] = spl[0]

        i_flag = '' if 'INSTALLED' not in spl[-1] \
                else color('purple',' ' + spl[-1])

        print('%s%s\n  %s' % (color('blue', '(%d) %s)' % (i, spl[0].rstrip())),
                i_flag, spl[1]) )

    inp = input(color('yellow', '>>> '))
    if not inp.isdigit() or not int(inp) <= i:
        sys.exit()

    choice = option_list[inp].split(' (')[0].rstrip()
    if input('\nDo you really want to install ' +
            color('blue', choice) + '? (y/n) ') == 'y':
        subprocess.call('sudo pip install --upgrade %s' % choice, shell=True)


def installed(term=''):
    pac_list = sorted(["%s (%s)" % (i.key, i.version)
        for i in pip.get_installed_distributions()])

    for p in pac_list:
        if term in str(p):
            print(color('blue', p))


def show_help():
    print('''Usage information:

  %s
   - searches for packages in the pypi repository that matches the query
   - list them with numbers next to them
   - you type in the number of the package you want to install and hit enter

  %s
   - lists all python packages installed on your system

  %s
   - lists installed packages that match the query''' % (
        color('yellow', 'yip search <query>'),
        color('yellow', 'yip list'),
        color('yellow', 'yip list <query>')))

    sys.exit()

def main(argv):
    if len(argv) < 2:
        show_help()

    if argv[1] == 'list':
        if len(argv) == 2:
            installed()
        else:
            installed(' '.join(argv[2:]))
    elif argv[1] == 'search':
        if len(argv) == 2:
            search()
        else:
            search(' '.join(argv[2:]))
    else:
        show_help()


if __name__ == "__main__":
    main(sys.argv)

It doesn't matter if Python 3 or Python 2 is used.

error searching pip has no attribute get_installed_distributions

I am using python3 and Manjaro Linux, I tried to upgrade the pip package and create a new virtualenv and the problem persists.

/home/skyline: yip search go
 |----------------------------------------------------------------------------------------------------| 0.0% Traceback (most recent call last):
  File "/usr/bin/yip", line 434, in 
    installed_packages = get_installed()
  File "/usr/bin/yip", line 152, in get_installed
    return {i.key: i.version for i in pip.get_installed_distributions()}
AttributeError: module 'pip' has no attribute 'get_installed_distributions'

ImportError: No module named configparser

Eriks-MacBook-Pro:~ erik$ sudo pip install yip
Password:
Downloading/unpacking yip
  Downloading yip-1.1.tar.gz
  Running setup.py egg_info for package yip

Installing collected packages: yip
  Running setup.py install for yip
    changing mode of build/scripts-2.7/yip from 644 to 755

    changing mode of /usr/local/bin/yip to 755
Successfully installed yip
Cleaning up...

Eriks-MacBook-Pro:~ erik$ yip djangorestframework
Traceback (most recent call last):
  File "/usr/local/bin/yip", line 10, in <module>
    import configparser
ImportError: No module named configparser

Eriks-MacBook-Pro:~ erik$ python --version
Python 2.7.10

Tests

Obligatory ... "this package needs tests" issue.

AttributeError

Hello Balázs,

I'm getting AttributeError:
>yip <whatever package> |----------------------------------------------------------------------------------------------------| 0.0% Traceback (most recent call last): File "/usr/local/bin/yip", line 434, in <module> installed_packages = get_installed() File "/usr/local/bin/yip", line 152, in get_installed return {i.key: i.version for i in pip.get_installed_distributions()} AttributeError: module 'pip' has no attribute 'get_installed_distributions'

My pip3 is fresh:
`

pip3 --version
pip 21.0.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
`
Any suggestion?
Thanks

utf-8 character in file

$ python --version
Python 2.7.5
$ yip -h
  File "/home/foo/.virtualenvs/c/bin/yip", line 412
SyntaxError: Non-ASCII character '\xe2' in file /home/foo/.virtualenvs/c/bin/yip on line 412, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Could you add utf-8 string to the file?

Why not make `search` optional?

Why not make yip blah the same thing as yip search blah?

This is more curiousity than anything. I'm sure there are others asking why you do this after reading the blurb saying that this is "yaourt for pip".

New release to fix breakages

v1.2.6, released 2016, is the latest tag on GitHub and PyPI.

#8 was a very important bugfix which hasnt been released yet.

What is needed to get a new release happening?

Do not colourise text if standard output is not a TTY

It seems yip ads colours no matter where the output goes. IMHO, colours should only be added if sys.stdout.isatty() is True:

$ yip list                  # this output should be coloured
aiodns (1.0.0)
  ⋮
zope.interface (4.3.2)
$ yip list | cat            # this output should NOT be coloured
aiodns (1.0.0)
  ⋮
zope.interface (4.3.2)
$ yip list > installed.txt  # nor should this
$

Does not work on pip 10

When I am trying to type yip <some package>, it returns me some messages

 |----------------------------------------------------------------------------------------------------| 0.0% Traceback (most recent call last):
  File "/usr/local/bin/yip", line 434, in <module>
    installed_packages = get_installed()
  File "/usr/local/bin/yip", line 152, in get_installed
    return {i.key: i.version for i in pip.get_installed_distributions()}
AttributeError: module 'pip' has no attribute 'get_installed_distributions'

It seems that it does not work on pip 10 and above. It could probably be solved by from pip._internal.utils.misc import get_installed_distributions instead of pip.get_installed_distributions directly.
My pip version:

$ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

Reference

  1. pypa/pip#5243

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.