Run native VS Python OS commands in Fabric

I use Fabric for project management, deployment, etc. I really don't understand a more convenient way to run commands. For example, given that I don't need the capture and shell arguments of the Fabric local function, which are the pluses / minuses from the following?

 os.mkdir(path) 

VS

 local("mkdir %s" % path) 
+4
source share
3 answers

Depending on the objectives of your project, it may be a little more appropriate. Here are some pros and cons.

  • Benefits for standard python library functions
    • cross platform compatibility.
    • usually more efficient since no child process is created.
    • generally less complex because it includes fewer modules, processes, moving parts, shell parsing, etc. (therefore easier to debug as well)
  • Benefits for local fabric
    • it's easier to switch between local and run or sudo as your project changes.
    • more consistent with run and sudo

I think that simple local commands, which can be easily represented using the standard library functions, should be written using the standard library as the default choice due to less complexity. In each case, I asked myself a question that is more likely: running this program fabfile.py on different operating systems or converting this command from a local to a remote command, and then the code as local calls, if the latter is more likely.

+2
source

Using native OS commands means that you can pass them as arguments to both local and run . It is more consistent and flexible.

+1
source

Some good points have already been mentioned , but another advantage for using local (and friends) is that non-Python characters can more easily see what's going on.

+1
source

Source: https://habr.com/ru/post/1446773/


All Articles