liip / django-template

Project template for Django projects
MIT License
17 stars 14 forks source link

Cannot pass arguments to fabric tasks #97

Closed sephii closed 3 years ago

sephii commented 3 years ago

Some tasks, such as import-db, can take command-line arguments, for example to specify the path to the dump file to load. But if you check the output of fab --help import-db you’ll see that the task doesn’t seem to accept any argument. That’s caused by the @remote decorator. I guess because the wrapper function takes *args and **kwargs, fabric cannot parse its signature.

I’m not sure if it can be solved. If there’s no other way, we could remove the @remote decorator.

simonbru commented 3 years ago

It seems to work fine on my side:

app@bce716155a72:/code$ fab import-db --help
Usage: fab [--core-opts] import-db [--options] [other tasks here ...]

Docstring:
  Restore the given database dump.

  The dump must be a gzipped SQL dump. If the dump_file parameter is not set,
  the database will be dumped and retrieved from the remote host.

Options:
  -d STRING, --dump-file=STRING
app@bce716155a72:/code$ fab import-db --dump-file something.sql.gz
gzip: something.sql.gz: No such file or directory

I tried this on a new empty project, with Python 3.7.9 and the following dependencies:

apipkg==1.5
appdirs==1.4.4
asgiref==3.3.1
attrs==20.3.0
backcall==0.2.0
bcrypt==3.2.0
black==20.8b1
certifi==2020.12.5
cffi==1.14.4
click==7.1.2
coverage==5.3.1
cryptography==3.3.1
decorator==4.4.2
dj-database-url==0.5.0
dj-email-url==1.0.1
Django==3.1.5
django-debug-toolbar==3.2
django-extensions==3.1.0
dulwich==0.20.3
execnet==1.7.1
fabric==2.5.0
factory-boy==3.2.0
Faker==5.4.0
flake8==3.8.4
flake8-black==0.2.1
flake8-isort==4.0.0
importlib-metadata==3.3.0
iniconfig==1.1.1
invoke==1.5.0
ipdb==0.13.4
ipython==7.19.0
ipython-genutils==0.2.0
isort==5.7.0
jedi==0.18.0
mccabe==0.6.1
mypy-extensions==0.4.3
packaging==20.8
paramiko==2.7.2
parso==0.8.1
pathspec==0.8.1
pexpect==4.8.0
pickleshare==0.7.5
pip-tools==5.5.0
pluggy==0.13.1
prompt-toolkit==3.0.10
psycopg2-binary==2.8.6
ptyprocess==0.7.0
py==1.10.0
pycodestyle==2.6.0
pycparser==2.20
pyflakes==2.2.0
Pygments==2.7.3
PyNaCl==1.4.0
pyparsing==2.4.7
pytest==6.2.1
pytest-cov==2.10.1
pytest-django==4.1.0
pytest-forked==1.3.0
pytest-xdist==2.2.0
python-dateutil==2.8.1
pytz==2020.5
regex==2020.11.13
six==1.15.0
sqlparse==0.4.1
testfixtures==6.17.0
text-unidecode==1.3
toml==0.10.2
traitlets==5.0.5
typed-ast==1.4.2
typing-extensions==3.7.4.3
urllib3==1.26.2
wcwidth==0.2.5
Werkzeug==1.0.1
zipp==3.4.0
sephii commented 3 years ago

Ah yes, the import-db task doesn’t have the @remote decorator (I’m not sure why I had it in my project). Can you try with a task that has the @remote decorator and a parameter, like fab fetch-db --help?

simonbru commented 3 years ago

Oh right, I forgot to check if it was decorated in the template. :man_facepalming:

However I tried with other tasks and it also works:

app@19b4311170d6:/code$ fab --help fetch-db
Usage: fab [--core-opts] fetch-db [--options] [other tasks here ...]

Docstring:
  Dump the database on the remote host and retrieve it locally.

  The destination parameter controls where the dump should be stored locally.

Options:
  -d STRING, --destination=STRING

app@19b4311170d6:/code$ fab --help push-code-update
Usage: fab [--core-opts] push-code-update [--options] [other tasks here ...]

Docstring:
  Synchronize the remote code repository

Options:
  -g STRING, --git-ref=STRING

I added print("git_ref:", git_ref) at the beginning of push_code_update and passed a hash from the CLI:

app@19b4311170d6:/code$ fab prod push-code-update -g 8e0318a41c81ad5eca13a84cb16ae5780cf6bbf0
git_ref: 8e0318a41c81ad5eca13a84cb16ae5780cf6bbf0
...
sephii commented 3 years ago

Nevermind, it was fixed here. Thanks for the investigation!