Nanny tutorial by example
Nanny is a language-agnostic tool for managing dependencies between your projects. We use Nanny at BackType to manage our internal Java, Clojure, and Python dependencies. Here's a step-by-step tutorial to show you how to use Nanny:
First, you'll want to get Nanny installed and a repository created on a server somewhere. Follow the installation instructions in the README (should only take a few minutes).
Let's create a project and manage it through Nanny:
mkdir /tmp/project1cd /tmp/project1echo "hello world" > hello.txtecho project1 > CHILDecho "cp *.txt \$1" > CHILDMAKERchmod a+x CHILDMAKERnanny push 1.0.0 "first version of project1"
Now, let's create a new project that depends on project1:
mkdir /tmp/project2cd /tmp/project2echo project1 > NANNYnanny deps
If you look in the _deps/project1 folder, you'll see hello.txt there. Notice that _deps/project1 is a symlink to _deps/_actual/project1-1.0.0. You can look in the _deps/_actual folder to see the currently checked out versions of the dependencies.
Let's go back to project1 and create a new version:
cd /tmp/project1echo "HELLO WORLD" > hello.txtnanny push 0.0.9 "more emphatic hello world"
Uh oh, you'll see an error because you can't push an older version to the repository. Let's try again:
nanny push 1.0.1 "more emphatic hello world"
That should work fine. To see the history of a package, use the "history" command:
nanny history project1
This should print out the following:
1.0.1: more emphatic hello world1.0.0: first version of project1
To see more information about a specific version, use the "info" command:
nanny info project1 1.0.1
This prints out:
--------------------------------------------------------------------------Version control logs:--------------------------------------------------------------------------Message: more emphatic hello world--------------------------------------------------------------------------
Nanny automatically tags each version you push with the first 100 lines of "git log" or "svn log". Since these examples aren't version controlled, you won't see any information in the "Version control logs" section.
Let's go back to project2 and pull in the new dependencies:
cd /tmp/project2nanny depscat _deps/project1/hello.txt
This will print out "HELLO WORLD". If you decide you want the older version of project1, you can specify your dependency in the NANNY file with a specific version, i.e.:
echo "project1 1.0.0" > NANNYnanny depscat _deps/project1/hello.txt
This will print out "hello world".
Let's see how Nanny handles transitive dependencies:
echo "lalala" > project2.txtecho project2 > CHILDecho "cp *.txt \$1" > CHILDMAKERchmod a+x CHILDMAKERnanny push 1.0.0 "first version of project2"mkdir /tmp/project3cd /tmp/project3echo "project2" > NANNYnanny deps
This will pull in the latest version of project2 and all dependencies of project2. Dependency resolution continues transitively (dependencies of your dependencies, dependencies of those dependencies, etc.)
Let's see what happens when there's a conflict:
echo "project1project2" > NANNYnanny deps
project2 depends on v1.0.0 of project1, but project3's NANNY file states that it wants the latest version of project 1 (v1.0.1). Nanny resolves conflicts by choosing the latest version, so in this case it chooses v1.0.1 of project1.
That's really all there is to it. As we've seen, all dependency management occurs through three files:
- NANNY - specify dependencies of this project
- CHILD - name the packages created by this project to be used as dependencies by other projects
- CHILDMAKER - a script to package up this project into a dependency
Be sure to check out the README file in the project for more information. You can get more information on all the commands by executing "nanny help". Enjoy!
You can follow me on Twitter at @nathanmarz.
Source: http://tech.backtype.com/nanny-tutorial-by-example
dell computer repair overland park ks computer repair olathe ks computer repair kansas city computer repair lawrence ks

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home