banesullivan / scooby

🐶 🕵️ Great Dane turned Python environment detective
MIT License
47 stars 12 forks source link

Add pip listing method #36

Closed banesullivan closed 2 years ago

banesullivan commented 5 years ago

This adds a way to create pip requirements files addressing part of #35

prisae commented 5 years ago

Just for clarification, how does that differ from a pip freeze? I guess only the packages you want. This, on the other hand, just revealed another way how to find version numbers... with pip freeze.

prisae commented 5 years ago

E.g., the dummy package no-version, which I created and has no __version__ info, is reported by pip freeze as no-version==0.1.0; so pip freeze must have some clever features how to get version number, which might be useful for us.

prisae commented 5 years ago

Maybe the whole version-finding stuff we have could be replaced with grepping the pip freeze output? It also finds vtk and pyqt without any fuss and extra loops...

banesullivan commented 5 years ago

Just for clarification, how does that differ from a pip freeze? I guess only the packages you want.

Exactly - I often work in cluttered, experimental environments and don't need to share the versions of everything for a given project.

pip freeze must have some clever features how to get version number, which might be useful for us.

That's a really interesting find... we should take a look in that source to see how they implemented it.

Maybe the whole version-finding stuff we have could be replaced with grepping the pip freeze output?

That might be a nice approach to implement

Does that work for packages installed with anaconda as well?

prisae commented 5 years ago

Yes it does work for conda-installed packages too.

prisae commented 5 years ago

Instead of making the user write

with open('requirements.txt', 'w') as f:
    f.write(report.listing())

couldn't you implement that directly in report.listing()? Maybe with an optional parameter, e.g.,

def listing(write=True):
   ...

so if write=True, it is written to ./requirements.txt, if it is false, it is returned to the user.

So the user would only have to do

report.listing()

to write requirements.txt.

prisae commented 5 years ago

That's a really interesting find...

I do use pip freeze every now and then, but I never made the link to Versions or now Report.

banesullivan commented 5 years ago

I think everything is addressed now. @prisae can you approve whenever you get a chance?

banesullivan commented 5 years ago

One incredibly annoying thing to consider - many packages out there have PyPI names that vary from their import statement, e.g. sklearn is pip install scikit-learn and import sklearn. We might have to use pip for these scenarios...

prisae commented 5 years ago

One incredibly annoying thing to consider - many packages out there have PyPI names that vary from their import statement, e.g. sklearn is pip install scikit-learn and import sklearn. We might have to use pip for these scenarios...

I do not think this as an issue, because the reporting always works with the name as you would import it. You can even provide strings or packages itself. E.g.

import scooby
scooby.Report('scipy')
import scipy
scooby.Report(scipy)

So there should be no confusion, IMHO. I usually use packages, not strings, because I am interested in the things I actually imported, so directly provided them works just fine. Maybe there are other scenarios which might differ.

banesullivan commented 5 years ago

I do not think this as an issue, because the reporting always works with the name as you would import it.

I'm only referring to how it will be an issue for this PR when we send those packages to a requirements.txt file. pip install sklearn will not install scikit-learn This PR has scooby write sklearn in the requirements.txt file, not scikit-learn which is needed. There are plenty of other packages out there like this.

prisae commented 5 years ago

Now I get you. Correct. In this case we would have to implement the pip freeze approach I guess...

banesullivan commented 5 years ago

I'm going to put this on hold for a while and see if anything comes of #37