Skip to content

Commit

Permalink
Add Python packaging framework
Browse files Browse the repository at this point in the history
This was based on the cookiecutter template ionelmc/pylibrary,
but simplified!
  • Loading branch information
jonc125 committed May 21, 2018
1 parent 1fc4fb3 commit b7925e0
Show file tree
Hide file tree
Showing 23 changed files with 542 additions and 5 deletions.
20 changes: 20 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = True

[bumpversion:file:setup.py]
search = version='{current_version}'
replace = version='{new_version}'

[bumpversion:file:README.rst]
search = v{current_version}.
replace = v{new_version}.

[bumpversion:file:docs/conf.py]
search = version = release = '{current_version}'
replace = version = release = '{new_version}'

[bumpversion:file:tlo/__init__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'
15 changes: 15 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[paths]
source =
tlo

[run]
branch = true
source =
tlo
tests
parallel = true

[report]
show_missing = true
precision = 2
omit = *migrations*
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# see http://editorconfig.org
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
charset = utf-8

[*.{bat,cmd,ps1}]
end_of_line = crlf
34 changes: 34 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
language: python
sudo: false
cache: pip
env:
global:
- LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
- SEGFAULT_SIGNALS=all
matrix:
- TOXENV=check
- TOXENV=docs
matrix:
include:
- python: '3.6'
env:
- TOXENV=py36,report
before_install:
- python --version
- uname -a
- lsb_release -a
install:
- pip install tox
- virtualenv --version
- easy_install --version
- pip --version
- tox --version
script:
- tox -v
after_failure:
- more .tox/log/* | cat
- more .tox/*/log/* | cat
notifications:
email:
on_success: never
on_failure: always
15 changes: 15 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
graft docs
graft src
graft ci
graft tests

include .bumpversion.cfg
include .coveragerc
include .cookiecutterrc
include .editorconfig

include README.rst

include tox.ini .travis.yml

global-exclude *.py[cod] __pycache__ *.so *.dylib
5 changes: 0 additions & 5 deletions README.md

This file was deleted.

66 changes: 66 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
========
Overview
========

.. start-badges
.. image:: https://travis-ci.com/UCL/TLOmodel.svg?branch=master
:alt: Travis-CI Build Status
:target: https://travis-ci.com/UCL/TLOmodel

.. end-badges
Thanzi la Onse Epidemiology Model
=================================

This is the main software framework for epidemiology and health system modelling in the Thanzi la Onse project.

See https://www.york.ac.uk/igdc/research/thanzi-la-onse/ for more about the project.

Installation
============

To get started quickly, we recommend using Anaconda Python, and installing within a fresh environment.

::

conda create -n tlo python=3.6 virtualenv
source activate tlo
pip install -r requirements/dev.txt
pip install -e .

This will install the software in 'editable' mode, so any changes you make to the source will immediately be reflected.
After the initial install, each time you wish to use the model simply activate the environment::

source activate tlo

Documentation
=============

To build the documentation, activate your environment as above then run::

tox -e docs

Development
===========

To run all the tests run::

tox

Note, to combine test coverage data from all the tox environments run:

.. list-table::
:widths: 10 90
:stub-columns: 1

- - Windows
- ::

set PYTEST_ADDOPTS=--cov-append
tox

- - Other
- ::

PYTEST_ADDOPTS=--cov-append tox
5 changes: 5 additions & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

Authors
=======

* Jonathan Cooper - http://iris.ucl.ac.uk/iris/browse/profile?upi=JCOOP83
53 changes: 53 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os


extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx.ext.extlinks',
'sphinx.ext.ifconfig',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
]
if os.getenv('SPELLCHECK'):
extensions += 'sphinxcontrib.spelling',
spelling_show_suggestions = True
spelling_lang = 'en_GB'

source_suffix = '.rst'
master_doc = 'index'
project = 'TLOmodel'
year = '2018'
author = 'Jonathan Cooper'
copyright = '{0}, {1}'.format(year, author)
version = release = '0.1.0'

pygments_style = 'trac'
templates_path = ['.']
extlinks = {
'issue': ('https://github.com/UCL/TLOmodel/issues/%s', '#'),
'pr': ('https://github.com/UCL/TLOmodel/pull/%s', 'PR #'),
}
# on_rtd is whether we are on readthedocs.org
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

if not on_rtd: # only set the theme if we're building docs locally
html_theme = 'sphinx_rtd_theme'

html_use_smartypants = True
html_last_updated_fmt = '%b %d, %Y'
html_split_index = False
html_sidebars = {
'**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'],
}
html_short_title = '%s-%s' % (project, version)

napoleon_use_ivar = True
napoleon_use_rtype = False
napoleon_use_param = False
73 changes: 73 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
============
Contributing
============

We'll flesh out the guidelines here further as the project gets going!

Bug reports
===========

When `reporting a bug <https://github.com/UCL/TLOmodel/issues>`_ please include:

* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting.
* Detailed steps to reproduce the bug.

Development
===========

To set up `TLOmodel` for local development:

1. Fork `TLOmodel <https://github.com/UCL/TLOmodel>`_
(look for the "Fork" button).
If you have write access to this main repository, you can skip this step and clone
it directly in step 2.
2. Clone your fork locally::

git clone [email protected]:your_name_here/TLOmodel.git

3. Create a branch for local development::

git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

4. When you're done making changes, run all the checks, doc builder and spell checker with `tox <http://tox.readthedocs.io/en/latest/install.html>`_ one command::

tox

5. Commit your changes and push your branch to GitHub::

git add .
git commit # Write a description of your changes in the editor and save
git push origin name-of-your-bugfix-or-feature

6. Submit a pull request through the GitHub website.

Pull Request Guidelines
-----------------------

If you need some code review or feedback while you're developing the code just make the pull request.

For merging, you should:

1. Include passing tests (run ``tox``) [1]_.
2. Update documentation when there's new API, functionality etc.
3. Add a note to ``CHANGELOG.rst`` about the changes.
4. Add yourself to ``AUTHORS.rst``.

.. [1] If you don't have all the necessary python versions available locally you can rely on Travis - it will
`run the tests <https://travis-ci.com/UCL/TLOmodel/pull_requests>`_ for each change you add in the pull request.
It will be slower though ...
Tips
----

To run a subset of tests::

tox -e py36 -- pytest -k test_myfeature

To run all the test environments in *parallel* (you need to ``pip install detox``)::

detox
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
========
Contents
========

.. toctree::
:maxdepth: 2

readme
installation
usage
reference/index
contributing
authors

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

17 changes: 17 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
============
Installation
============

To get started quickly, we recommend using Anaconda Python, and installing within a fresh environment.

::

conda create -n tlo python=3.6 virtualenv
source activate tlo
pip install -r requirements/dev.txt
pip install -e .

This will install the software in 'editable' mode, so any changes you make to the source will immediately be reflected.
After the initial install, each time you wish to use the model simply activate the environment::

source activate tlo
1 change: 1 addition & 0 deletions docs/readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../README.rst
7 changes: 7 additions & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Reference
=========

.. toctree::
:glob:

tlo*
9 changes: 9 additions & 0 deletions docs/reference/tlo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tlo
===

.. testsetup::

from tlo import *

.. automodule:: tlo
:members:
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx>=1.3
sphinx-rtd-theme
-e .
11 changes: 11 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
builtin
builtins
classmethod
staticmethod
classmethods
staticmethods
args
kwargs
callstack
Changelog
Indices
9 changes: 9 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=====
Usage
=====

To use TLOmodel in a project::

import tlo

More to come...
Loading

0 comments on commit b7925e0

Please sign in to comment.