Closed VolkerH closed 1 year ago
+1, there should be a way to get the Pathlib Path without joinpath anyways.
Also, a workaround for now:
print((files(spacem_maldi.Ontologies) / "fakefilename.txt").parent)
there should be a way to get the Pathlib Path without joinpath anyways
Yes, I felt that / "."
was a crutch to start with but couln't find a better (proper) way.
Oh, you shouldn't rely on joinpath
to get a materialized path. If what you need is a materialized path on the file system, use as_file(traversable)
. files()
returns a Traversable and Traversable.joinpath
also returns a Traversable, which may or may not be on the filesystem. Although depending on your usage, you may not need to materialize the traversable at all and you may be able to get the value directly from the Traversable (such as with .open
or .read_text()
).
Still, you shouldn't get a StopIteration
by attempting to join a path.
I'm unable to replicate the issue:
>>> import importlib_resources as resources
>>> print(resources.files('importlib_resources') / ".")
/Users/jaraco/code/python/importlib_resources/importlib_resources
What's special about spacem_maldi.Ontologies
that triggers the issue?
I thought maybe the issue was that Ontologies
was a directory without an __init__
, but I'm still unable to trigger the failure:
>>> import pathlib
>>> pathlib.Path('importlib_resources/foo').mkdir()
>>> print(resources.files('importlib_resources.foo') / ".")
/Users/jaraco/code/python/importlib_resources/importlib_resources/foo
Since the issue isn't reproducible, I'm closing it, but feel free to follow-up with the requested info and we can investigate further.
Consider the following code snippet:
stopiteration_bug.py
:With
importlib-resources<=5.7.1
this produces the following output:Starting from version
5.8.0
, i.e. after PR #250 this throws aStopIteration
exception:The
spacem_maldi
package is a private package, but I don't think that is relevant here. If needed I can try and create a minimal public package.