-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faulty handling of UNC paths #1675
Comments
Please provide an example using Jinja. It seems like you've extracted some code from Jinja, but have also mixed it with your own code, and it's hard for me to follow what part of Jinja the issue is coming from with that.
Thanks, I'm well aware of pathlib. I've already evaluated using it in the code you're showing. It did not help, and occasionally made the implementation more complicated.
This seems like obviously a bad idea. If |
Also note that we have to join using |
Hello David! Thanks for your feedback. I'm aware I was a bit vague, it was a long and warm day yesterday. I'll dig further into it today and hopefully be able to provide a full example. |
Just a short update: It's not trivial to reproduce in isolation. The reason is that If I understand the intentions correctly, the Jinja template is specified using a notation similar to a POSIX path. In loaders.py, in
Can you elaborate, perhaps give some examples? It's unfortunately not obvious to me... |
If the template name I know there's a similar issue with (non-literal) UNC paths, but I can't remember an example of that one. So instead, Jinja joins using |
I see, didn't expect that semantic of joining two absolute paths. For some reason, Still, it can conveniently solve the task:
|
Happy to review a PR. |
Heya! :) There is https://github.com/UlrichEckhardt/jinja/releases/tag/jfrog-dev1 as a preview. I need to do some more testing due to the complicated software stack here, but it seems to have fixed the issue. I'll clean this up when I find time, probably next week rather, and file a proper PR then. I'd appreciate if you could take a look, just to say if this is heading the right direction. |
I have run into this bug when trying to convert a setuptools project to a maturin (rust) project. My python code uses jinja2's I suspect (but haven't proven) that maturin uses rust standard library code that returns UNC paths: rust-lang/rust#42869 |
I've also run into this when using Buck2 which is built in Rust. As a workaround I ended up just using |
I have a case where Jinja doesn't find a template which is loaded using the
PackageLoader("gcovr")
.For reference, see https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd:
Using the "\\?\" prefix is desirable in general, because it lifts a few limits, in particular one on the length of the path.
I haven't gotten to the state where I can present a simple example. My setup is a bit stacked, Jenkins running a job in Kubernetes on Windows, there using Bazel to invoke gcovr to generate a coverage report from some C/C++ binaries compiled with MinGW. What I found there was that Jinja fails to load a style.css file, which is totally there. What I ended up with was that I copied bits'n'pieces from loader.py in order to debug them on that stack in the most crude
print()
way you can imagine. It's not pretty.Still, here's the code from gcovr, which shows how Jinja is integrated:
And a bit of code that comes from
split_template_path()
andclass PackageLoader
:Locally (running Ubuntu), it works and it doesn't enter the "altsep" path of course. On Windows, it produces this output though:
I believe that converting the string-based and rather manual path handling could be improved by using the Python pathlib. I have only gotten to use it recently, but I'm fully convinced that it's a huge step ahead in reliability and readability of code handling paths. As a quick workaround, see the above, i.e. replacing
os.path.altsep
withos.path.sep
in the paths.Environment:
The text was updated successfully, but these errors were encountered: