Testing | Coverage | Documentation |
---|---|---|
python_package_template provides an example python project template to quickly setup continuous integration, test coverage reports, and automatic documentation deployment.
The documentation for the package can be found here: https://sisl.github.io/python_package_template.jl/latest
More example code and examples will be added as time permits.
To start off with, look through the package and replace python_package_template
with your own project name.
deps
contains C/C++ file dependencies of the packages which are compiled when
the package is installed by using the BinDeps.jl package.
docs
contains Sphinx documentation which is automatically build from in-code
comments and deployed
python_package_template
contains the python source code of the package. This
folder should be renamed to match your package name.
test
contains unit tests which can be run locally
It is possible to test the package and code locally before commiting the update and triggering a CI build.
First, open a terminal window and navigate to the package root directory and navigate to the package root directory
cd /Stanford/repos/python_package_template
Next, install the requirements needed for testing and running the package
pip3 install -U -r requirements.txt -r test_requirements.txt
From here we can test the package by simply typing in the pytest
command:
pytest
To setup continuous integration for the package we will use Travis-CI. Travis is free to use for open source projects (Thank you Travis!), or for build of private repositories a subscription can be purchased.
To setup continuous integration your repository must contain a .travis.yml
file
AND continuous integration must be enabled for your repository on the TRAVIS CI
webpage. This can be done either for your presonal repositories here:
https://travis-ci.org/account/repositories
or for your organizations' repositories here:
https://travis-ci.org/organizations/YOUR_GITHUB_ORGANIZATION_NAME/repositories
Note: If the project does not appear immediately, you may need to hit the "sync repositories" button to have it appear.
To set up test coverage, go to coveralls.io, login with your github account, and activate the project to add coverage reports.
Note: If the project does not appear immediately, you may need to hit the "sync repositories" button to have it appear.
To setup the automated deployment of documentation as part of the CI build process travis-ci needs to have an access token configured be able to add the documentation.
Follow the travis-sphinx documentation to setup a personal access token for travis to deploy documentation to github pages.
Note: Github has since moved the location where you generate/manage personal access tokens (the travis-sphinx documentation is out of date). You can now generate access tokens from your personal settings at:
Settings -> Developer Settings -> Personal Access Tokens
If you have not already done so, you also need to enable github pages as the deployment end-point which can be done by following step 1 of the documentation for github pages.
- Make an account with the Python Package Index.
- Install the travis-ci command line client so you can encrypt your PyPi account information.
- Uncomment the relevant lines in the
.travis.yml
file - Encrypt your pypi.org username and password for travis by following the procedure here