ploxiln/fab-classic

Error when updating to fab-classic 1.19

Closed this issue · 2 comments

Hello friends,

after upgrading to fab-classic 1.19 I get the following error while trying to deploy:

Traceback (most recent call last):
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\main.py", line 769, in main
    execute(
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\tasks.py", line 377, in execute
    results[host] = _execute(
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\tasks.py", line 268, in _execute
    return task.run(*args, **kwargs)
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\tasks.py", line 168, in run
    return self.wrapped(*args, **kwargs)
  File "C:\progr\py3\foodrec\foodrec\fabfile.py", line 59, in full_deploy
    commit()
  File "C:\progr\py3\foodrec\foodrec\fabfile.py", line 21, in commit
    local("git add .")
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\operations.py", line 1249, in local
    with settings(hide('stdout', 'stderr') if capture else None):
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\context_managers.py", line 241, in settings
    return nested(*managers)
  File "c:\progr\py3\foodrec\venv\lib\site-packages\fabric\context_managers.py", line 40, in __init__
    self.enter_context(manager)
  File "C:\Users\serafeim\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 424, in enter_context
    _exit = _cm_type.__exit__
AttributeError: type object 'NoneType' has no attribute '__exit__'

My fabfile is the following:

from __future__ import with_statement
from fabric.api import env, cd, run, local, settings
import os


def black():
    "Run black"
    print("Running black...")
    local("black .")
    print("Black ok!")


def flake8():
    "Run flake8 checks"
    print("Check with flake8")
    # local("flake8 .")
    print("flake8 ok!")


def commit():
    local("git add .")
    with settings(warn_only=True):
        local("git commit")
    with settings(warn_only=True):
        local("git push origin master")
    print("Commit ok")


def pull():
    with cd(env.directory):
        run("git fetch origin")
        run("git merge origin/master")
    print("fetch / merge ok")


def work():
    "Do work on server (copy settings, migrate and run collect static)"
    with cd(env.directory):
        requirements_txt = "requirements/" + env.env + ".txt"
        if os.stat(requirements_txt).st_size > 0:
            virtualenv("pip install -r {0}".format(requirements_txt))
        virtualenv("python manage.py migrate")
        virtualenv("python manage.py update_permissions")
        virtualenv("python manage.py collectstatic --noinput")
        if env.env == "prod":
            virtualenv("python manage.py compres")


def touch_wsgi():
    print("Restarting uwsgi")
    if env.env == "prod":
        run(r"cat /home/serafeim/aismanager/gunicorn.pid | xargs kill -HUP")


def full_deploy():
    "Reformat - check - commit - pull - do work - and restart uwsgi"
    black()
    flake8()
    commit()
    pull()
    work()
    touch_wsgi()


def virtualenv(command):
    run(env.activate + "&&" + command)


def uat():
    "UAT settings"
    env.env = "uat"
    env.user = "serafeim"
    env.hosts = ["test.gr"]
    env.directory = "/home/serafeim/foodrec/foodrec"
    env.activate = "source /home/serafeim/foodrec/venv/bin/activate"


def prod():
    "PROD settings"
    env.env = "prod"
    env.user = "serafeim"
    env.hosts = [""]
    env.directory = "/home/serafeim/foodrec/foodrec"
    env.activate = "source /home/serafeim/foodrec/venv/bin/activate"

It seems that there's something fishy while trying to run local when encapsulating in the settings context manager...

I am using Python 3.8.1 and the command I run is fab uat full_deploy. Notice that this works flawlessly with fab-classic 1.18.1.

TIA

Works now with verrsion 1.19.1! Thank you so much for the quick response and for this great project!!

Kind regards,
Serafeim