[Python-Dev] Re: Revive PEP 396 -- Module Version Numbers ?

2021-04-27 Thread Paul Moore
On Tue, 27 Apr 2021 at 18:01, Brett Cannon  wrote:

> Unfortunately I thought importlib.metadata would have used the module name 
> instead of the metadata details, but in hindsight am guessing that the 
> .dist-info is what it's using to do the lookup and that's based on the 
> package name instead of the project name.
>
> This is a long-standing issue with projects that use project names which 
> differ from their module name, but there's no good way without checking what 
> files a project installed (which is what you're doing below).

That's correct. There is no link from a given import name back to the
PyPI project name. And the metadata for installed packages (defined
here: https://packaging.python.org/specifications/recording-installed-packages/)
is keyed on the PyPI project name, as the OP noted ("beautifulsoup4"
rather than "bs4", "setuptools" rather than "pkg_resources", etc).

>> This is the best I could come up with from reading the docs:
>>
>> import bs4  #<- This is the module we want the version of
>>
>> import importlib
>> import sys
>> from itertools import chain
>> from pathlib import Path
>>
>> loaders = sys.meta_path
>>
>> target_path = Path(bs4.__file__)
>>
>> distros = list(chain(*(finder.find_distributions() for finder in loaders 
>> if hasattr(finder, 'find_distributions'
>> distros_files = chain(*(f for f in (d.files for d in distros)))
>> distro_files = [(d, d.locate_file(f)) for d in distros if d.files for f 
>> in d.files]
>> matching = [d for d, f in distro_files if f == target_path]
>>
>> for match in matching:
>> print("Found Version:", match.version)

The following is a bit simpler. The file.locate() method of a
distribution is undocumented - but I tried to use resolve() on the
path object I got from dist.files, and it appears not to be
implemented (at least in Python 3.9) - PackagePath objects are a
subclass of *Pure* Path objects, not concrete paths :-( TBH, I suspect
the fact that it's undocumented is an oversight, it's clearly
deliberately added.

import importlib.metadata
from pathlib import Path

import pkg_resources
target = Path(pkg_resources.__file__)

for dist in importlib.metadata.distributions():
for file in dist.files:
path = file.locate()
if path == target:
print(f"{dist.metadata['name']}: {dist.version}")
break

To be honest, if anyone were interested in making a PEP from any of
this, having Python modules contain a __distribution_name__ attribute
that links the module back to the PyPI distribution, would probably be
more useful than standardising __version__. But I'm not sufficiently
interested to do anything more than mention that as a possibility.

Paul
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/66G7A5ZZRYT7H6MRJVELFMC23IDP67CL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: bz2.BZ2File doesn't support name?

2021-04-27 Thread Hasan Diwan
[response inline]

On Tue, 27 Apr 2021 at 04:55, Senthil Kumaran  wrote:

> why did you have a self.filename and (getter?) as name. You could set the
> attribute as name.
>

I wasn't aware that this was an option. -- H

-- 
OpenPGP: https://hasan.d8u.us/openpgp.asc
If you wish to request my time, please do so using
*bit.ly/hd1AppointmentRequest
*.
Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest
*.

Sent
from my mobile device
Envoye de mon portable
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/IHIRFXDMJ25IEOX74L5A5KSGAO4GWMQG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Revive PEP 396 -- Module Version Numbers ?

2021-04-27 Thread Brett Cannon
On Mon, Apr 26, 2021 at 3:25 PM Stestagg  wrote:

>
>
> On Mon, Apr 26, 2021 at 10:31 PM Brett Cannon  wrote:
>
>>
>>
>> On Mon, Apr 26, 2021 at 9:37 AM Baptiste Carvello <
>> devel2...@baptiste-carvello.net> wrote:
>>
>>> Hi,
>>>
>>> sorry for being late to the party, but I may not be the only one
>>> wondering…
>>>
>>> Le 14/04/2021 à 20:56, Barry Warsaw a écrit :
>>> >
>>> > I’d forgotten that this PEP was in Deferred state.  I think it should
>>> be rejected and I plan on making that change.  importlib.metadata is a much
>>> better approach to programmatically determining package versions.
>>> >
>>> >
>>> https://docs.python.org/3/library/importlib.metadata.html#distribution-versions
>>>
>>> This is indeed the correct approach, thanks for letting me learn this.
>>>
>>> However, I unsuccessfully searched for the canonical way to look up the
>>> distribution name based on either a module name or an imported module
>>> object. Is there one?
>>>
>>
>> If you mean how to tie a module back to its name on PyPI, you should be
>> able to look up the "Name" in the project's metadata:
>> https://docs.python.org/3/library/importlib.metadata.html#distribution-metadata
>> .
>>
>>
> The missing bit here, for me, is how do you map a module back to it's
> project (distribution)?
>
> For example:
>
> ```
> >>> import bs4
> >>> bs4.__version__
> '4.9.1'
> >>> importlib.metadata.metadata('bs4')
> PackageNotFoundError: bs4
> ```
>
> This is because the distribution calls itself 'beautifulsoup4' instead.
>

Unfortunately I thought importlib.metadata would have used the module name
instead of the metadata details, but in hindsight am guessing that the
.dist-info is what it's using to do the lookup and that's based on the
package name instead of the project name.

This is a long-standing issue with projects that use project names which
differ from their module name, but there's no good way without checking
what files a project installed (which is what you're doing below).

-Brett


>
> The same goes for another package: `umap`, for which the distribution is
> called `umap-learn`
>
>
> This is the best I could come up with from reading the docs:
>
> import bs4  #<- This is the module we want the version of
>
> import importlib
> import sys
> from itertools import chain
> from pathlib import Path
>
> loaders = sys.meta_path
>
> target_path = Path(bs4.__file__)
>
> distros = list(chain(*(finder.find_distributions() for finder in
> loaders if hasattr(finder, 'find_distributions'
> distros_files = chain(*(f for f in (d.files for d in distros)))
> distro_files = [(d, d.locate_file(f)) for d in distros if d.files for
> f in d.files]
> matching = [d for d, f in distro_files if f == target_path]
>
> for match in matching:
> print("Found Version:", match.version)
>
> Steve
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ON5SH2F654I7NEMCYXRH253QRN32LQGG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: bz2.BZ2File doesn't support name?

2021-04-27 Thread Rik
I am new and I am just lurking here, so please pardon me if I say or do 
anything out of place.

I saw your patch Mr. Diwan and I want to say that instead of making `filename` 
attribute, it would be better to change it to `name`, just to adhere to 
standards. And changing the name method to something else or even removing it.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/XEKHBJRPTE2DIV5HHHQRENYXJPBK3N7Y/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Deferral of PEP 648 - Extensible customizations of the interpreter at startup

2021-04-27 Thread Mario Corchero
Hi Barry,

After the feedback and seeing how busy the 3.10 release is being, I was not
expecting less. As mentioned, I have no rush in getting this through. Let's
put the right time into it.
I have been updating the PEP with the feedback you gave me and I expect to
get an updated version up before the end of the week.

Regards,
Mario

On Mon, 26 Apr 2021 at 20:39, Barry Warsaw  wrote:

> Hi Mario,
>
> The Python Steering Council today decided that we will defer consideration
> of PEP 648 to Python 3.11.  On March 30, 2021 we sent the following
> feedback to you via python-dev, which began a discussion thread:
>
>
> https://mail.python.org/archives/list/python-dev@python.org/message/OGYZZZ4A54RI24YEKZEPPLWU4WPRLJPE/
>
> We on the SC extend our thanks again for the PEP, and encourage you to
> continue to work on this PEP for pronouncement in Python 3.11.
>
> Cheers,
> -Barry
> (on behalf of the Python Steering Council)
>
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/KIRJF3NMTF3G5W7TEYCK25ISIT2B4TC4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Existing asyncio features scheduled for removal in Python 3.9 and 3.10

2021-04-27 Thread Victor Stinner
Hi,

On Mon, Apr 26, 2021 at 10:51 PM Illia Volochii
 wrote:
> There are a couple of uncompleted asyncio feature removals scheduled
> for 3.9 and 3.10 releases.
> It will be great if we either complete them or reschedule before the
> 3.10 feature freeze. There are two stale pull requests related to
> this.

I would prefer to wait for 3.11 to remove more deprecated features,
these ones can survive a little bit longer.

If possible, I suggest to remove functions at the beginning of a new
Python development cycle, rather than just before the feature freeze.
So projects tested with the development branch of Python can detect
issues early and we can more time to either fix these projects, or to
consider reverting the removals to give more time for updating these
projects.

It's common that we forget to remove deprecated functions and so that
documentation is not accurate. IMO it's not a big deal ;-)

Victor
-- 
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/37M7AYCYUUIUUSN7MQ25UORJH5K2TWHJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: bz2.BZ2File doesn't support name?

2021-04-27 Thread Senthil Kumaran
Hello Hasan,

Thank you. Please submit your patch as a PR in Github.
https://devguide.python.org/pullrequest/
Also, why did you have a self.filename and (getter?) as name. You could set
the attribute as name.

Thank you,
Senthil

On Tue, Apr 27, 2021 at 12:32 AM Hasan Diwan  wrote:

> I just added the .name property to bz2.Bzip2File and added a test to
> verify it. -- H
>
> On Mon, 26 Apr 2021 at 21:40, Senthil Kumaran  wrote:
>
>> There is an open bug report https://bugs.python.org/issue24258
>>
>> I guess it was overlooked. It could be a good task for someone
>> interested.
>> Please add me as a reviewer if you submit a patch, I can help review and
>> move it forward.
>>
>> On Mon, Apr 26, 2021 at 9:22 PM  wrote:
>>
>>> I was surprised recently to discover that BZ2File (at least in 3.7)
>>> doesn't have a name attribute.  Is there some fundamental reason name
>>> couldn't be supported, or is it just a bug that it wasn't implemented?
>>> ___
>>> Python-Dev mailing list -- python-dev@python.org
>>> To unsubscribe send an email to python-dev-le...@python.org
>>> https://mail.python.org/mailman3/lists/python-dev.python.org/
>>> Message archived at
>>> https://mail.python.org/archives/list/python-dev@python.org/message/N3Q7AN5ISRGKS76GT4YSJX2SV6BNQIWM/
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>
>> ___
>> Python-Dev mailing list -- python-dev@python.org
>> To unsubscribe send an email to python-dev-le...@python.org
>> https://mail.python.org/mailman3/lists/python-dev.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-dev@python.org/message/NCGH6EYRIDFANEAWDQ3KVE6LFXNS4ROV/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
> --
> OpenPGP: https://hasan.d8u.us/openpgp.asc
> If you wish to request my time, please do so using 
> *bit.ly/hd1AppointmentRequest
> *.
> Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest
> *.
>
> Sent
> from my mobile device
> Envoye de mon portable
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/B3CCQRW7UKPK3GD7A6ZSRYNRV3CVXG6V/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/EHDAR5JN2NIV4NEQXWJG525XUPZYNYTQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: bz2.BZ2File doesn't support name?

2021-04-27 Thread Hasan Diwan
I just added the .name property to bz2.Bzip2File and added a test to verify
it. -- H

On Mon, 26 Apr 2021 at 21:40, Senthil Kumaran  wrote:

> There is an open bug report https://bugs.python.org/issue24258
>
> I guess it was overlooked. It could be a good task for someone
> interested.
> Please add me as a reviewer if you submit a patch, I can help review and
> move it forward.
>
> On Mon, Apr 26, 2021 at 9:22 PM  wrote:
>
>> I was surprised recently to discover that BZ2File (at least in 3.7)
>> doesn't have a name attribute.  Is there some fundamental reason name
>> couldn't be supported, or is it just a bug that it wasn't implemented?
>> ___
>> Python-Dev mailing list -- python-dev@python.org
>> To unsubscribe send an email to python-dev-le...@python.org
>> https://mail.python.org/mailman3/lists/python-dev.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-dev@python.org/message/N3Q7AN5ISRGKS76GT4YSJX2SV6BNQIWM/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/NCGH6EYRIDFANEAWDQ3KVE6LFXNS4ROV/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
OpenPGP: https://hasan.d8u.us/openpgp.asc
If you wish to request my time, please do so using
*bit.ly/hd1AppointmentRequest
*.
Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest
*.

Sent
from my mobile device
Envoye de mon portable
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/B3CCQRW7UKPK3GD7A6ZSRYNRV3CVXG6V/
Code of Conduct: http://python.org/psf/codeofconduct/