|
From: | Bob Gustafson |
Subject: | Re: [Fab-user] Not having much luck with your initial examples. |
Date: | Sat, 24 Nov 2018 13:27:01 -0600 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 |
Hi Nick If you are really serious about pushing corrections to the
Fabric/Python documentation, you could just grab a random fabric
'Getting Started' page and look at the first code line (more or
less like I did below). Since there are so many variations (2
pythons X 3 Fabrics = 6 possible starting points), just
specifying the environment of the first 'Hello World' example
would be a big help. This is not so easy. With two possibilities of python and three possibilities of the fabric library, there are six combinations of starting points before the '>>> from fabric import Connection' line. The documentation for fabric is quite good looking. However,
looking at Fabric Overview and Tutorial (http://docs.fabfile.org/en/1.14/tutorial.html),
the 5th line into that document recommends looking at the 'usage
documentation' (http://docs.fabfile.org/en/1.14/index.html#usage-docs).
This is a short page and on the 4th line it recommends looking
at the Overview and Tutorial (http://docs.fabfile.org/en/1.14/tutorial.html),
which of course is the page I just came from. This 'going in
circles' is a metaphor for a lot of the fabric documentation. ---------- Ok, I'm cheating now. I talked with my son for awhile this morning. He has several remote deployments going in Europe - all using Fabric. I mentioned that when I put in the @task decorator as you had recommended, I got an error complaining about "TypeError: Tasks must have an initial Context argument!". This was a new error for me!!! My son explained that I needed a few lines at the top of the fabfile.py to define the environment 'Context' where the command (hello world) will execute. I said I already was using virtualenv and had the (env) in front of my shell prompt. He said that the 'env' I was using was just for Python, not
for Fabric. Fabric needs an *Additional* environment ('Context')
set up. In the Getting Started document, there is no mention of
'Context' prior to the first code line. With that new clue, I scrambled off into Google with a new
series of searches - looking for 'Context' in combination with
fabric, python, etc. I found a different Overview and Tutorial (http://docs.fabfile.org/en/1.4.1/tutorial.html). There was a warning bar saying that I was not viewing the latest version - I should get 1.12.1 - which I did. This much newer Overview and Tutorial looked quite familiar
(http://docs.fabfile.org/en/1.12.1/tutorial.html) but it is not
quite the same as the 1.14 referenced above. The first code lines, to be typed into fabfile.py: def hello(): of course do not work: (env) air:fabric-test bobgus$ fab helloNo idea what 'hello' is! Ok, I can put in the @task decorator as you suggested
initially @task(env) air:fabric-test bobgus$ fab hello ... NameError: name 'task' is not defined Ok, we have seen that before. By now (after days...) I know that @task must be imported. I can add the line "from fabric.api import task" above the @task line.
This doesn't work either (env) air:fabric-test bobgus$ fab hello... ModuleNotFound: No module named 'fabric.api' I have seen that error before too. It means I am trying to
execute Fabric <2 code with Fabric 2+ library. I can change the import statement to: "from fabric import task" But then I get another series of errors: (env) air:fabric-test bobgus$ fab hello... IndexError: pop from empty list During handling of the above exception, another exception occurred: ... TypeError: Tasks must have an initial Context argument! ---------------------------------------------------------------------------------- It suggests using a dummy argument to fool Fabric into doing the right thing... So, I change my code to:
And, presto, I get a 'correct' output: (env) air:fabric-test bobgus$ fab helloHello world! Even though I get the correct answer, I don't think this is really the correct approach. I haven't put in any Context definition, I just put in some characters that don't refer to anything else (unless the word 'dummy' is a reserved word in the Fabric/Python world). I think the discussion has moved from incomplete documentation to buggy code. Sincerely, Bob Gustafson On 11/23/18 4:46 PM, Nick Timkovich wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |