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

[FEATURE][Python console] Run shell commands from the console #51919

Merged
merged 5 commits into from
Apr 24, 2023

Conversation

YoannQDQ
Copy link
Contributor

Description

Mimics IPython behavior to run system command from the Python console.

  • Run any command that works at the command-line with the syntax !cmd. The console will start a subprocess, and forward its output to the Python Console Output.
  • While the subprocess is running, the Python Console Input switch to STDIN mode and forwards entered character to the child process. This make it possible to send confirmation when the child program ask for it.
  • EASY pip install/remove !!!
  • When the Console is in STDIN mode, pressing Ctrl+C kills the subprocess.
  • Affect the result of a command to a variable with the syntax var = !cmd

Example

>>> !echo Hello
Hello

>>> !gdalinfo --version
GDAL 3.4.1, released 2021/12/27

>>> sql_formats = !ogrinfo --formats | grep SQL
>>> sql_formats
['SQLite -vector- (rw+v): SQLite / Spatialite', '  MSSQLSpatial -vector- (rw+): Microsoft SQL Server Spatial Database', '  PostgreSQL -vector- (rw+): PostgreSQL/PostGIS', '  MySQL -vector- (rw+): MySQL', '  PGDUMP -vector- (w+v): PostgreSQL SQL dump']

demo

@github-actions github-actions bot added the Python Console Python Console label Feb 17, 2023
@YoannQDQ YoannQDQ changed the title [FEATURE][Python console] Run system commands frm the console [FEATURE][Python console] Run shell commands from the console Feb 17, 2023
@YoannQDQ YoannQDQ closed this Feb 17, 2023
@YoannQDQ YoannQDQ reopened this Feb 17, 2023
@github-actions github-actions bot added this to the 3.30.0 milestone Feb 18, 2023
@nyalldawson nyalldawson added Feature Frozen Feature freeze - Do not merge! labels Feb 20, 2023
@YoannQDQ YoannQDQ force-pushed the python-console-run-system-commands branch from 4be9e0c to 515aaf7 Compare February 21, 2023 14:28
@YoannQDQ YoannQDQ added the Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. label Feb 27, 2023
@github-actions
Copy link

@YoannQDQ
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@YoannQDQ YoannQDQ force-pushed the python-console-run-system-commands branch from 515aaf7 to 14a7bb5 Compare March 3, 2023 14:49
@nyalldawson nyalldawson modified the milestones: 3.30.0, 3.32 (feature) Mar 6, 2023
@nyalldawson nyalldawson removed the Frozen Feature freeze - Do not merge! label Mar 6, 2023
@YoannQDQ YoannQDQ modified the milestones: 3.32 (feature), 3.32.0 Mar 6, 2023
@YoannQDQ YoannQDQ closed this Mar 13, 2023
@YoannQDQ YoannQDQ reopened this Mar 13, 2023
@YoannQDQ YoannQDQ force-pushed the python-console-run-system-commands branch from 14a7bb5 to 1f23378 Compare March 18, 2023 01:58
@nirvn
Copy link
Contributor

nirvn commented Mar 18, 2023

@YoannQDQ , really nice feature.

@YoannQDQ YoannQDQ force-pushed the python-console-run-system-commands branch from 1f23378 to 839ce8c Compare March 21, 2023 10:41
@YoannQDQ YoannQDQ requested a review from nirvn March 22, 2023 22:42
@YoannQDQ YoannQDQ force-pushed the python-console-run-system-commands branch from 839ce8c to 1d147f6 Compare April 1, 2023 12:20
@YoannQDQ
Copy link
Contributor Author

@nyalldawson Would you care to review this? I'd really like to see it merged.

@YoannQDQ YoannQDQ requested review from elpaso and m-kuhn April 18, 2023 06:35
Copy link
Member

@m-kuhn m-kuhn left a comment

Choose a reason for hiding this comment

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

I am in favor of merging this. It's a lot of system specific code in areas I don't know very well. But this is isolated to when the new functionality is actually used and so it should be save to send this for a wider test ride and react on feedback from different system.

@github-actions
Copy link

@YoannQDQ
A documentation ticket has been opened at qgis/QGIS-Documentation#8207
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@YoannQDQ YoannQDQ deleted the python-console-run-system-commands branch April 24, 2023 07:04
@YoannQDQ YoannQDQ added the Changelog Items that are queued to appear in the visual changelog - remove after harvesting label Apr 28, 2023
@zacharlie zacharlie added ChangelogHarvested This PR description has been harvested in the Changelog already. and removed Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ChangelogHarvested This PR description has been harvested in the Changelog already. Feature Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Python Console Python Console
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants