Skip to content

Commit 2810d15

Browse files
authored
Add detection for pipx installation method in update messages (#299)
1 parent ad2a734 commit 2810d15

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/sinol_make/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ def main():
109109
'https://github.com/sio2project/sinol-make/#reporting-bugs-and-contributing-code')
110110
finally:
111111
if new_version is not None:
112+
install_method = 'pipx' if util.is_probably_installed_by_pipx() else 'pip'
112113
if not util.is_dev(new_version):
113114
print(util.warning(
114115
f'New version of sinol-make is available (your version: {__version__}, available version: '
115116
f'{new_version}).\n'
116117
f'Changelog can be found at https://github.com/sio2project/sinol-make/releases.\n'
117-
f'You can update sinol-make by running `pip install sinol-make --upgrade`.'))
118+
f'You can update sinol-make by running `{install_method} install sinol-make --upgrade`.'))
118119
elif util.is_dev(new_version):
119120
print(util.warning(
120121
f'New development version of sinol-make is available (your version: {__version__}, available '
121122
f'version: {new_version}).\n'
122123
f'Changelog can be found at https://github.com/sio2project/sinol-make/releases.\n'
123-
f'You can update sinol-make by running `pip install sinol-make --pre --upgrade`.'
124+
f'You can update sinol-make by running `{install_method} install sinol-make --pre --upgrade`.'
124125
))

src/sinol_make/util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,18 @@ def exit_with_error(text, func=None):
431431

432432
def has_sanitizer_error(output, exit_code):
433433
return ('ELF_ET_DYN_BASE' in output or 'ASan' in output) and exit_code != 0
434+
435+
436+
def is_running_in_virtualenv():
437+
return (
438+
hasattr(sys, 'real_prefix') or
439+
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
440+
)
441+
442+
def is_probably_installed_by_pipx():
443+
if not is_running_in_virtualenv():
444+
return False
445+
446+
# Pipx installs into ~/.local/pipx/venvs/
447+
venv_path = sys.prefix
448+
return 'pipx' in venv_path or 'pipx' in os.path.abspath(venv_path)

0 commit comments

Comments
 (0)