jhauberg / cards.py

Generate Print-and-Play cards for your board games
MIT License
35 stars 7 forks source link

Invalid format string ValueError in W10 #159

Open AunSiro opened 6 years ago

AunSiro commented 6 years ago

Hello,

I am using Python 3.5.2 through Anaconda on Windows 10. I have installed the module and its dependencies as the readme states. Then, I tried to execute the example: \example\love-letter> cards make cards.csv but it failed after creating a new folder called "generated" with an empty html named "index.html". I obtained the following error message:

Generating cards from 1 datasource:
 ['cards.csv']

[-] [cards.csv] Card backs will not be generated since the '@template-back' column has not been set
Traceback (most recent call last):
  File "C:\Anaconda3\Scripts\cards-script.py", line 11, in <module>
    load_entry_point('cards.py==0.6.5', 'console_scripts', 'cards')()
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\__main__.py", line 127, in main
    clean)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\cards.py", line 1039, in make
    index, styles, pages, header, pages_total, cards_total, definitions)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\template.py", line 661, in fill_index
    fill_date_fields(template)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\template.py", line 369, in fill_date_fields
    formatted_date = date.strftime(date_format)
ValueError: Invalid format string

I obtained similar looking errors for the templated example:

\example\love-letter-templated>  cards make cards.cs
v
Generating cards from 1 datasource:
 ['cards.csv']

[-] [cards.csv] Card backs will not be generated since the '@template-back' column has not been set
Traceback (most recent call last):
  File "C:\Anaconda3\Scripts\cards-script.py", line 11, in <module>
    load_entry_point('cards.py==0.6.5', 'console_scripts', 'cards')()
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\__main__.py", line 127, in main
    clean)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\cards.py", line 839, in make
    card, size_class=card_size.style, content=card_content)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\cards.py", line 151, in get_sized_card
    fill_each(TemplateFields.CARD_CONTENT, content, template, indenting=True)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\template.py", line 331, in fill_each
    template.content, occurences = search.subn(field_value, template.content)
  File "C:\Anaconda3\lib\re.py", line 325, in _subx
    template = _compile_repl(template, pattern)
  File "C:\Anaconda3\lib\re.py", line 312, in _compile_repl
    p = sre_parse.parse_template(repl, pattern)
  File "C:\Anaconda3\lib\sre_parse.py", line 872, in parse_template
    raise s.error("missing <")
sre_constants.error: missing < at position 101 (line 2, column 73)

And also for the Dungeon deck master:

\dungeon-deck-master\src> cards make cards.csv
Generating cards from 1 datasource:
 ['cards.csv']

[-] No definitions have been specified; using definitions automatically found at: 'definitions.csv'
[-] [cards.csv] Card backs will be generated since the '@template-back' column has been set (you can disable card backs by specifying the --disable-backs option)
[!] [cards.csv:#2] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#2] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#3] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#3] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#4] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#4] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#5] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#5] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#6] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#6] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#7] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#7] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#8] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#8] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#9] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#9] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#10] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#10] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#11] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#11] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#12] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#12] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#13] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#13] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#14] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#14] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#15] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#15] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#16] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#16] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#17] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#17] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#18] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#18] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#19] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#19] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#20] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#20] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#21] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#21] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#22] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#22] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#23] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#23] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#24] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#24] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#25] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#25] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#26] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#26] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#27] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#27] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#28] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#28] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#29] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#29] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#30] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#30] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#31] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#31] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#32] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#32] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#33] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#33] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#34] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#34] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#35] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#35] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#36] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#36] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#37] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#37] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#38] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#38] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#39] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#39] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#40] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#40] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#41] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#41] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#42] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#42] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#43] The card provided a template that could not be opened: '{{ path_dungeon-template }}' (2 cards)
[!] [cards.csv:#43] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}' (2 cards)
[!] [cards.csv:#44] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#44] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#45] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#45] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#46] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#46] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#47] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#47] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#48] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#48] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#49] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#49] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#50] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#50] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
[!] [cards.csv:#51] The card provided a template that could not be opened: '{{ path_dungeon-template }}'
[!] [cards.csv:#51] The card provided a back template that could not be opened: '{{ path_dungeon-template-back }}'
Traceback (most recent call last):
  File "C:\Anaconda3\Scripts\cards-script.py", line 11, in <module>
    load_entry_point('cards.py==0.6.5', 'console_scripts', 'cards')()
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\__main__.py", line 127, in main
    clean)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\cards.py", line 1039, in make
    index, styles, pages, header, pages_total, cards_total, definitions)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\template.py", line 661, in fill_index
    fill_date_fields(template)
  File "C:\Anaconda3\lib\site-packages\cards.py-0.6.5-py3.5.egg\cards\template.py", line 369, in fill_date_fields
    formatted_date = date.strftime(date_format)
ValueError: Invalid format string
jhauberg commented 6 years ago

Interesting. I've never heard of Anaconda, but have run this successfully on Windows 10 previously (a while ago, admittedly).

I'll take a look.

EDIT: I can confirm that this happens on my Windows machine as well. Looking into fixing this right away :)

jhauberg commented 6 years ago

So I've opened up this can of worms, and it turns out that there was actually quite a few compatibility problems. Not only on Windows, but also on Python versions pre-3.6.

Starting with https://github.com/jhauberg/cards.py/commit/8b867f680ad9e354ae8ea2a199715d95a391488d I've fixed a few of them, but there's still at least one big issue remaining.

On Windows, something is causing all image URLs to use backslashes instead of the expected normal slashes; e.g. path\to\image.svg instead of path/to/image.svg, which has a nasty side-effect that causes the regex engine to fail parsing some content, leading to the sre_constants.error: missing < at position 101 (line 2, column 73) error that you're seeing.

The error can be consistently reproduced with the love-letter-templated example, because one of the cards use a particular image with a path that, as noted above, incorrectly ends up being art\guard.png, which interestingly enough now contains a regex meta specifier (\g); however, that specifier is invalid and should be something like \g<1>- which is why the error says missing <.

So once I get the pathing right, the project should be back in fighting shape.

Thanks a lot for letting me know! I don't use Windows frequently enough to discover these issues when adding new stuff.