python-holidays icon indicating copy to clipboard operation
python-holidays copied to clipboard

L10n howto for Windows based contributors

Open arkid15r opened this issue 2 years ago • 12 comments

I am thinking of contributing Italian names for Italian holidays and am following this thread closely. I too am on Windows but don't know the technology/library used here, and am a bit worried as I don't really want to install WSL2. Also worrisome is the lack of support for UTF-8 (based on the error reported above) as it's required for Italian.

As the author of #827 and the make file that doesn't seem to work on Windows, do you have any input on where I should look to be able to contribute a Windows-native solution?

Originally posted by @mborsetti in https://github.com/dr-prodigy/python-holidays/issues/946#issuecomment-1432731177

arkid15r avatar Feb 16 '23 17:02 arkid15r

Here's one of the placeholder methods until we get this working natively on Windows (not ideal, but it works for now).

  • Enable "Windows Subsystem for Linux" (WSL2)
    • wsl --install, select your repo of choice (I picked Ubuntu 22.04 LTS for this case)
    • After setting everything up, wsl ~ to enter WSL
  • Installing additional packages:
    • sudo apt update && sudo apt upgrade -y to update Linux distro.
    • sudo apt install gettext -y needed for localisation.
  • cd to the installed location: cd /mnt/[drive no]/[whatever folders]/python-holidays
  • Check echo $PYTHONPATH; if this is not set yet, run export PYTHONPATH=/mnt/[drive no]/[whatever folders]/python-holidays
  • Installing additional python requirements: pip install --requirement requirements/dev.txt
  • Creating the following files and folders (either in Windows Explorer's GUI or mkdir in the command line):
    • holidays/locale/pot
    • holidays/locale/[new_language_code]/LC_MESSAGES/[new_language_code].po ← (if new translation files, both for the new languages and in the English folder)
  • You should now be able to run make l10n

Edit: For countries with non-ASCII holiday names, instead of merely blank files you'll need to add header to the file itself to get the code working, here's an example:

# CountryName holidays English translation.
# Authors: AuthorName <[email protected]>, (c) 2023.
#
msgid ""
msgstr ""
"Project-Id-Version: Python Holidays 0.20\n"
"POT-Creation-Date:\n"
"PO-Revision-Date: \n"
"Last-Translator: AuthorName <[email protected]>\n"
"Language-Team: Python Holidays localization team\n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

PPsyrius avatar Feb 19 '23 05:02 PPsyrius

Respectfully, this is not a recipe on how to enable contributions from the Windows community (~50+% of computers). It's one for installing a brand new operating system chewing up over ~5GB of space, which is a huge ask!!

I think we can do better; most open source projects I am aware of are cross-platform compatible.

mborsetti avatar Apr 12 '23 23:04 mborsetti

As the author of #827 and the make file that doesn't seem to work on Windows, do you have any input on where I should look to be able to contribute a Windows-native solution?

Hi, I encountered the same error while setting up the project, so I made general modifications to the Makefile. This change will not cause errors on Linux machines during execution. Should I create a pull request?

Prateekshit73 avatar Feb 07 '25 18:02 Prateekshit73

@Prateekshit73 I'm not sure if that solves the original Windows-related problem but yeah go ahead and create a PR!

arkid15r avatar Feb 07 '25 18:02 arkid15r

@Prateekshit73 I'm not sure if that solves the original Windows-related problem but yeah go ahead and create a PR!

Is this the original Windows-related problem you are referring to:-

make[1]: *** [Makefile:60: pre-commit] Error 1
make[1]: Leaving directory 'vacanza_holidays'
make: *** [Makefile:32: check] Error 2

Prateekshit73 avatar Feb 08 '25 06:02 Prateekshit73

I think the cause of error is line endings:

  • Linux uses LF (Line Feed, \n) as the line ending.
  • Windows uses CRLF (Carriage Return + Line Feed, \r\n).

Prateekshit73 avatar Feb 08 '25 07:02 Prateekshit73

@Prateekshit73 I'm not sure if that solves the original Windows-related problem but yeah go ahead and create a PR!

Is this the original Windows-related problem you are referring to:-

make[1]: *** [Makefile:60: pre-commit] Error 1
make[1]: Leaving directory 'vacanza_holidays'
make: *** [Makefile:32: check] Error 2

I'm not sure how it looks like specifically. The problem is that make command is not a part of Windows out of the box and you need to install WSL for that. From my perspective it's not really a blocker for contributing to holidays as a Makefile is just a way to group multiple commands into a single command in our case.

We still want to make the contribution process easier for Windows users if possible.

arkid15r avatar Feb 08 '25 07:02 arkid15r

Thank you for your feedback! To verify the issue, I spun up a Windows VM and ran the command. As I mentioned earlier, it seems that the problem is related to the line endings. I’ll look into this further to ensure compatibility for Windows users. If you have any suggestions on how to address this, I’d appreciate your input!

Prateekshit73 avatar Feb 08 '25 08:02 Prateekshit73

Still, the issue persists when we try to push with git push without the --no-verify flag, as it automatically falls back to the Makefile supported by Linux.


run `make check`.........................................................Failed
- hook id: tests
- exit code: 2

make l10n
make[1]: Entering directory 'vacanza_holidays'
scripts/l10n/generate_po_files.py >/dev/null 2>&1
make[1]: *** [Makefile:36: l10n] Error 49
make[1]: Leaving directory 'vacanza_holidays'
make: *** [Makefile:15: check] Error 2

Prateekshit73 avatar Feb 13 '25 16:02 Prateekshit73

That's strange. Make.cmd in the current folder should take priority over Make located somewhere in the PATH.

KJhellico avatar Feb 13 '25 21:02 KJhellico

Hi @KJhellico,

The problem still persists as I mentioned earlier. Even with Make.cmd in the current folder, it doesn’t seem to take priority over the Linux-style Make in the PATH when running commands like git push without the --no-verify flag. It continues to fall back to the Makefile designed for Linux, resulting in errors like:

run `make check`.........................................................Failed
- hook id: tests
- exit code: 2

make l10n
make[1]: Entering directory 'vacanza_holidays'
scripts/l10n/generate_po_files.py >/dev/null 2>&1
make[1]: *** [Makefile:36: l10n] Error 49
make[1]: Leaving directory 'vacanza_holidays'
make: *** [Makefile:15: check] Error 2

I’ve tested this on Windows. Do you have any thoughts on how to ensure Make.cmd is prioritized or other ways to resolve this for Windows users?

Prateekshit73 avatar Mar 17 '25 16:03 Prateekshit73

Yes, git runs its hooks through bash (Cygwin), so it doesn't consider make.cmd.

Try specifying python for .py scripts in Makefile explicitly (i.e. python scripts/l10n/generate_po_files.py ...

KJhellico avatar Mar 17 '25 17:03 KJhellico