1

I am working in python script (windows located) to remotely execute (another) script in a linux server. I need to change the directory and keep the state for executing the script and after research I found fabric's help could resolve the problem. However it hits pylint error:

E1129:Context manager 'generator' doesn't implement __enter__ and __exit__.and 

Found some comments to this problem like the ones here, however I do not get the point, not sure what is happening and how to resolve. As far as I understood the fabric context manager cd works along with the "with" statement, many examples look like my code, few people reports a solution for this behaviour, or it is me who is a beginner does not understand. I am using VSCode as IDE, python 3.7 and fabric3. Hope you can help me to clarify what is happening. Thank you!

This is the code I am using now:

from fabric.api import cd, run, task, run, env
from fabric.context_managers import cd

env.hosts = ['xxx@server.domain.com:22']
env.password = ['myp@ss']
DIR = 'elfar/elfar'

def go_to_script():
    with cd(DIR):
        run("ls")
Sora
  • 95
  • 1
  • 10

1 Answers1

0

I seems that this issue has been around for very long time, it is called "false positive not-context-manager error". The solution is skip the warning by disabling the not-context-manager pylint check. I achieved it following the steps below:

  1. Go to the project folder and Create a pylintrc file

    pylint --generate-rcfile > ~/.pylintrc
    
  2. Open the file and locate the lines:

    # --disable=W".
    disable=
    
  3. Add not-context-manager at the end of the list as they did it here
Sora
  • 95
  • 1
  • 10