Skip to content

Strict detection of tmux version via regex #397

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

Closed
wants to merge 1 commit into from
Closed

Strict detection of tmux version via regex #397

wants to merge 1 commit into from

Conversation

mdeguzis
Copy link

See: #396

This change uses a more precise regex method to grab the tmux version string, taking into account the many variations of tmux versions:

# tmux 3.3a · tmux 3.3 · tmux 3.2a · tmux 3.2 · tmux 3.1c · tmux 3.1b · tmux tmux.org 2.8

I tested my change locally with tmuxp as well:

[dev-dsk-deguzim-1a-fa82568b DeGuzim-Config]$ tmuxp freeze --force -f yaml --yes --quiet
Save to: /home/deguzim/.tmuxp/work.yaml [/home/deguzim/.tmuxp/work.yaml]: 
[dev-dsk-deguzim-1a-fa82568b DeGuzim-Config]$ cat ~/.tmuxp/work.yaml 
session_name: work
windows:
- focus: 'true'
  layout: 61a9,231x42,0,0[231x16,0,0{150x16,0,0,0,80x16,151,0,2},231x25,0,17,1]
  options: {}
  panes:
  - shell_command:
    - cd /local/home/deguzim/src/libtmux
    - zsh
  - shell_command:
    - cd /local/home/deguzim/src/tmuxp
    - zsh
  - focus: 'true'
    shell_command:
    - cd /local/home/deguzim/src/DeGuzim-Config
    - python3
  window_name: zsh

Testing with python3:

>>> ver = "tmux 1.8"
>>> import re
>>> re.search('[0-9]{1}.[0-9]', ver).group(0)
'2.8'

>>> ver = "tmux 2.3"
>>> re.search('[0-9]{1}.[0-9]', ver).group(0)
'2.3'

Regex 101 test: https://regex101.com/r/y7jsSJ/1

@CLAassistant
Copy link

CLAassistant commented Aug 11, 2022

CLA assistant check
All committers have signed the CLA.

@mdeguzis mdeguzis changed the title Update common.py Strict detection of tmux version via regex Aug 12, 2022
@tony tony self-requested a review August 12, 2022 20:16
Copy link
Member

@tony tony left a comment

Choose a reason for hiding this comment

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

Looking good so far. Good catch and nice job.

  1. We may want to test for get_version() test 3.2a and 3.2
  2. I have a regex here: https://github.com/tmux-python/libtmux/blob/d4c9af5/tests/test_common.py#L32, interestingly I don't fetch the letter either

@@ -552,7 +552,7 @@ def get_version() -> LooseVersion:
)
raise exc.VersionTooLow(proc.stderr)

version = proc.stdout[0].split("tmux ")[1]
version = re.search('[0-9]{1}.[0-9]', proc.stdout[0]).group(0)
Copy link
Member

Choose a reason for hiding this comment

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

What about line 561, wouldn't this lose access to the a in 3.2a?

@@ -552,7 +552,7 @@ def get_version() -> LooseVersion:
)
raise exc.VersionTooLow(proc.stderr)

version = proc.stdout[0].split("tmux ")[1]
version = re.search('[0-9]{1}.[0-9]', proc.stdout[0]).group(0)
Copy link
Member

Choose a reason for hiding this comment

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

poetry run mypy .

libtmux/common.py:555: error: Item "None" of "Optional[Match[str]]" has no attribute "group"

This will need null-checks to handle empty matches. I haven't tested, but it'd be something like

Suggested change
version = re.search('[0-9]{1}.[0-9]', proc.stdout[0]).group(0)
match = re.search('[0-9]{1}.[0-9]', proc.stdout[0])
assert match is not None
version = match.group(0)

@tony
Copy link
Member

tony commented Aug 21, 2022

@mdeguzis I will give your PR priority review if you have more commits

I can also take a stab at it (but would be happy if yours got in so you get credit!)

@mdeguzis
Copy link
Author

I should be able to look at the comments this week and see what I can do.

@tony
Copy link
Member

tony commented Aug 24, 2022

@mdeguzis That sounds fine!

@tony
Copy link
Member

tony commented Dec 10, 2022

@mdeguzis Is this a PR you're still interested in?

@tony tony force-pushed the master branch 3 times, most recently from d3613a0 to 0c76816 Compare May 27, 2023 13:20
@tony tony force-pushed the master branch 2 times, most recently from f15027f to 8baa764 Compare February 17, 2024 13:33
@mdeguzis mdeguzis closed this by deleting the head repository Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants