We bring Python and Bash together: the release of the python-shell and smart-env v libraries. 1.0.1

Good day to all!

On February 29, 2020, the official micro-release of smart-env and python-shell libraries was held . For those who are not in the know, I suggest that you first read the first post .

In short, the changes include auto-completion of commands, expanding the ability to run commands, a bit of refactoring and bug fixes.

I ask for details under cat.

What's new in python-shell?


I'll start right away with dessert.

Team completion


Agree - it is convenient when the editor / IDE / terminal prompts the name of the command, and sometimes call parameters? So python-shell is progressing a bit in providing such functionality. Due to the fact that the fields of the Shell class under the de-facto hood are not its fields (ubiquitous __getattr__), autocompletion was also created from scratch (by overloading the __dir__ method, respectively). Auto-completion is currently running on BPython and IPython environments. Of course, I want to see integration with more venerable products like PyCharm, and in this direction we are exploring implementation possibilities.

Adding Properties


As part of the release, the Shell class received a new last_command property. The need for it arose due to the fact that when a ShellException was thrown by a command with a non-zero return code, the Command object was not returned from the __call __ () call of the command object. Now there is an opportunity to do so:

try:
    command = Shell.touch('/foo.txt')
except ShellException:
    command = Shell.last_command

Also expanded the list of properties of the Command object. Added the errors field, which returns the output of the command to the error stream.

Running Commands with Python Invalid Names


Almost any system has at least one program whose name does not fit as an identifier in Python (for example, the well-known utility 2to3). Call her with

Shell.2to3()

fails - the interpreter will not skip.
The solution is to invoke the command in a workaround:

Shell("2to3")  #   

It is worth noting that in the same way it is possible to run commands that are valid from the point of view of the interpreter, which leaves it possible to create flexible scripts like

cmd = "python{}".format(sys.version_info[0])
Shell(cmd)(*args, **kwargs)

Minor changes


  • The __repr __ () and __str __ () methods of the Command object are implemented, which now produce intuitive values ​​(a command with parameters and its stdout exhaust, respectively).
  • Minor corrections by code.
  • Adding test coverage as well as reorganizing existing ones.
  • Adding the Subprocess and Process classes, the purpose of which is to create an additional level of abstraction when working with the subprocess module. For the most part, it is necessary to eliminate code repetitions when working with Python 2/3, but it can potentially give other bonuses.

What's new in smart-env?


Unlike python-shell, there are fewer changes in the smart-env library. The reason for this is simple - lack of free time, during which some potential improvements (for example, the completion of environment variables) were carried over to the next release.

In fact, the following changes have been made to the library:

  • Minor corrections by code.
  • Refactoring
  • Reorganization and refinement of existing tests.

Next Release Plans


Python-shell library


  • Adding support for non-blocking command calls (parallel execution).

Smart-env library


  • Implementation of self-completion of environment variables in the ENV class.
  • Support for the in operator to verify the existence of an env variable.
  • Implementing str () and repr () functions for the ENV class.

The dates of the next releases will be additionally announced in the following communication channels:


All Articles