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

Invalid character in Windows template filenames #1

Closed
grovduck opened this issue Dec 2, 2021 · 9 comments · Fixed by #2 or #4
Closed

Invalid character in Windows template filenames #1

grovduck opened this issue Dec 2, 2021 · 9 comments · Fixed by #2 or #4
Assignees

Comments

@grovduck
Copy link

grovduck commented Dec 2, 2021

Great idea and really cool tutorial - thanks so much for this.

When I try to use this template on Windows using copier, I'm getting the following error:

C:\Users\gregorma\Desktop>copier gh:gahjelle/template-aoc-python foo2
Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\gregorma\.local\bin\copier.exe\__main__.py", line 7, in <module>
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\cli\application.py", line 629, in run
    inst, retcode = subapp.run(argv, exit=False)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\cli\application.py", line 624, in run
    retcode = inst.main(*tailargs)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\copier\cli.py", line 38, in _wrapper
    return method(*args, **kwargs)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\copier\cli.py", line 252, in main
    self.parent._copy(template_src, destination_path)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\copier\cli.py", line 173, in _copy
    return copy(
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\copier\main.py", line 133, in copy
    conf = make_config(**locals())
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\copier\config\factory.py", line 96, in make_config
    src_path = vcs.clone(repo, vcs_ref or "HEAD")
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\copier\vcs.py", line 92, in clone
    git("checkout", ref)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\commands\base.py", line 99, in __call__
    return self.run(args, **kwargs)[1]
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\commands\base.py", line 240, in run
    return p.run()
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\commands\base.py", line 201, in runner
    return run_proc(p, retcode, timeout)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\commands\processes.py", line 322, in run_proc
    return _check_process(proc, retcode, timeout, stdout, stderr)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\commands\processes.py", line 24, in _check_process
    proc.verify(retcode, timeout, stdout, stderr)
  File "C:\Users\gregorma\.local\pipx\venvs\copier\lib\site-packages\plumbum\machines\base.py", line 28, in verify
    raise ProcessExecutionError(
plumbum.commands.processes.ProcessExecutionError: Unexpected exit code: 1
Command line: | 'C:\Program Files\Git\cmd\git.exe' checkout HEAD
Stderr:       | error: invalid path 'src/[[year]]/[[puzzle_dir]]/aoc[[year]][['%02d'|format(day)]].py.tmpl'
              | error: invalid path 'src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][['%02d'|format(day)]].py.tmpl'

From what I can tell, it doesn't accept the pipe character as a valid character in a Windows filename (although I'm not totally sure of this). If I replace [['%02d'|format(day)]] with [[formatted_day]] and put an entry for [[formatted_day]] in the copier.yml file, it seems to work fine. Here's an example of that: https://github.com/grovduck/test-template.

Please let me know if I'm doing something incorrectly - it's my first time using copier!

@gahjelle
Copy link
Owner

gahjelle commented Dec 2, 2021

@grovduck Thanks a lot for reporting this, and for figuring out the issue. I don't have a ton of experience with Copier myself, and I've apparently not tested it on Windows at all 🙈

I have a proposed fix in #2. Are you able to run a quick check on whether it resolves the issue? You can test it by running:

C:\Users\gregorma\Desktop>copier gh:gahjelle/template-aoc-python -r bugfix/support-windows-filenames foo2

If this works as it should, I'll deploy it ASAP 😊

@grovduck
Copy link
Author

grovduck commented Dec 2, 2021

@gahjelle Thanks for the very quick fix. I can confirm that this command worked for me:

copier gh:gahjelle/template-aoc-python -r bugfix/support-windows-filenames foo2

I struggled for a bit to get the bash shell script to work and had to do two different things (in case this helps others).

  1. Using git bash, I had to activate my virtual environment using this tip from Presh Onyee. (I have advent-of-code-data and other packages you recommend installed in a virtualenv
  2. I had to add a command line -d flag for puzzle_dir as well (i.e. -d puzzle_dir=$day), otherwise I was getting a UnicodeEncodeError.

Here was the Bash script that worked for me:

  for day in {01..25}; do
    copier gh:gahjelle/template-aoc-python -r bugfix/support-windows-filenames -d year=2021 -d day=$day -d puzzle_name="" -d puzzle_dir=$day foo2/
  done

Finally, I was able to do the same thing using PowerShell using this command:

  for ($day = 1; $day -le 25; $day++) {
    $day_str = "{0:00}" -f $day
    copier gh:gahjelle/template-aoc-python -r bugfix/support-windows-filenames -d year=2021 -d day=$day_str -d puzzle_name="" -d puzzle_dir=$day_str foo2/
  }

Thanks so much for your help. Now to actually start on the puzzles! Please feel free to close the issue.

@psycho-baller
Copy link

psycho-baller commented Dec 3, 2021

THANK YOUUUU SOOO MUCHHH!! @grovduck

I've been stuck on this error since yesterday. True example of 'not all heroes wear capes'

@gahjelle
Copy link
Owner

gahjelle commented Dec 3, 2021

Thank you again, @grovduck , I wholeheartedly agree with @psycho-baller . I have added your tips to the README as well, so that they will be easier to find for other Windows users.

Happy Advent of Coding!

@grovduck
Copy link
Author

grovduck commented Dec 3, 2021

@gahjelle @psycho-baller Y'all are much too kind. A tiny contribution to what @gahjelle has done here!

@grovduck
Copy link
Author

grovduck commented Dec 2, 2022

Hi again @gahjelle! I'm using your awesome template generator again this year, but it looks like recent pushes may have reintroduced pipe characters ("|") into these filenames which is causing issues on Windows again:

aoc{{year}}{{'%02d'|format(day)}}.py.jinja
test_aoc{{year}}{{'%02d'|format(day)}}.py.jinja.

I was able to get around it by renaming these files to:

aoc{{year}}{{'%02d' % day}}.py.jinja
test_aoc{{year}}{{'%02d' % day}}.py.jinja

Note that using '%02d'|format(day) within the files themselves causes no issues, only the filenames themselves. I haven't tested on any *nix systems, so I'll leave it to you if you want to make this change (hence, no new issue for this!)

@gahjelle
Copy link
Owner

gahjelle commented Dec 2, 2022

Ah, yes, they changed the templating engine in the latest version of Copier, so I had to change the names and I forgot about pipes on windows.
I'll try to have a look at it tomorrow, I'd be happy to find something that works on all systems.
Thanks for the heads up!

@gahjelle gahjelle self-assigned this Dec 2, 2022
@gahjelle gahjelle reopened this Dec 2, 2022
@gahjelle
Copy link
Owner

gahjelle commented Dec 5, 2022

Thanks again @grovduck

The filenames have been updated, so it should work again now. Thanks again for letting me know!

@grovduck
Copy link
Author

grovduck commented Dec 5, 2022

Thanks @gahjelle, looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants