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

Support default arguments for the executable #27

Closed
wants to merge 1 commit into from

Conversation

mkhl
Copy link
Member

@mkhl mkhl commented Feb 13, 2017

Some “Run Script” commands supply arguments to the executable that may lead to errors, which caused for example textmate/swift.tmbundle#16.

This change adds a default_args option to #run which is appended to the command line when there is no hashbang line (or parsing them is disabled).

“Run Script” type commands in other bundles will need updating to take advantage of this change.

Some “Run Script” commands supply arguments to the executable that may lead to errors, which caused for example textmate/swift.tmbundle#16.

This change adds a `default_args` option to `#run` which is appended to the command line when there is *no* hashbang line (or parsing them is disabled).

“Run Script” type commands in other bundles will need updating to take advantage of this change.
@mkhl
Copy link
Member Author

mkhl commented Feb 13, 2017

The problem mentioned above hit me again while using pytest.

Pytest files are Python scripts that one is supposed to run with pytest, so it would seem sensible to add a hashbang line to that effect:

#!/usr/bin/env pytest

def test_nothing():
    pass

Running the above fails with

usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: -u
  inifile: None
  rootdir: /Users/mkhl/Desktop

because Python’s “Run Script” command hardcodes a "-u" argument to the interpreter, which pytest doesn’t understand.
This change together with a change of that command from TextMate::Executor.run(ENV["TM_PYTHON"] || "python", "-u", ENV["TM_FILEPATH"],… to TextMate::Executor.run(ENV["TM_PYTHON"] || "python", ENV["TM_FILEPATH"], :default_args => "-u",… fixes the problem.

The same error occurs when using alternative forms like #!/usr/local/bin/pytest or #!/usr/bin/env python -m pytest.

mkhl added a commit to mkhl/python.tmbundle that referenced this pull request Mar 1, 2017
The `-u` parameter is not recognized by all executables running python code,
pytest being one that doesn’t.

This change declares `-u` a _default_ argument that is only used when the file
contains _no_ hashbang.

Depends on textmate/bundle-support.tmbundle#27
@mkhl mkhl closed this Nov 14, 2021
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.

None yet

1 participant