[py-dev] py.path.embed patch
Matthew Scott
mscott at goldenspud.com
Sat Jan 29 01:07:35 CET 2005
holger krekel wrote:
>
> thanks for the patch, first of all. i couldn't yet look more
> carefully into your patch but i am wondering why you didn't
> just provide the virtual path based on dictionaries so that
> you can use py.path.local and py.path.dict (or some such)
> quite interchangeably?
>
Well, I had originally considered that, but I realized that what I
mainly wanted was a way to have a self-contained "sandbox" of files.
That sandbox could either be based on a local path, or embedded into a
Python module (or even a pickle, or whatever) as a dictionary.
Then, the code using those sandboxes would initialize them based on what
was available (either a local path or a dictionary) and after that, not
care whether the files were on disk or in a dictionary.
The use of a "context" also allows virtual chdir() operations to occur.
That means you can do the following:
>>> import py
>>> ctx = py.path.embed.virtualContext()
>>> path = py.path.embed(context=ctx)
>>> print repr(path)
embed('/', virtual(406cddfc))
>>> subdir = path.join('foo').ensure(dir=True)
>>> subdir.chdir()
>>> path2 = py.path.embed(context=ctx)
>>> print repr(path2)
embed('/foo', virtual(406cddfc))
> On a side note i believe that py.path.extpy uses some "embed" similar
> ideas to represent files/hierarchies from within python modules
> offering a filesystem-path like interface. Generally i think
> the virtualization idea is worthwhile to integrate but i am not
> sure yet how it bests fits in and it's obviously good to
> avoid code duplication.
Hmm...
Perhaps the "local context" in my code could be refactored into some
sort of "sandbox" path class that can use *any* path object as its
"context" or "virtual root".
That would satisfy my desire to take a py.path.local object pointing to
a directory, then use that as the root of a sandbox of files that I want
to manage.
I may look at py.path.extpy and see how it works. I think it might make
sense in this case to use a simpler dictionary-based virtual filesystem.
But then we have the conundrum that I solved with the concept of
contexts in py.path.embed - what is the "root" of that virtual
filesystem? Some sort of top-level object would still be needed to
allow navigation through parents of virtual paths.
Well those are my ramblings for now. :) I may charge forward with
using py.path.embed but I think its actual use will be simple enough
that if we decide to use some other techniques to accomplish the same
thing, it won't be a problem at all to refactor.
And speaking of paths, contexts, and virtual filesystems... Schevo has
some support for ZIP files for loading icons. py.path.zip?? :)
- Matthew
More information about the Pytest-dev
mailing list