Open afparsons opened 3 years ago
Would be awesome, if this could be included in a pypi release, 'cause it would be the same for WindowsPath
.
For now, the docs on the sys module say that sys.path
should only contain strings:
A program is free to modify this list for its own purposes. Only strings should be added to sys.path; all other data types are ignored during import.
So I think the right thing to do in entrypoints is to just ignore pathlib objects, rather than converting them to [edit: string] paths.
I should also make it clear that entry points are now supported in the Python standard library, by the importlib.metadata
module, so this package is no longer all that important. But I'm happy to merge a fix if people are still using it.
iter_files_distros(path=None, repeated_distro='first')
will fail if one of the elements insys.path
is not a string. For example, mysys.path
contained aPosixPath
:PosixPath
objects do not implement anrstrip()
method, and so the following happens [permalink]:I'll defer to someone with far more Python experience than I have to decide whether this is just a silly user error (i.e. entirely my fault), or something that should be handled within
iter_files_distros(...)
.Maybe it seems absurd that anything other than a string would find its way into
sys.path
, but for newcomers to Python (i.e. me, since ~3.5) who have grown up with pathlib, it doesn't feel too out of place. In fact, here's a PR.For search engines and passers-by:
I had encountered this stacktrace in my Django + Dagster + MLflow + Gensim + Docker project:
It took me a while to find the cause.
My
BASE_DIR
in Django'ssettings.py
was a pathlibPath
object:For whatever reason, I had to append
BASE_DIR
tosys.path
from within a Dagster solid:This resulted in a
PosixPath
object being added tosys.path
. As explained above,sys.path
is expected presently to hold only strings, and soiter_files_distros(path=None)
will just callrstrip(...)
on each element without type consideration.A solution is ensure that a string is appended to
sys.path
: