cs50 / lib50

This is lib50, CS50's own internal library used in many of its tools.
GNU General Public License v3.0
16 stars 15 forks source link

Windows Support for lib50 #79

Closed Sashank999 closed 3 weeks ago

Sashank999 commented 2 months ago

I'm a Windows user. I personally don't like using codespaces because my internet connection is unstable and having a cloud instance running seems like an overkill for me.

This PR does a lot of stuff but some highlights are:

  1. Use pexpect.popen_spawn.PopenSpawn class directly instead of pexpect.spawn. (76f1c92947ef171c42badecbc3fc55b37f28b911)
    • pexpect.spawn is not available on Windows as pseudo terminals are not available, which the pexpect library uses.
    • Also, the commit name is misleading. I later removed the psutil and replaced with the Popen.poll from Python which is in proc attribute of PopenSpawn.
  2. Exit testing temporary directory before removing it. (b7b6453082541f89a81bed6fe3dd5035ce1805a6)
    • This is not needed on Linux but very important on Windows.
  3. Fix logging colors. (e282e43ea4cffa97c788bd3c984a9eb6a9ab184e and bddcf26ea4dd84861550f2c3081a8199e095d599)
    • Windows console is not good with ANSI escape sequences for colors. I added the colorama package as a Windows-only dependency.
  4. Disable output echo on Windows for GitHub personal access token entry. (10cd79612af79b4b5062d0f92650146041374ece)
    • This is a workaround. A reference to the source is mentioned in the file and the commit messages https://stackoverflow.com/a/9218551 .
    • It uses the ctypes package and calls Windows API functions which are already available.
  5. Quoting arguments on Windows cmd is different. Added oslex dependency for it. (33aac2e736d843bee70423d83188324dd3286164 and bddcf26ea4dd84861550f2c3081a8199e095d599)
  6. The test for invalid UTF-8 filenames is skipped. (55d26a3061ecfe53f3d7b8fd7e10675c588dadfd)
    • For some reason, Python takes the invalid byte stream and decodes it on Windows instead of opening the file directly(as on Linux). This is the only actual change in tests.
  7. Windows does not have Unix sockets and hence the default git config credential.helper=cache does not work. Added support for the GCM Core credential manager on Windows along with regex for parsing its output. (fae9f04b4bc455b8f217e6b547f964df9227a4ee)

All the tests run fine on both Windows and Linux (except the UTF-8 filename check on Windows). If you want to check with check50, only online checks will work as check50 has the Exit testing temporary directory before removing it. errors for offline mode. I will fix those once we agree on this PR.

P. S. Will any of these contributions count towards my CS50 score ? This is the GitHub account for my course as well. I'm just curious.

rongxin-liu commented 3 weeks ago

Thank you for your contribution and the effort you’ve put into improving support for Windows users. We genuinely appreciate your initiative to make the tools more accessible. However, after careful consideration, we’ve decided not to merge this pull request at this time.

Our primary recommendation for those who prefer a local environment is to use cs50.dev, which is well-supported and provides a consistent experience across platforms. Additionally, for users seeking an offline solution, cli50 is available via Docker, allowing you to run submit50 and check50 locally.

We recognize the effort you put into making this PR, therefore you can use this PR as your final project.

Sashank999 commented 3 weeks ago

Thank you for your reply.