Skip to content
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

FileSystemLoader doesn't work with Windows paths (backslashes) #767

Closed
FreddieChopin opened this Issue Sep 7, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@FreddieChopin
Copy link

FreddieChopin commented Sep 7, 2017

Expected Behavior

On Windows FileSystemLoader should allow both Windows-style (with \) and UNIX-style (with /) paths.

Actual Behavior

On Windows, when using FileSystemLoader the following fails:
jinjaEnvironment.get_template('.\source\architecture\ARM\ARMv6-M-ARMv7-M\bo ardTemplates\ARMv6-M-ARMv7-M.metadata')
with
jinja2.exceptions.TemplateNotFound: .\source\architecture\ARM\ARMv6-M-ARMv7-M\bo ardTemplates\ARMv6-M-ARMv7-M.metadata

while this jinjaEnvironment.get_template('.\source\architecture\ARM\ARMv6-M-ARMv7-M\bo ardTemplates\ARMv6-M-ARMv7-M.metadata'.replace('\\', '/')) works perfectly fine.

Full Traceback

Traceback (most recent call last):
  File "./scripts/generateBoard.py", line 186, in <module>
    metadata = jinjaEnvironment.get_template(metadataFile).render(dictionary = d
ictionary)
  File "C:\Python27\lib\site-packages\jinja2\environment.py", line 830, in get_t
emplate
    return self._load_template(name, self.make_globals(globals))
  File "C:\Python27\lib\site-packages\jinja2\environment.py", line 804, in _load
_template
    template = self.loader.load(self, name, globals)
  File "C:\Python27\lib\site-packages\jinja2\loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "C:\Python27\lib\site-packages\jinja2\loaders.py", line 168, in get_sourc
e
    pieces = split_template_path(template)
  File "C:\Python27\lib\site-packages\jinja2\loaders.py", line 31, in split_temp
late_path
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: .\source\architecture\ARM\ARMv6-M-ARMv7-M\bo
ardTemplates\ARMv6-M-ARMv7-M.metadata

Your Environment

  • Python version: 2.7.12
  • Jinja version: 2.9.6
@ThiefMaster

This comment has been minimized.

Copy link
Member

ThiefMaster commented Sep 7, 2017

Jinja template names are not fileystem paths (even though they map to filesystem paths when using just a FileSystemLoader). They always use forward slashes so this is working as intended.

@ThiefMaster ThiefMaster closed this Sep 7, 2017

@FreddieChopin

This comment has been minimized.

Copy link
Author

FreddieChopin commented Sep 7, 2017

I think this information should be explicitly stated in the documentation with bold font if you don't intend to fix it. It's not that I have purposefully used backslashes - when generating the filename using some other python code (for example by searching the folders for appropriate extensions), the string has system's native slashes (so backslashes on Windows). In that case you have to explicitly replace the slashes...

BTW - I'm not using Windows, but I'm writing a script which should work on all platforms.

FreddieChopin pushed a commit to DISTORTEC/distortos that referenced this issue Sep 7, 2017

Fix generateBoard.py's behaviour for Windows
The fixes are related to the fact that both jinja (
pallets/jinja#767 ) and templates expect
forward slashes only.
1. Use posixpath instead of os.path
2. Replace all backslashes with slashes in current folder returned by
os.walk()

caseycesari added a commit to CoastalResilienceNetwork/GeositeFramework that referenced this issue Oct 15, 2018

caseycesari added a commit to CoastalResilienceNetwork/GeositeFramework that referenced this issue Oct 16, 2018

caseycesari added a commit to CoastalResilienceNetwork/GeositeFramework that referenced this issue Oct 22, 2018

@gotexis

This comment has been minimized.

Copy link

gotexis commented Mar 29, 2019

@FreddieChopin
Is this one fixed? seems still affecting me in 2019.

What I have to do is to manually replace all \\ to /.

@FreddieChopin

This comment has been minimized.

Copy link
Author

FreddieChopin commented Mar 29, 2019

Is this one fixed?

"It is not a bug - it's a feature!" (;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.