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

List venvs #308

Closed
wants to merge 21 commits into from
Closed

List venvs #308

wants to merge 21 commits into from

Conversation

juancarlospaco
Copy link

Example:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs
*** fades ***  2018-04-06 23:38:49,233  INFO     
VENV_UUID:      9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
DATE_TIME:      2017-02-21T00:54:00-03:00
FULL_PATH:      /home/juan/.local/share/fades/9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
PACKAGES:       {'pypi': {'microraptor': '1.9.5'}}
INTERPRETER:    /usr/bin/python3.6
OPTIONS:        {'pyvenv_options': [], 'virtualenv_options': []}

*** fades ***  2018-04-06 23:38:49,233  INFO     
VENV_UUID:      9fc04480-b2f2-43da-a7ed-6afc32321522
DATE_TIME:      2017-04-27T14:48:40-03:00
FULL_PATH:      /home/juan/.local/share/fades/9fc04480-b2f2-43da-a7ed-6afc32321522
PACKAGES:       {'pypi': {'requests': '2.13.0'}}
INTERPRETER:    /usr/bin/python3.6
OPTIONS:        {'pyvenv_options': [], 'virtualenv_options': []}

*** fades ***  2018-04-06 23:38:49,234  INFO
VENV_UUID:      9affefcf-1a7b-4545-8bf5-52739ee90299
DATE_TIME:      2018-04-06T21:55:55-03:00
FULL_PATH:      /home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299
PACKAGES:       {'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}
INTERPRETER:    /usr/bin/python3.6
OPTIONS:        {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

juan@x ~/code/fades list-venvs|✓ $

(The logger=None allows more clean output without the line *** fades *** 2018-04-06 23:38:49,233 INFO)
🐍💻🐱👍

@coveralls
Copy link

coveralls commented Apr 7, 2018

Coverage Status

Coverage decreased (-1.04%) to 73.899% when pulling c2c548d on juancarlospaco:list-venvs into 56e6f8e on PyAr:master.

@facundobatista
Copy link
Member

Hello! Thanks for this work!!

I'll do a general analysis on the example you shown above, and after you consider this feedback, a proper review.

So, some items (numbered, in case you want to refer them, feel free to discuss this here or in the Telegram group):

  1. This work addresses Have a --list-envs #216; certainly not Show venv info #276 which is for a specific venv according to the dependencies, and surely not Help does not indicate how to obtain a UUID to remove it #306 which may be a duplicate or very closely related to Show venv info #276.

  2. This new option (--list-venvs) needs an entry and example in the README, and proper documentation in the man page

  3. Tests needed (no, it's not enough to not break older tests for a new parameter)

  4. Don't use logging for this; the user is requiring some information, so is ok to use stdout in this case (see for example what we do for -V option)

  5. I would do a better layout of the results; specifically:

  • separate each block using an empty line and the virtualenv ID, with the rest of the information indented

  • the timestamp should be more readable; it's ok to keep the timezone (maybe improved) but let's just get rid of the intermediate "T"

  • reorder the rest of the options according to it's "importance" (?)

  • use more human friendly names and case for the options

    here is a sample layout that I think is better, using the same content you provided above:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs
Virtualenv id: 9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
    path:          /home/juan/.local/share/fades/9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
    dependencies:  {'pypi': {'microraptor': '1.9.5'}}
    timestamp:     2017-02-21T00:54:00-03:00
    interpreter:   /usr/bin/python3.6
    options:       {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv id: 9fc04480-b2f2-43da-a7ed-6afc32321522
    path:          /home/juan/.local/share/fades/9fc04480-b2f2-43da-a7ed-6afc32321522
    dependencies:  {'pypi': {'requests': '2.13.0'}}
    timestamp:     2017-04-27T14:48:40-03:00
    interpreter:   /usr/bin/python3.6
    options:       {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv id: 9affefcf-1a7b-4545-8bf5-52739ee90299
    path:          /home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299
    dependencies:  {'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}
    timestamp:     2018-04-06T21:55:55-03:00
    interpreter:   /usr/bin/python3.6
    options:       {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

juan@x ~/code/fades list-venvs|✓ $

@juancarlospaco
Copy link
Author

Some tests failing because of #309 (comment)

@juancarlospaco
Copy link
Author

Now #309 seems Fixed. Is this Ok?. 🤔

fades/helpers.py Outdated
pac=v_dct_get("installed"),
pyv=v_dct_get("interpreter"),
opt=v_dct_get("options"),
dat=datetime.fromtimestamp(v_dct_get("timestamp")).replace(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use {:%Y-%m-%d %H:%m} (or similar) in tmplt and here you only need to use fromtimestamp

@gilgamezh
Copy link
Contributor

as fades is a CLI maybe we have to provide a way to "grep" the output.

fades --list-venvs | grep my_dep <--- all venvs with my_dep installed ?

Or maybe is better to add a filter ?

@juancarlospaco
Copy link
Author

juancarlospaco commented Apr 22, 2018

Not sure I follow, output IS grep-able. 🤔

You want an Option for it to spit out the pretty printed JSON, then you can use any JSON specific tool to parse/highlight/filter/whatever ?.

@facundobatista
Copy link
Member

Being able to grep is a nice thing... we could show them one per line, like...

id='9dbbe58b-94ef-40a7-8a35-098a04cf4dfd', path='/home/juan/.local/share/fades/9dbbe58b-94ef-40a7-8a35-098a04cf4dfd', dependencies={'pypi': {'microraptor': '1.9.5'}}, timestamp='2017-02-21T00:54:00-03:00', interpreter='/usr/bin/python3.6', options={'pyvenv_options': [], 'virtualenv_options': []},
id='9fc04480-b2f2-43da-a7ed-6afc32321522', path='/home/juan/.local/share/fades/9fc04480-b2f2-43da-a7ed-6afc32321522', dependencies={'pypi': {'requests': '2.13.0'}}, timestamp='2017-04-27T14:48:40-03:00', interpreter='/usr/bin/python3.6', options={'pyvenv_options': [], 'virtualenv_options': []},
id='9affefcf-1a7b-4545-8bf5-52739ee90299', path='/home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299', dependencies={'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}, timestamp='2018-04-06T21:55:55-03:00', interpreter='/usr/bin/python3.6', options={'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']},

However, that escalates really quickly to "horrible".

We could output a real json with all the info... but how would we consume it? if we're making that into a Python code anyway, probable it's easier to do ... ?

>>> import fades
>>> fades.list_venvs()
<some json>

However, having to process a full json only to see those venvs that have some dependency installed is not really nice. Is this a use case? I think it's a nice to have.

Note that we should have a different --show-venv or something to dump all the info "of the venv that matches the dependencies I'm passing" (which is what #276) is about.

@juancarlospaco
Copy link
Author

Right now fades.list_venvs() returns a str, the same printed to std out.

@juancarlospaco
Copy link
Author

juancarlospaco commented Apr 24, 2018

This adds optional Filtering of the list of venvs!.

Filter by UUID:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs 9affefcf-1a7b-4545-8bf5-52739ee90299

Virtualenv UUID:  9affefcf-1a7b-4545-8bf5-52739ee90299
    timestamp:    2018-04-06 21:55:55
    full path:    /home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299
    dependencies: {'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

juan@x ~/code/fades list-venvs|✓ $

Filter by Dependency:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs ipython

Virtualenv UUID:  158c5d41-10b1-412b-8522-f5ad3caba62c
    timestamp:    2017-12-16 04:32:32
    full path:    /home/juan/.local/share/fades/158c5d41-10b1-412b-8522-f5ad3caba62c
    dependencies: {'pypi': {'ipython': '6.2.1', 'scrapy': '1.4.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

Virtualenv UUID:  9affefcf-1a7b-4545-8bf5-52739ee90299
    timestamp:    2018-04-06 21:55:55
    full path:    /home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299
    dependencies: {'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

juan@x ~/code/fades list-venvs|✓ $

Filter by Dependencies:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs ipython,pep257

Virtualenv UUID:  b07962da-5719-47a9-a8d0-e5ae29232e6e
    timestamp:    2017-06-22 22:55:51
    full path:    /home/juan/.local/share/fades/b07962da-5719-47a9-a8d0-e5ae29232e6e
    dependencies: {'pypi': {'flake8': '2.5.2', 'logassert': '2', 'mccabe': '0.4.0', 'nose': '1.3.7', 'pep8': '1.7.0', 'pyflakes': '1.0.0', 'pyxdg': '0.25', 'wheel': '0.26.0', 'rst2html5': '1.7.5', 'setuptools': '28.8.0', 'nosexcover': '1.0.10', 'pep257': '0.7.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  158c5d41-10b1-412b-8522-f5ad3caba62c
    timestamp:    2017-12-16 04:32:32
    full path:    /home/juan/.local/share/fades/158c5d41-10b1-412b-8522-f5ad3caba62c
    dependencies: {'pypi': {'ipython': '6.2.1', 'scrapy': '1.4.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

Virtualenv UUID:  9affefcf-1a7b-4545-8bf5-52739ee90299
    timestamp:    2018-04-06 21:55:55
    full path:    /home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299
    dependencies: {'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

Virtualenv UUID:  5f11ebe8-46a7-45d1-ba01-6bf5011818a8
    timestamp:    2018-04-06 23:53:57
    full path:    /home/juan/.local/share/fades/5f11ebe8-46a7-45d1-ba01-6bf5011818a8
    dependencies: {'pypi': {'pycodestyle': '2.3.1', 'nose': '1.3.7', 'wheel': '0.26.0', 'rst2html5': '1.9.3', 'flake8': '3.5.0', 'pyflakes': '1.6.0', 'pyxdg': '0.25', 'pyuca': '1.1.2', 'nosexcover': '1.0.10', 'logassert': '2', 'pep257': '0.7.0', 'mccabe': '0.6.1', 'pep8': '1.7.0', 'setuptools': '28.8.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

juan@x ~/code/fades list-venvs|✓ $

Filter by non-existent:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs non_existent

juan@x ~/code/fades list-venvs|✓ $

Dont Filter:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs 

Virtualenv UUID:  9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
    timestamp:    2017-02-21 00:54:00
    full path:    /home/juan/.local/share/fades/9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
    dependencies: {'pypi': {'microraptor': '1.9.5'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  6852052a-da4a-4b48-8542-d1c183f82cdd
    timestamp:    2017-04-26 20:02:30
    full path:    /home/juan/.local/share/fades/6852052a-da4a-4b48-8542-d1c183f82cdd
    dependencies: {'pypi': {'unicodemoticon': '3.0.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  9fc04480-b2f2-43da-a7ed-6afc32321522
    timestamp:    2017-04-27 14:48:40
    full path:    /home/juan/.local/share/fades/9fc04480-b2f2-43da-a7ed-6afc32321522
    dependencies: {'pypi': {'requests': '2.13.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  ce84c8de-ea4a-4b56-b992-0f284cb8bafd
    timestamp:    2017-06-22 22:09:21
    full path:    /home/juan/.local/share/fades/ce84c8de-ea4a-4b56-b992-0f284cb8bafd
    dependencies: {'pypi': {}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  b07962da-5719-47a9-a8d0-e5ae29232e6e
    timestamp:    2017-06-22 22:55:51
    full path:    /home/juan/.local/share/fades/b07962da-5719-47a9-a8d0-e5ae29232e6e
    dependencies: {'pypi': {'flake8': '2.5.2', 'logassert': '2', 'mccabe': '0.4.0', 'nose': '1.3.7', 'pep8': '1.7.0', 'pyflakes': '1.0.0', 'pyxdg': '0.25', 'wheel': '0.26.0', 'rst2html5': '1.7.5', 'setuptools': '28.8.0', 'nosexcover': '1.0.10', 'pep257': '0.7.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  95bf380a-b164-4c3c-8c50-b9edc3e18667
    timestamp:    2017-06-28 12:20:44
    full path:    /home/juan/.local/share/fades/95bf380a-b164-4c3c-8c50-b9edc3e18667
    dependencies: {'pypi': {'anglerfish': '2.5.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  158c5d41-10b1-412b-8522-f5ad3caba62c
    timestamp:    2017-12-16 04:32:32
    full path:    /home/juan/.local/share/fades/158c5d41-10b1-412b-8522-f5ad3caba62c
    dependencies: {'pypi': {'ipython': '6.2.1', 'scrapy': '1.4.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

Virtualenv UUID:  9affefcf-1a7b-4545-8bf5-52739ee90299
    timestamp:    2018-04-06 21:55:55
    full path:    /home/juan/.local/share/fades/9affefcf-1a7b-4545-8bf5-52739ee90299
    dependencies: {'pypi': {'ipython': '6.3.1', 'fades': '7.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': ['--system-site-packages'], 'virtualenv_options': ['--system-site-packages']}

Virtualenv UUID:  5f11ebe8-46a7-45d1-ba01-6bf5011818a8
    timestamp:    2018-04-06 23:53:57
    full path:    /home/juan/.local/share/fades/5f11ebe8-46a7-45d1-ba01-6bf5011818a8
    dependencies: {'pypi': {'pycodestyle': '2.3.1', 'nose': '1.3.7', 'wheel': '0.26.0', 'rst2html5': '1.9.3', 'flake8': '3.5.0', 'pyflakes': '1.6.0', 'pyxdg': '0.25', 'pyuca': '1.1.2', 'nosexcover': '1.0.10', 'logassert': '2', 'pep257': '0.7.0', 'mccabe': '0.6.1', 'pep8': '1.7.0', 'setuptools': '28.8.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  158988c8-abbe-4a35-ad71-d82221b0c065
    timestamp:    2018-04-24 15:24:45
    full path:    /home/juan/.local/share/fades/158988c8-abbe-4a35-ad71-d82221b0c065
    dependencies: {}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

juan@x ~/code/fades list-venvs|✓ $

🐈

@facundobatista
Copy link
Member

I really don't like having to filter ourselves.

You would be adding a lot of code, and it will never be enough, like... hey, I now want to filter by interpreter!

The best filtering tool is grep, people should use grep, we need to make (at least some of) our output consumable by grep

@juancarlospaco
Copy link
Author

Filter by Interpreter:

juan@x ~/code/fades list-venvs|✓ $ bin/fades --list-venvs /usr/bin/python3.6

Virtualenv UUID:  9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
    timestamp:    2017-02-21 00:54:00
    full path:    /home/juan/.local/share/fades/9dbbe58b-94ef-40a7-8a35-098a04cf4dfd
    dependencies: {'pypi': {'microraptor': '1.9.5'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

Virtualenv UUID:  6852052a-da4a-4b48-8542-d1c183f82cdd
    timestamp:    2017-04-26 20:02:30
    full path:    /home/juan/.local/share/fades/6852052a-da4a-4b48-8542-d1c183f82cdd
    dependencies: {'pypi': {'unicodemoticon': '3.0.0'}}
    interpreter:  /usr/bin/python3.6
    options:      {'pyvenv_options': [], 'virtualenv_options': []}

juan@x ~/code/fades list-venvs|✓ $ 

@juancarlospaco
Copy link
Author

juancarlospaco commented Apr 24, 2018

The Template is now an arg of the function so anyone can customize helpers.LIST_VENVS_TEMPLATE or pass it as argument and it works, for grep or whatever tool.

I think the point of --list-venvs is to make it human friendly and smooth on the eye,
else you can just cat venvs.idx | grep foo... 🤣

@facundobatista
Copy link
Member

Ok, we discussed with @gilgamezh about this PR. We have chosen the desired output.

There will not be any template, and no internal heuristic for filtering.

The user will have two options: --list-venvs and --list-venvs-raw. The former will output what I specified in this comment, the later will just show one record per line, json-formated (to be explicit: it's not a json of the whole DB, each line is a json of it's own, each record of the DB encoded to json and shown).

I think that with this info you can continue and prepare the PR for the next review, right? Please let me know if you have any doubt (or we can talk in fades' IRC channel or Telegram group.

Thanks!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants