DevKey Documentation Release 0.1 Colm O Connor March 23, 2015
Contents 1 Quickstart 3 2 FAQ 5 3 Release Notes 7 i
ii
DevKey Documentation, Release 0.1 Github PyPI Contents 1
DevKey Documentation, Release 0.1 2 Contents
CHAPTER 1 Quickstart Step 1: Install like so: sudo pip install projectkey Step 2: Create a key.py file in the root folder of your project like this: #!/usr/bin/python """Yourproject development environment commands.""" from projectkey import cd, run, run_return, runnable def runserver(): """Run django debug web server on port 8080.""" print "Running webserver..." # Run simple shell commands run("./venv/bin/python manage.py runserver_plus 8080 --traceback --settings=yourproject.special_s def upgrade(): """pip upgrade on all packages and freeze to requirements afterwards.""" # Copy and paste whole bash scripts if you like... run("""./venv/bin/pip freeze --local grep -v ^\-e cut -d = -f 1 xargs./venv/bin/pip instal./venv/bin/pip freeze >./requirements.txt """) def smtp(): """Run development smtp server on port 25025.""" print "Running SMTP server..." run("python -m smtpd -n -c DebuggingServer localhost:25025") def striptrailingwhitespace(): """strip the trailing whitespace from all files in your mercurial repo.""" # Get the output of shell commands... repofiles = run_return("hg locate *.py").split( \n ) #...and write simple, short, python scripts to do stuff with it. repofiles.remove( ) for filename in repofiles: with open(filename, r ) as fh: new = [line.rstrip() for line in fh] with open(filename, w ) as fh: [fh.write( %s\n % line) for line in new] def inspectfile(*filenames): """Inspect file(s) for pylint violations.""" # You can also change to the directory that the k command was run from, if you need that. 3
DevKey Documentation, Release 0.1 cd(cwd) run("{0}/venv/bin/pylint --rcfile={0}/pylintrc -r n {1}".format(KEYDIR,.join(filenames))) # Add this and you can run the file directly (e.g. python key.py smtp) as well as by running "k smtp" runnable( name ) Step 3: Run the k command in any folder in your project: $ k inspectfile onefile.py twofiles.py [ Runs pylint on those files ] Step 4: Add more commands. 4 Chapter 1. Quickstart
CHAPTER 2 FAQ What problem is this intended to solve? It is mainly intended to cut down these types of unnecessary team interactions: Can you Skype me the command to run lint using our config file? How do you run a test again? I keep forgetting. What s the exact command to run a development web server? I tried but it isn t working for me. You mean we actually do have a script to deploy docker? Where?? How do I run it? Are you sure the instructions on the wiki work? They re three years old. Help! My git repo is broken again! I don t really understand git and I think I might have used a command wrongly. It should also save you keystrokes for commonly run sets of commands on your own projects. Why do I need ProjectKey? I already have ant/fabric/nose/salt/ansible/docker/fabric ProjectKey is not a tool intended to replace these tools. It is a tool that is supposed to invoke all of these tools and more. Ok I installed it. What kind of commands do I write with it? Anything you like, but here s the kind of commands I created with it: Set up [development testing staging live] environments Run various lint tools Run tests Generate documentation Run builds Create skeleton code. Dump/load data from the database. Upgrade dependencies Upload or sync files. Tail logs on production. ssh into production servers. Run deployment scripts. 5
DevKey Documentation, Release 0.1 Perform common pulling/pushing/merging/rebasing workflows. Common interaction tasks with docker/vagrant/ansible/puppet/etc. Why is the script called k and not projectkey? Because you will probably be running it a lot. A one letter command means fewer keystrokes to wear you and your keyboard out. Is this just for python projects? No, you can use it on any project, you just have to create the commands in python (or translate shell commands). You don t even really need to know python to use this. Just use the template from quickstart. I already have a bunch of shell scripts. Why should I use this? Great! You can unite them in one place, and: 1. All of your project commands get united under one easy to use, discoverable, self documenting file that anybody on your team can invoke up with one key. 2. It can be run even if you are six levels deep inside of your project. 3. You can translate almost any line in your bash script to use this self.sc( your command here ) so it s not hard to switch. 4. You can use a programming language that doesn t suck to write some of the more complex automation tasks. Shouldn t I install this in a virtualenv? You can, but I wouldn t. I would install it on your system python and write commands for each individual project key that understand the virtualenv that your project runs in. It has one dependency, so it is unlikely to cause conflicts with other packages installed on your system python. 6 Chapter 2. FAQ
CHAPTER 3 Release Notes 0.5 sudo pip install now sets up argument completion automagically. 0.4 Made the default starting directory the directory that the key file is in. 0.3 Made the key file directly runnable with the runnable( name ) command. 0.2 Made ProjectKey a module function based runner rather than a class method based runner. 0.1.1 Fixed bug caused by missing docstring. 0.1 Initial release 7