[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-18 Thread Filipe Laíns
On Tue, 2022-05-17 at 23:04 -0700, Christopher Barker wrote: > If we go back to the OPs point, they were saying that they didn't like that > you have to put an __init__.py in a dir in order to put resources in it. And I > get that idea, but that wouldn't be making a dir a resource, it would be >

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-18 Thread Jeff Allen
On 16/05/2022 23:22, Filipe Laíns wrote: No, Python source files are resources too. "resource" is an abstract concept akin to files, its propose is to allow support other use-cases than just files on the OS file system (eg. zip file, tarball, database). Adding a "directory" reference goes

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-18 Thread Christopher Barker
On Tue, May 17, 2022 at 1:46 PM Greg Werbin wrote: > 1) Allow a directory to be a resource in and of itself, and provide APIs > for working with "directory-type" resources. > I'm still confused here -- what would a "directory be a resource" even mean? A directory is not a file, it is a

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-17 Thread Greg Werbin
I think I might have confused things further, my apologies. I see 3 related but distinct feature requests here: 1) Allow a directory to be a resource in and of itself, and provide APIs for working with "directory-type" resources. 2) Allow resources with "/" in the name, and provide APIs to

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-17 Thread Filipe Laíns
On Mon, 2022-05-16 at 14:36 +, Greg Werbin wrote: > Non-"binary" resources are already in widespread use, so perhaps that > requirement shouldn't be in the docs at all. In practice, a resource is "any > data file other than a Python source file." > > Moreover, I see no reason why a resource

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-17 Thread Filipe Laíns
On Mon, 2022-05-16 at 18:55 +1200, Greg Ewing wrote: > On 16/05/22 5:05 pm, Christopher Barker wrote: > > a directory is not a binary artifact -- it can't have actually data in > > it like a file can. > > and: > > > the entire > > point of resources is to provide an abstraction -- the

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-16 Thread Chris Angelico
On Tue, 17 May 2022 at 08:00, Greg Ewing wrote: > > On 17/05/22 4:58 am, Christopher Barker wrote: > > if you want to call your collection of files a single resource, then > > sure -- but then it's not the directory that's the resource, it's the > > collection of files that's the resource > >

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-16 Thread Greg Ewing
On 17/05/22 4:58 am, Christopher Barker wrote: if you want to call your collection of files a single resource, then sure -- but then it's not the directory that's the resource, it's the collection of files that's the resource Sure, but why am I not allowed to use the name of the directory as

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-16 Thread Christopher Barker
On Mon, May 16, 2022 at 7:38 AM Greg Werbin wrote: > Non-"binary" resources are already in widespread use, I didn't write the docs -- but a text file is, indeed a binary blob -- it only becomes text when it is read and decoded, so there is no distinction at this level. I *think* the idea

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-16 Thread Christopher Barker
On Sun, May 15, 2022 at 11:57 PM Greg Ewing wrote: > On 16/05/22 5:05 pm, Christopher Barker wrote: > > a directory is not a binary artifact -- it can't have actually data in > > it like a file can. > > and: > > > the entire > > point of resources is to provide an abstraction -- the individual >

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-16 Thread Greg Werbin
Non-"binary" resources are already in widespread use, so perhaps that requirement shouldn't be in the docs at all. In practice, a resource is "any data file other than a Python source file." Moreover, I see no reason why a resource name in general shouldn't be allowed to contain a "/"

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-16 Thread Greg Ewing
On 16/05/22 5:05 pm, Christopher Barker wrote: a directory is not a binary artifact -- it can't have actually data in it like a file can. and: the entire point of resources is to provide an abstraction -- the individual resources may not be files on disk at all These two statements are

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-15 Thread Christopher Barker
I honestly wasn't aware that this was added in 3.7 -- I always thought handling resources was up to setuptools or hand-written code. So it's nice to see that it's there in the stdlib. And while I haven't actually used this feature, I have read through the docs and have a few comments. On Sun, May

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-15 Thread Greg Werbin
I think this is a bit of an "XY" feature request. Currently, resources must be individual files inside a package. A directory cannot itself be a "resource". So for example if you have a directory structure like this: my_great_app/ __init__.py something.py data/

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-15 Thread Ray Chen
How would I go about doing it myself then? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-15 Thread Ray Chen
An example is when an API asks for a folder that contains a set of images, and reads each image one by one. Having a folder is also useful for globbing and selecting certain files. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe

[Python-ideas] Re: `importlib.resources` access whole directories as resources

2022-05-09 Thread Filipe Laíns
On Sun, 2022-05-08 at 17:36 +, tankimarsh...@gmail.com wrote: > An `importlib.resources.as_file` equivalent but for whole directories. > > To access a directory of files in a package and load them (for example, a > skybox with 6 faces), one would need to use `as_file` 6 times with 6 context >