[issue45591] PathFinder does not find namespace packages children

2021-10-27 Thread Filipe Laíns

Filipe Laíns  added the comment:

Okay, I think that makes sense to me. Thank you!!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45591] PathFinder does not find namespace packages children

2021-10-27 Thread Brett Cannon


Brett Cannon  added the comment:

The full name argument approach comes from PEP 302.

But you want the full name as you are otherwise missing potentially key 
information for the finder. For instance, if you manipulate __path__, then it's 
just some random directory you're searching in. But searching for what? What if 
you want custom logic based on what package you're searching under?

Because the import system is designed to be flexible enough to let you import 
from a URL or SQLite database as well as DSL files, providing all of the 
available information becomes important.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45591] PathFinder does not find namespace packages children

2021-10-26 Thread Filipe Laíns

Filipe Laíns  added the comment:

Thank you for clarifying, that does work. This is surprising behavior to me, do 
you recall what was the reasoning for this design? Or is there some discussion 
you can point me to? And sorry for bothering, I know I am asking too many 
questions, but I'd like to understand the importlib design 😅

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45591] PathFinder does not find namespace packages children

2021-10-26 Thread Brett Cannon


Brett Cannon  added the comment:

> I am curious, what is `fullname` supposed to mean then? "full" in what sense?

You can still specify the full name of the module you're trying to import, but 
you also need to pass in the location information for that module. So the code 
does `fullname.rpartition(".")[-1]` to get the name of the module that you're 
looking for. So `PathFinder.find_spec('namespace.a', 
path=spec.submodule_search_locations)` should also work.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45591] PathFinder does not find namespace packages children

2021-10-25 Thread Filipe Laíns

Filipe Laíns  added the comment:

Ah, this was not obvious to me! I did not specify a path, but as it defaults to 
`sys.path` and `namespace.a` is available there, I was expecting it to find it.
One of the things that threw me off was the first arguments being called 
`fullname`, which I assumed implied that `PathFinder` was able to do a 
recursive search.


This indeed works:
```
$ ./python
Python 3.11.0a1+ (heads/main:9e05da6224, Oct 23 2021, 20:36:14) [GCC 11.1.0] on 
linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.machinery import PathFinder
>>> spec = PathFinder.find_spec('namespace')
>>> PathFinder.find_spec('a', path=spec.submodule_search_locations)
ModuleSpec(name='a', loader=<_frozen_importlib_external.SourceFileLoader object 
at 0x7f245d0d3e80>, origin='/home/anubis/git/cpython/namespace/a.py')
```

I should have validated if normal packages also had the same behavior, which 
they do, before opening this -.-

I am curious, what is `fullname` supposed to mean then? "full" in what sense?

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45591] PathFinder does not find namespace packages children

2021-10-25 Thread Brett Cannon


Brett Cannon  added the comment:

You didn't specify the path to search in to find `a`. 
https://docs.python.org/3/library/importlib.html#importlib.machinery.PathFinder.find_spec
 says that PathFinder only has class methods, which means find_spec() won't 
know where 'namespace' is, so the search will fail to find anything, hence 
returning None.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45591] PathFinder does not find namespace packages children

2021-10-23 Thread Filipe Laíns

New submission from Filipe Laíns :

```
$ tree namespace
namespace/
└── a.py

0 directories, 1 file
```

```
$ ./python
Python 3.9.7 (default, Oct 10 2021, 15:13:22)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.machinery import PathFinder
>>> PathFinder.find_
PathFinder.find_distributions(  PathFinder.find_module( 
PathFinder.find_spec(
>>> PathFinder.find_spec('namespace')
ModuleSpec(name='namespace', loader=None, 
submodule_search_locations=_NamespacePath(['/home/anubis/git/cpython/namespace']))
>>> PathFinder.find_spec('namespace.a')
```

Currently, it is unable to find namespace.a, but it should:

```
Python 3.11.0a1+ (heads/main:9e05da6224, Oct 23 2021, 20:36:14) [GCC 11.1.0] on 
linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.machinery import PathFinder
>>> spec = PathFinder.find_spec('namespace')
>>> spec.loader.load_module('namespace.a')
:283: DeprecationWarning: the load_module() method 
is deprecated and slated for removal in Python 3.12; use exec_module() instead
)>
```

I can make a PR, but just wanted to make sure the current behavior is not 
intended.

--
messages: 404912
nosy: FFY00, brett.cannon, eric.snow, ncoghlan
priority: normal
severity: normal
status: open
title: PathFinder does not find namespace packages children

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com