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

Platform handling improvements and WSL bugfix. #1059

Merged
merged 4 commits into from
Jul 25, 2021

Conversation

zee-bit
Copy link
Member

@zee-bit zee-bit commented Jun 28, 2021

This PR improves our platform handling by defining an isolated module config/platform_detection.py that contains the platform detection code and uses a single variable PLATFORM to hold the name of the platform that the current ZT instance is loaded on. This fixes a bug in WSL where multiple platforms were detected. Related discussion in: #zulip-terminal>Platform handling (#T791) and WSL issues

Fixes #791.

@zulipbot zulipbot added size: L [Automatic label added by zulipbot] further discussion required Discuss this on #zulip-terminal on chat.zulip.org General labels Jun 28, 2021
@zee-bit zee-bit added the PR needs review PR requires feedback to proceed label Jun 29, 2021
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zee-bit Some initial thoughts: (possibly some are in the issue?)

  • I think a good long-term goal would be to have all the platform-specific code in one module, and it's likely easier for that to be where the detection happens too; on that basis and given the detection would then be a detail of the module, I'm not entirely convinced it fits in config/.
  • While it's not always possible, it would be good to see this first commit not just add unused code but migrate to using it - ie. be a refactor of the detection into the new file, with the old platform variables being set according to PLATFORM - the second commit would then become a migration from those to use PLATFORM (so be slightly smaller). If we go the approach of one module for minimal platform-specific functions, that could then be a good follow-up.
  • We don't currently test the platform detection, which I think we could do with marks/skips; that's maybe not explicitly part of TRACKING: Improve platform handling #791 but we should test it more explicitly if we can.
  • You've reused the Literal definition in multiple places which would normally make me want to define it instead, along with the multi-part definition I suggested on the stream (like we do with Flags), to leave "unsupported" separate.
  • Another follow-up might be to add an extra helper to the module to check the platform is supported and/or give details of that

@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Jul 1, 2021
@zee-bit zee-bit force-pushed the improve-platform-handling branch from e70c224 to 210a9eb Compare July 7, 2021 20:10
@zee-bit zee-bit force-pushed the improve-platform-handling branch from 210a9eb to cb6a7d2 Compare July 20, 2021 16:33
@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Jul 20, 2021
zee-bit added 4 commits July 25, 2021 14:44
This commit creates a new module (platform_code.py) inside zulipterminal/
which contains the code to detect the current platform (OS) that the ZT
instance is running on.

The platform_code.py module has a PLATFORM variable that holds the platform
name which could only be one of "Linux", "MacOS", "WSL" or "unsupported".
Currently, we only use this to set our old platform variables in helper.py
accordingly.
This commit adapts the codebase to use the new PLATFORM variable instead
of the 3 booleans that stood for each of the supported platforms i.e. WSL,
MACOS and LINUX. This ensures that only one platform (OS) is set for each
instance i.e. it is mutually exclusive.

We modify the platform-dependent codes in various modules to use this new
variable, which prevents bugs that arose earlier due to multiple OS'es
being detected in WSL. Discussion about the bug and how it affected some
features in WSL: #zulip-terminal>Platform handling (#T791) and WSL issues.

Tests amended.

This is a partial fix towards zulip#791.
This commit shifts the notify() function to the platform_code.py module
in an effort to move all platform dependent code to a single isolated
module so that other modules are unaware of the underlying platform and
how they are handled for different platforms. This will also allow us to
better handle unsupported platforms.

Tests amended.

New test file created, and added to list of files to be linted by mypy.
This commit moves the platform dependent selection_key condition to
the platform_code.py module. The selection key is now stored inside a
global variable MOUSE_SELECTION_KEY that can be imported in other modules
whenever needed.
@neiljp neiljp force-pushed the improve-platform-handling branch from cb6a7d2 to 464faf6 Compare July 25, 2021 22:58
@zulipbot
Copy link
Member

Hello @zee-bit, it seems like you have referenced #791 in your pull request description, but you have not referenced them in your commit message description(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged.

Please run git commit --amend in your command line client to amend your commit message description with Fixes #791..

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.

Thank you for your contributions to Zulip!

@neiljp
Copy link
Collaborator

neiljp commented Jul 25, 2021

@zee-bit Thanks for this refactor/bugfix 👍 I'm going to merge this now after a few minor adjustments 🎉

While this migrates almost all platform use into the new module, we can discuss other functionality which might be worth having there too (open in browser? open media?)

I've left #791 from being closed by this, since while this does resolve the multiple-platform issue, it also mentions other issues, which I've expanded on in a task list there after the discussion in the stream.

@neiljp neiljp merged commit 4f8c6dc into zulip:main Jul 25, 2021
@neiljp neiljp added area: refactoring bug Something isn't working and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback further discussion required Discuss this on #zulip-terminal on chat.zulip.org labels Jul 25, 2021
@zulipbot
Copy link
Member

Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

@neiljp neiljp added this to the Next Release milestone Jul 25, 2021
@neiljp neiljp removed the General label Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: refactoring bug Something isn't working size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TRACKING: Improve platform handling
3 participants