Invoking tool from command line for VSCode Extension
See original GitHub issueHello,
I’m in the process of writing a VSCode extension that adds support for reorder-python-imports
. As part of this process, I need to be able to provide a file that may not yet have been saved to your tool, so that it can sort its imports. Ideally, I would like to provide the text of the file via stdin, and get the file output via stdout. However, to get this to work, I have the following questions:
- Is
reorder-python-imports /dev/stdin
still the recommended method of reading from stdin? ~It might be better if this wasreorder-python-imports --
instead to indicate that the file to be read will be from stdin, as that is a more platform agnostic way of doing things.~ --print-only
is marked as deprecated, but I don’t see another way of getting the output of the file that is easy to parse for a command line tool (writing a regex to parse the difflib output seems tedious). Is there a better way that I’m not aware of to solve this, or is there any chance that option could be un-deprecated?- My understanding is that
reorder-python-imports
uses static analysis to determine which imports are third party and which are first party. Will providing the file via stdin to this tool mess that up? What impact does the current working directory have on this static analysis?
Looking forward to getting this tool better supported in my favorite IDE! I strongly prefer your approach over isort 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Command Line Interface (CLI) - Visual Studio Code
Visual Studio Code has a powerful command-line interface built-in that lets you control how you launch the editor. You can open files, install...
Read more >Managing Extensions in Visual Studio Code
You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the...
Read more >Integrated Terminal in Visual Studio Code
From the Command Palette (Ctrl+Shift+P), use the View: Toggle Terminal command. The integrated terminal can run commands such as mkdir and git just...
Read more >Commands | Visual Studio Code Extension API
The vscode.commands.executeCommand API programmatically executes a command. This lets you use VS Code's built-in functionality, and build on extensions such as ...
Read more >Terminal Shell Integration in Visual Studio Code
Visual Studio Code has the ability to integrate with common shells, allowing the terminal to understand more about what's actually happening inside the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
By the way, the first working version is available at this location: https://github.com/TheButlah/vscode-reorder-python-imports
There’s still a few issues to iron out, namely figuring out how to avoid
isort
from microsoft’s python extension overwritingreorder-python-import
s changes on filesaves, but there ya go.for (1.) and (2.)
reorder-python-imports -
does exactly what you want (reads from stdin, writes to stdout)for 3. the filename itself shouldn’t matter unless the script is importing from itself (but that seems super rare???). the working directory is pretty sensitive as that’s used to find the local modules – there’s also the
--application-directories
option which is commonly used when using asrc
layout (for example)hope that helps! some other people were looking for a vs code extension in #117 so maybe once it’s completed you can resolve that one as well!