Skip to content

Improve how trogon is calling the command with arguments #107

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bigbirdcode
Copy link

This PR tries to resolve several problems. All the changes are small and connected, that is why I opened just one PR.

Please review it commit by commit.

Fixes:

#104 - In run_command.py file the UserCommandData.to_cli_args() now contains string conversion.
I have not added conversion to _to_cli_args() as it was already too complex.

#105 - shlex replaced to oslex, for the need of Windows users.
I have added to pyproject.toml.
TODO: poetry.lock was not updated, I don't have tooling for that.

#106 - To run well and wait for the output on Windows I have added sys.exit(subprocess.call(..., shell=True)) as the pair of os.execvp() call.
Note: shell=True was needed for me.

#81 , #70 , #67 , #65 - I try to fix all these. In the file detect_run_string.py the function detect_run_string() returns a short version of the command, while for execution we need the full version. So I have added a function exact_run_commands(). I have also modified how the command is called in trogon.py and replaced os.execvp() to os.execv().

Tested:

  • Windows, from venv with and without -m, outside of a venv with direct path to Python.exe, and with installed app
  • Linux, from venv with and without -m, outside of a venv with direct path to python3

I have not tested with pipx or such cases. Please tell me of more modification is needed.

@bigbirdcode bigbirdcode changed the title Improve cli args Improve how trogon is calling the command with arguments Feb 1, 2025
@bissonex
Copy link

I have tested this PR and it solve my issues with running commands on Windows. Especially #67.

@Mythical-Github
Copy link

I am waiting on the merge as well

@bigbirdcode
Copy link
Author

@daneah by any chance can you review and comment my PR?

@daneah
Copy link
Collaborator

daneah commented Apr 6, 2025

I'll try to review in depth soon @bigbirdcode — I'm working through finalizing my talk about our internal CLI tooling for PyTexas this coming weekend.

import sys
from types import ModuleType

import oslex
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not confident we should be taking on this dependency—it appears not to have been updated in some time, nor with many stars on GitHub. It is a small enough footprint that we should perhaps bring what we need of its functionality here into this package directly.

@@ -84,7 +84,7 @@ def to_cli_args(self, include_root_command: bool = False) -> list[str]:
Returns:
A list of strings that can be passed to subprocess.run to execute the command.
"""
cli_args = self._to_cli_args()
cli_args = list(str(arg) for arg in self._to_cli_args())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
cli_args = list(str(arg) for arg in self._to_cli_args())
cli_args = [str(arg) for arg in self._to_cli_args()]

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.

4 participants