Github/Packaging
From charlesreid1
Also see: Github
Overview
This page covers the basic components of a Github package that is bundled up and released on a regular basis. These components are:
- Testing
- Releases
- Branches
- Issues
- Bots (for maintenance/other)
Testing
Continuous integration testing is essential for ensuring consistent behavior of any package. If a package is open source, Travis can be used to run tests for free. To do this you have to:
- Create a test directory
- Write tests
- Drop a travis.yml file to tell Travis how to run tests
- Register/set up your project with Travis
Writing Tests
This mainly consists of defining a subdirectory within the package that is an importable package itself. The folder should probably be called tests/
and should have an __init__.py
(even if empty) to make the tests importable. Likewise, if other parts of the module are in subdirectories that also have __init__.py
files, these can be imported like this:
Directory structure:
spam/ __init__.py foo.py eggs/ __init__.py bar.py tests/ __init__.py test_spam.py test_eggs.py
The test of the top-level spam component foo.py:
import pytest from spam.foo import foo_widget1 from spam.foo import foo_widget2 def test_foo_widget1() # do some test of foo_widget1 1+1 def test_foo_widget2() # do some test of foo_widget2 2+2 if __name__=="__main__": pytest.main([__file__])
Next, the test of the deeper-level spam.eggs module's bar.py functionality:
import pytest from spam.eggs.bar import bar_widget1 from spam.eggs.bar import bar_widget2 def test_bar_widget1() # do some test of bar_widget1 here 1+1 def test_foo_widget2() # do some test of bar_widget2 here 2+2 if __name__=="__main__": pytest.main([__file__])
Now, these tests can be run using Travis.
Releases
Tagging is the process of picking a particular state of the repo, and creating a git tag with a version number.
Branches
This is mostly a git thing, but maintaining multiple branches to aid development requires some care and forethought. This basically requires the use of git patterns.
Issues
Some of the things you want to do for issues include:
- Create useful labels for categorizing issues
- Create bots that label, comment on, or close issues