libtmux icon indicating copy to clipboard operation
libtmux copied to clipboard

libtmux is picking up the wrong tmux version

Open mdeguzis opened this issue 3 years ago • 14 comments

See: https://github.com/tmux-python/tmuxp/issues/794

Started new server, protocol mismatch. tmuxp seems to be using /usr/bin/tmux instead of what I have aliased.

$ tmux -V
tmux.orig 2.8

$ /usr/bin/tmux -V
tmux 1.8

The problem for me is https://github.com/tmux-python/libtmux/blob/master/libtmux/common.py#L241 Your search paths are then placing the system paths AFTER the custom patch which tmux pulls up:

241     def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
242         tmux_bin = which(
243             "tmux",
244             default_paths=kwargs.get(
245                 "tmux_search_paths",
246                 ["/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/local/bin"],
247             ),
248             append_env_path=kwargs.get("append_env_path", True),
249         )

This really should be the other way around.

$ which tmux
tmux=/apollo/env/envImprovement/bin/tmux

I'd hate to have to fork this, so can we just perform a subprocess.run which tmux instead? Why do we need to search paths?

tmuxp:

-------------------------
environment:
        dist: Linux-5.4.204-124.362.amzn2int.x86_64-x86_64-with-glibc2.2.5
        arch: x86_64
        uname: Linux; dev-dsk-deguzim-1a-fa82568b.us-east-1.amazon.com; 5.4.204-124.362.amzn2int.x86_64
        version: #1 SMP Wed Jul 13 03:24:31 UTC 2022
-------------------------

tmux version: 1.8
libtmux version: 0.12.0
tmuxp version: 1.12.1
tmux path: /usr/bin/tmux
tmuxp path: /home/deguzim/.local/lib/python3.7/site-packages/tmuxp
shell: /bin/zsh
-------------------------
tmux sessions:

        protocol version mismatch (client 7, server 8)
tmux windows:

        protocol version mismatch (client 7, server 8)
tmux panes:

        protocol version mismatch (client 7, server 8)
tmux global options:

        protocol version mismatch (client 7, server 8)
tmux window options:

        protocol version mismatch (client 7, server 8)

mdeguzis avatar Aug 11 '22 13:08 mdeguzis

The problem is how this code detects the version. It needs to be using regex, not list indices:

$ tmuxp freeze --force -f yaml --yes --quiet
DEBUG:
['/apollo/env/envImprovement/bin/tmux', '-V']
DEBUG:
b'tmux.orig 2.8\n'
b''

This code needs to go away in favor of regex:

version = proc.stdout[0].split("tmux ")[1]

Test

>>> 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'

Tmux versions can have a letter after it as well, so this regex should work

# tmux 3.3a · tmux 3.3 · tmux 3.2a · tmux 3.2 · tmux 3.1c · tmux 3.1b · tmux
[0-9]{1}.[0-9]

Will you accept a CR for this?

mdeguzis avatar Aug 11 '22 13:08 mdeguzis

Fixed tmuxp:

$ tmuxp freeze --force -f yaml --yes --quiet
Save to: /home/deguzim/.tmuxp/work.yaml [/home/deguzim/.tmuxp/work.yaml]: 

Submitted PR: https://github.com/tmux-python/libtmux/pull/397

mdeguzis avatar Aug 11 '22 14:08 mdeguzis

@mdeguzis can you look at the tests? Can you elaborate a bit more on the PR and what it's fixing?

How are you installing tmux? e.g. why is the name of it tmux.orig?

tony avatar Aug 17 '22 04:08 tony

It's just how tmux from our company is done, I don't see why a regex that picks up the version N.N is a bad thing, it should not be using .split to pull the version and accessing an index. I have 0 problems when using version detection based on regex. Our company probably appends orig, since the system tmux exists and is very old (1.8).

As far as the tests, throwing different strings at it like tmux.orig 2.8 would be ideal.

mdeguzis avatar Aug 17 '22 15:08 mdeguzis

Why do we need to search paths?

Not directly related to the issue, but I had the same concern about the reason to force the paths instead of relaying on PATH env

rockandska avatar Aug 17 '22 19:08 rockandska

It's just how tmux from our company is done, I don't see why a regex that picks up the version N.N is a bad thing, it should not be using .split to pull the version and accessing an index. I have 0 problems when using version detection based on regex. Our company probably appends orig, since the system tmux exists and is very old (1.8).

@mdeguzis We welcome PRs that improve support and compatibility

On that note, are you still committed to doing #397? Since this is the first time I've seen this case - it needs a champion to take it to the finish line (while preserving the behavior that works)

tony avatar Aug 21 '22 16:08 tony

@rockandska

Not directly related to the issue, but I had the same concern about the reason to force the paths instead of relaying on PATH env

I'm happy to have better support in this regard. Are you open to making a PR for this simplification?

tony avatar Aug 21 '22 16:08 tony

@mdeguzis Does v0.15.0a1 change anything with this?

v0.15.0a1: GitHub release, git tag, PyPI package

pip install libtmux==0.15.0a1

tony avatar Aug 28 '22 21:08 tony

$ pip3 install libtmux==0.15.0a1
Defaulting to user installation because normal site-packages is not writeable
Collecting libtmux==0.15.0a1
  Using cached libtmux-0.15.0a1-py3-none-any.whl (33 kB)
Installing collected packages: libtmux
  Attempting uninstall: libtmux
    Found existing installation: libtmux 0.14.2
    Uninstalling libtmux-0.14.2:
      Successfully uninstalled libtmux-0.14.2
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.                                                        
tmuxp 1.13.1 requires libtmux<0.15.0,>=0.14.0, but you have libtmux 0.15.0a1 which is incompatible.

What tag of tmuxp works for this lib version?

mdeguzis avatar Aug 29 '22 15:08 mdeguzis

@mdeguzis

pip install libtmux==0.15.0a1 --pre

Does that work?

If not, https://github.com/tmux-python/tmuxp/pull/805 may be needed

pip install --user 'git+https://github.com/tmux-python/[email protected]'
pipx install [email protected] 'tmuxp @ git+https://github.com/tmux-python/[email protected]'

tony avatar Aug 29 '22 16:08 tony

@mdeguzis P.S. If you do above, you may need to pip uninstall libtmux and pip uninstall tmuxp first.

tony avatar Aug 29 '22 16:08 tony

pip3 uninstall libtmux
pip3 uninstall tmuxp

$ pip3 install --user 'git+https://github.com/tmux-python/[email protected]'a                                                                                                        
Collecting git+https://github.com/tmux-python/[email protected]
  Cloning https://github.com/tmux-python/tmuxp.git (to revision libtmux-v0.15a) to /tmp/pip-req-build-o6j9st1k
  Running command git clone --quiet https://github.com/tmux-python/tmuxp.git /tmp/pip-req-build-o6j9st1k
  warning: You appear to have cloned an empty repository.
  WARNING: Did not find branch or tag 'libtmux-v0.15a', assuming revision or ref.
  error: subprocess-exited-with-error

  × git rev-parse HEAD did not run successfully.
  │ exit code: 128
  ╰─> [2 lines of output]
      HEAD
      fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:
      'git <command> [<revision>...] -- [<file>...]'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git rev-parse HEAD did not run successfully.
│ exit code: 128
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.


$ pip3 install [email protected] 'tmuxp @ git+https://github.com/tmux-python/[email protected]'

Usage:   
  /usr/bin/python3 -m pip install [options] <requirement specifier> [package-index-options] ...
  /usr/bin/python3 -m pip install [options] -r <requirements file> [package-index-options] ...
  /usr/bin/python3 -m pip install [options] [-e] <vcs project url> ...
  /usr/bin/python3 -m pip install [options] [-e] <local project path> ...
  /usr/bin/python3 -m pip install [options] <archive url/path> ...

no such option: --suffix

In the past I would just checkout master/mainline/branch and do pip3 install -e .. I'll defer to you on what I should be running.

mdeguzis avatar Aug 29 '22 21:08 mdeguzis

@mdeguzis Typo, trailing a: pip3 install --user 'git+https://github.com/tmux-python/[email protected]'a

Do: pip3 install --user 'git+https://github.com/tmux-python/[email protected]'

It's not master since it's a PR for libtmux-v0.15: https://github.com/tmux-python/tmuxp/pull/805 image

libtmux v0.15 isn't in master yet

tony avatar Aug 29 '22 21:08 tony

$  pip3 install --user 'git+https://github.com/tmux-python/[email protected]'
Collecting git+https://github.com/tmux-python/[email protected]
  Cloning https://github.com/tmux-python/tmuxp.git (to revision libtmux-v0.15) to /tmp/pip-req-build-7ekjpwtu
  Running command git clone --quiet https://github.com/tmux-python/tmuxp.git /tmp/pip-req-build-7ekjpwtu
  warning: You appear to have cloned an empty repository.
  WARNING: Did not find branch or tag 'libtmux-v0.15', assuming revision or ref.
  error: subprocess-exited-with-error
  
  × git rev-parse HEAD did not run successfully.
  │ exit code: 128
  ╰─> [2 lines of output]
      HEAD
      fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:
      'git <command> [<revision>...] -- [<file>...]'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git rev-parse HEAD did not run successfully.
│ exit code: 128
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

mdeguzis avatar Aug 30 '22 13:08 mdeguzis