I’m all about a docs-first approach – for example, in the latest SDK domain-model overhaul I participated in, I was able to contribute to the API’s call signature consistency by commenting early on the technical design docs.
I’m also about testing my code samples as early as possible! And today I found a way to do it in Python; hope it helps other! I’m sure this trick is quite familiar to QA teams, but it was my first time figuring it out (guess I’ve never been so ahead of a release curve as now).
I wanted to test a prerelease branch of an SDK hosted as a python package on Github.
Normally I install this package through pip, like
pip some-sdk. How to install it straight from a GitHub repository branch, where the pre-release code lives?
It’s pretty simple! Use pipenv. For example, say I wanted to install the new-feature-branch branch of https://github.com/some-sdk. In an empty project dir, I can run:
pipenv install -e git+https://github.com/some-sdk.git@new-feature-branch#egg=some-sdk
Where I get the egg from the value of
name in the package’s
Then I just run my sample code using pipenv:
pipenv run python sample_code.py
note I’m aware that pipenv seems to be … not in a terribly healthy place release-wise? But for my limited purposes here, it worked fine. I’m sure you could do something similar with virtualenv, I just haven’t investigated it.
If you’re not getting the results you expect, do some sanity checking:
- are you pulling the branch as you expect? do you see the methods/attributes that you expect from your branch? you can examine your module in your code, for example:
print(dir(somesdk)) #see methods and attributes
pipenv cleanto uninstall anything not specified in Pipfile.lock
- examine your Pipefile.lock. Does the
reqfor your package listed there match the latest commit hash for the branch you want?