bamos / cv

http://bamos.github.io
MIT License
402 stars 144 forks source link

jinja2.exceptions.TemplateNotFound: sections\education.tex (On Windows?) #11

Closed rlabrecque closed 9 years ago

rlabrecque commented 9 years ago

I'm looking into this cv project for myself, but it doesn't seem to work out of the box, at least on windows.

I end up with this:

D:\Riley\Desktop\cv-master>generate.py -p cv.yaml
  + Processing section: interests
  + Processing section: education
Traceback (most recent call last):
  File "D:\Riley\Desktop\cv-master\generate.py", line 289, in <module>
    main()
  File "D:\Riley\Desktop\cv-master\generate.py", line 284, in main
    process_resume(LATEX_CONTEXT, yaml_data, args.preview)
  File "D:\Riley\Desktop\cv-master\generate.py", line 251, in process_resume
    rendered_resume = context.render_resume(yaml_data)
  File "D:\Riley\Desktop\cv-master\generate.py", line 199, in render_resume
    section_template_name, section_data)
  File "D:\Riley\Desktop\cv-master\generate.py", line 150, in _render_template
    return self._jinja_env.get_template(template_name).render(yaml_data)
  File "C:\Python34\lib\site-packages\jinja2\environment.py", line 791, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "C:\Python34\lib\site-packages\jinja2\environment.py", line 765, in _load_template
    template = self.loader.load(self, name, globals)
  File "C:\Python34\lib\site-packages\jinja2\loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "C:\Python34\lib\site-packages\jinja2\loaders.py", line 160, in get_source
    pieces = split_template_path(template)
  File "C:\Python34\lib\site-packages\jinja2\loaders.py", line 31, in split_template_path
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: sections\education.tex

Any chance that I'm doing something wrong? All I did was clone, pip3 install -r requirements.txt, generate.py cv.yaml

bamos commented 9 years ago

Hi @rlabrecque - thanks for the report.

The code is written to be cross-platform, but I've never tested in Windows before. I think this is a subtle bug with the jinja templates. I'll debug on a Windows machine today or tomorrow.

Afterwards, I'd like to set up Linux and Windows CI so this won't be problem in the future. I've filed https://github.com/bamos/cv/issues/12 for this.

bamos commented 9 years ago

Hi @rlabrecque - can you pull the latest code and try again? I think I've fixed the problem, caused by how Jinja's FileSystemLoader handles paths in Windows.

rlabrecque commented 9 years ago

Yep, It's all good now! Thanks!

bamos commented 9 years ago

\cc @emichael

emichael commented 9 years ago

Huh, I don't quite understand what the problem was, and I'm curious. Did he have a folder/file with a forward slash in the path?

bamos commented 9 years ago

@emichael - in windows, generate.py will create a string like sections\education.tex (with backslashes from os.path.sep) to retrieve and render a template with self._jinja_env.get_template. I don't understand why, but Jinja's get_template method expects the path to be separated with forward slashes, even in Windows.

This seems to be a problem in other projects too: https://github.com/mrobb/complexity/commit/912ca3ac2fa97deb427d529a452c805903f686d2

emichael commented 9 years ago

Ugh. And I thought religious use of os.path.join would prevent such nonsense...