jump to navigation

Begin with the Ending July 26, 2016

Posted by PythonGuy in Uncategorized.
add a comment

I don’t know what it is, but I’m working on a team now where some people like to write a bunch of code, test it, and then integrate. To me, that feels backwards.

My preferred order is: write a tiny bit of code, integrate that, and then write a lot of code, testing the integration along the way. Unit tests and such often come last, and then only when I’m not able to easily test with integration tests.

The way you do this is through scaffolding. Say you have a client and a server. I would write a minimal server. Then I would write a minimal client. Then I would have the client call the server. After that, members of my team can start working on different features, which means modifying the client and the server to provide that feature.

Writing code this way isn’t a license to be stupid. You still have to think hard about how you want things to work. It does, however, free you from a lot of tedious and unnecessary details when planning. IE, you should be focusing on what messages are passed back and forth, and the general content of those messages, not specific parameters and fields.

Notes on Pip July 26, 2016

Posted by PythonGuy in Uncategorized.
add a comment

Why pip?

Pip manages your python code rather well. It downloads and installs dependencies and makes your python experience almost seamless.

Pip combined with virtualenv is a powerful tool. In fact, I never use the pip installed at /usr/bin/pip/. I always set up a virtualenv and use the pip installed there.

Installing 3rd Party Packages

Pip can take URLs but it usually takes package names of packages on PyPi. You can even specify versions.

Here’s how to do that:

pip install <package name>

If you want a specific version:

pip install <package name>==<version number>

You can install multiple packages at once, too.

But note, you really shouldn’t be installing more than one package. If you’re developing your own package, you shouldn’t be installing anything but your own package.

Installing Your Own Packages

Create a setup.py and layout your code properly. I won’t document that here; you can look elsewhere for instructions. Then run pip to install your package. It will install all your dependencies as well.

pip install -e <directory with setup.py>

If you want to install the test or dev dependencies:

pip install -e <directory with setup.py>[test]
pip install -e <directory with setup.py>[dev]

NOTE: If you are using zsh, you have to quote things properly.

The -e flag puts the files in as symlinks to the original code files. You can modify the files in your project and they will be modified in the installed location.

Bad Practices

  • Not writing a setup.py because you think your code is not a package. All the code you write should be a package.
  • Doing pip freeze > requirements.txt. Just use setup.py and list your dependencies explicitly.
  • Not using virtualenv or similar for each project.