Skip to content

Consider a guardrail for the fact that -f changed to load config, not fabfile #1823

@pcdinh

Description

@pcdinh

Hi,

The following code (fabfile.py) can cause an error by specifying an "import os"

from invoke import task, Exit, Collection, Responder
from fabric2 import Connection
from fabric2 import Config
from fabric2.transfer import Transfer
from patchwork.files import append
import os

@task
def deploy(context, host_name):
    pass

Run the above code:

fab2 -f ./fabfile.py -i C:/Users/fox/.ssh/id_rsa --ssh-config=C:/Users/fox/.ssh/config -H mango deploy dev1

on Windows

or

fab2 -f ./fabfile.py -i ~/.ssh/id_rsa --ssh-config=~/.ssh/config -H mango deploy dev1

on Ubuntu 18

will yield the following exception

Traceback (most recent call last):
  File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python36\Scripts\fab2.exe\__main__.py", line 9, in <module>
  File "c:\python36\lib\site-packages\invoke\program.py", line 329, in run
    self.update_config()
  File "c:\python36\lib\site-packages\fabric2\main.py", line 130, in update_config
    self.config.merge()
  File "c:\python36\lib\site-packages\invoke\config.py", line 931, in merge
    self._merge_file('runtime', "Runtime")
  File "c:\python36\lib\site-packages\invoke\config.py", line 951, in _merge_file
    merge_dicts(self._config, data)
  File "c:\python36\lib\site-packages\invoke\config.py", line 1200, in merge_dicts
    base[key] = copy.copy(value)
  File "c:\python36\lib\copy.py", line 96, in copy
    rv = reductor(4)
TypeError: can't pickle module objects

The exception disappears when I remove the line import os

Environment

Windows 10, Ubuntu 18
Python 3.6.4
Fabric 2.1.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions