Re: [Distutils] Getting dependecies of package from PyPiJSON

2017-07-21 Thread Marius Gedminas
On Fri, Jul 21, 2017 at 11:39:01AM +0200, Krzysiek Płachno wrote:
> Guys! Thanks a lot for all your responses and willingness to help!
> 
> Yesterday I noticed this `requires_dist` in response for Requests package. But
> actually it was the only one that had this field populated from many packages
> that I asked API for. So this cannot be reliable way of getting dependecies.
> 
> So if not using pip, the only way to get dependencies is from built packages:
> .whl and .egg.
> So in .egg it'd be: EGG_INFO/requires.txt and in .whl : 
> .dist-info/metadata.json, right?

I've had some luck parsing *.egg-info/requires.txt files in sdists.
This is not 100% reliable (a setup.py may dynamically-compute the
install_requires list during install time depending on sys.version_info
or other factors), but it was good enough for my purposes.

https://github.com/mgedmin/ztk-py3-status/blob/master/get_deps.py

Regards,
Marius Gedminas
-- 
Hi. I'm the "I love you" .signature virus. You have been infected.
Please panic immediately.


signature.asc
Description: PGP signature
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Getting dependecies of package from PyPiJSON

2017-07-21 Thread Nick Coghlan
On 21 July 2017 at 19:39, Krzysiek Płachno  wrote:
> Guys! Thanks a lot for all your responses and willingness to help!
>
> Yesterday I noticed this `requires_dist` in response for Requests package.
> But actually it was the only one that had this field populated from many
> packages that I asked API for. So this cannot be reliable way of getting
> dependecies.
>
> So if not using pip, the only way to get dependencies is from built
> packages: .whl and .egg.
> So in .egg it'd be: EGG_INFO/requires.txt and in .whl :
> .dist-info/metadata.json, right?

For wheel archives, the JSON format technically isn't stable yet (and
wheel generators aren't required to include it), so the file you want
is {distribution}-{version}.dist-info/METADATA, and specifically the
"Requires-Dist" entries

The relevant specifications:

METADATA file: 
https://www.python.org/dev/peps/pep-0345/#requires-dist-multiple-use
Requires-Dist values: https://www.python.org/dev/peps/pep-0508/
Wheel format: https://www.python.org/dev/peps/pep-0427/
Draft JSON metadata format: https://www.python.org/dev/peps/pep-0426/

There's no interoperability spec for the egg format, but the
setuptools docs have pretty good documentation for it:
https://setuptools.readthedocs.io/en/latest/formats.html#dependency-metadata

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Getting dependecies of package from PyPiJSON

2017-07-21 Thread Krzysiek Płachno
Guys! Thanks a lot for all your responses and willingness to help!

Yesterday I noticed this `requires_dist` in response for Requests package.
But actually it was the only one that had this field populated from many
packages that I asked API for. So this cannot be reliable way of getting
dependecies.

So if not using pip, the only way to get dependencies is from built
packages: .whl and .egg.
So in .egg it'd be: *EGG_INFO/requires.txt* and in .whl :
*.dist-info/metadata.json*, right?

Thanks a lot!
Best,
Krzysztof



2017-07-21 3:56 GMT+02:00 Jeremy Stanley :

> On 2017-07-20 21:09:28 -0400 (-0400), John Thorvald Wodder II wrote:
> > [Sending to the list this time]
> >
> > On 2017 Jul 20, at 12:41, Jeremy Stanley  wrote:
> > > So while it might be possible to add some sort of feature
> > > to inspect wheels at upload and then store the specific dependencies
> > > declared therein and report those back via an API method, I expect
> > > coverage across packages in general would be fairly low today.
> >
> > PyPI (both Legacy and Warehouse) actually does do this already;
> > see the `requires_dist` field in, e.g.,
> > . However, this only seems to
> > work if the maintainer uploads the wheel before uploading the
> > sdist (unless the sdist is a .zip instead of a .tar.gz, then it
> > can be uploaded first?  I'm not sure).
>
> Indeed, I'd never noticed that. And the projects I work on upload
> wheels before sdists so seem to have everything from our
> install_requires reflected there (including extras and environment
> markers... even the versioned pages work). Very neat, and glad to
> learn it already exists.
>
> I wonder though how it deals with projects that build multiple
> wheels for different platforms with different install_requires. It
> looks like that's a top-level field in the info dict so can't
> reasonably be differentiated. Takes the first one uploaded I guess
> and ignores the subsequent ones?
>
> Anyway, this looks like it probably fulfils Krzysiek's need for
> XWiki. Thanks for pointing it out! I very well may try to leverage
> this for a few things myself.
> --
> Jeremy Stanley
> ___
> Distutils-SIG maillist  -  Distutils-SIG@python.org
> https://mail.python.org/mailman/listinfo/distutils-sig
>
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig