Skip to content

Commit 4f54823

Browse files
authored
ENH: Add Dockerfile for development inside a container (#1527)
* Add Dockerfile for development inside a container * Use /Users/austin for portability * Put Dockerfile with scripts * Add script for starting development Docker container * Really add script this time * Modify options to create_testenv.sh * Shift while parsing arguments * Update dockerfile to run test suite * Add documentation for docker * Typo
2 parents 082c982 + 7367f20 commit 4f54823

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ _build
2121

2222
# Test artifacts
2323
mcmc.sqlite
24+
25+
# Docker development
26+
notebooks/

CONTRIBUTING.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ There are 4 main ways of contributing to the PyMC3 project (in descending order
1111

1212
# Opening issues
1313

14-
We appreciate being notified of problems with the existing PyMC code. We prefer that issues be filed the on [Gitub Issue Tracker](https://github.com/pymc-devs/pymc3/issues), rather than on social media or by direct email to the developers.
14+
We appreciate being notified of problems with the existing PyMC code. We prefer that issues be filed the on [Gitub Issue Tracker](https://github.com/pymc-devs/pymc3/issues), rather than on social media or by direct email to the developers.
1515

1616
Please verify that your issue is not being currently addressed by other issues or pull requests by using the GitHub search tool to look for key words in the project issue tracker.
1717

1818
# Contributing code via pull requests
1919

20-
While issue reporting is valuable, we strongly encourage users who are inclined to do so to submit patches for new or existing issues via pull requests. This is particularly the case for simple fixes, such as typos or tweaks to documentation, which do not require a heavy investment of time and attention.
20+
While issue reporting is valuable, we strongly encourage users who are inclined to do so to submit patches for new or existing issues via pull requests. This is particularly the case for simple fixes, such as typos or tweaks to documentation, which do not require a heavy investment of time and attention.
2121

2222
Contributors are also encouraged to contribute new code to enhance PyMC's functionality, also via pull requests. Please consult the [PyMC3 documentation](https://pymc-devs.github.io/pymc3/) to ensure that any new contribution does not strongly overlap with existing functionality.
2323

24-
The preferred workflow for contributing to PyMC3 is to fork the [GitHUb repository](https://github.com/pymc-devs/pymc3/), clone it to your local machine, and develop on a feature branch.
24+
The preferred workflow for contributing to PyMC3 is to fork the [GitHUb repository](https://github.com/pymc-devs/pymc3/), clone it to your local machine, and develop on a feature branch.
2525

2626
## Steps:
2727

@@ -33,13 +33,13 @@ The preferred workflow for contributing to PyMC3 is to fork the [GitHUb reposito
3333
$ git clone [email protected]:<your GitHub handle>/pymc3.git
3434
$ cd pymc3-learn
3535
```
36-
36+
3737
3. Create a ``feature`` branch to hold your development changes:
3838

3939
```bash
4040
$ git checkout -b my-feature
4141
```
42-
42+
4343
Always use a ``feature`` branch. It's good practice to never routinely work on the ``master`` branch of any repository.
4444

4545
4. Develop the feature on your feature branch. Add changed files using ``git add`` and then ``git commit`` files:
@@ -63,11 +63,12 @@ We recommended that your contribution complies with the following guidelines bef
6363

6464
* If your pull request addresses an issue, please use the pull request title to describe the issue and mention the issue number in the pull request description. This will make sure a link back to the original issue is created.
6565

66-
* All public methods must have informative docstrings with sample usage presented as doctests when appropriate.
66+
* All public methods must have informative docstrings with sample usage when appropriate.
6767

6868
* Please prefix the title of incomplete contributions with `[WIP]` (to indicate a work in progress). WIPs may be useful to (1) indicate you are working on something to avoid duplicated work, (2) request broad review of functionality or API, or (3) seek collaborators.
6969

70-
* All other tests pass when everything is rebuilt from scratch.
70+
* All other tests pass when everything is rebuilt from scratch. See
71+
[Developing in Docker](#Developing-in-Docker) for information on running the test suite locally.
7172

7273
* When adding additional functionality, provide at least one example script or Jupyter Notebook in the ``pymc3/examples/`` folder. Have a look at other examples for reference. Examples should demonstrate why the new functionality is useful in practice and, if possible, compare it to other methods available in PyMC3.
7374

@@ -104,9 +105,27 @@ tools:
104105
$ autopep8 path/to/pep8.py
105106
```
106107

108+
## Developing in Docker
109+
110+
We have provided a Dockerfile which helps for isolating build problems, and local development.
111+
Install [Docker](https://www.docker.com/) for your operating system, clone this repo, then
112+
run `./scripts/start_container.sh`. This should start a local docker container called `pymc3`,
113+
as well as a [`jupyter`](http://jupyter.org/) notebook server running on port 8888. The repo
114+
will be running the code from your local copy of `pymc3`, so it is good for development. You may
115+
also use it to run the test suite, with
116+
117+
```bash
118+
$ docker exec -it pymc3 bash # logon to the container
119+
$ cd ~/pymc3
120+
$ . ./scripts/test.sh # takes a while!
121+
```
122+
123+
This should be quite close to how the tests run on TravisCI.
124+
125+
107126
## Style guide
108127

109128
Follow [TensorFlow's style guide](https://www.tensorflow.org/versions/master/how_tos/style_guide.html) or the [Google style guide](https://google.github.io/styleguide/pyguide.html) for writing code, which more or less follows PEP 8.
110129

111130

112-
#### This guide was derived from the [scikit-learn guide to contributing](https://github.com/scikit-learn/scikit-learn/blob/master/CONTRIBUTING.md)
131+
#### This guide was derived from the [scikit-learn guide to contributing](https://github.com/scikit-learn/scikit-learn/blob/master/CONTRIBUTING.md)

scripts/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM jupyter/minimal-notebook
2+
3+
MAINTAINER Austin Rochford <[email protected]>
4+
5+
USER $NB_USER
6+
7+
COPY create_testenv.sh /tmp/create_testenv.sh
8+
RUN /bin/bash /tmp/create_testenv.sh --global --no-setup
9+
10+
# matplotlib nonsense
11+
ENV XDG_CACHE_HOME /home/$NB_USER/.cache/
12+
ENV MPLBACKEND=Agg
13+
# Import matplotlib the first time to build the font cache.
14+
RUN python -c "import matplotlib.pyplot"
15+
16+
ENV PYTHONPATH $PYTHONPATH:"$HOME"/pymc3

scripts/create_testenv.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,39 @@
22

33
set -e # fail on first error
44

5+
while test $# -gt 0
6+
do
7+
case "$1" in
8+
--global)
9+
GLOBAL=1
10+
;;
11+
--no-setup)
12+
NO_SETUP=1
13+
;;
14+
esac
15+
shift
16+
done
17+
518
PYTHON_VERSION=${PYTHON_VERSION:-3.5} # if no python specified, use 3.5
619

7-
if [[ "$*" != *--global* ]]
20+
if [ -z ${GLOBAL} ]
821
then
9-
conda create -n testenv --yes pip python=${PYTHON_VERSION}
10-
source activate testenv
22+
conda create -n testenv --yes pip python=${PYTHON_VERSION}
23+
source activate testenv
1124
fi
1225

1326
conda install --yes pyqt=4.11.4 jupyter pyzmq numpy scipy nose matplotlib pandas Cython patsy statsmodels joblib coverage
1427
if [ ${PYTHON_VERSION} == "2.7" ]; then
15-
conda install --yes mock enum34;
28+
conda install --yes mock enum34;
1629
fi
1730

31+
pip install --upgrade pip
1832
pip install tqdm
1933
pip install --no-deps numdifftools
2034
pip install git+https://github.com/Theano/Theano.git
2135
pip install git+https://github.com/mahmoudimus/nose-timer.git
2236

23-
python setup.py build_ext --inplace
37+
if [ -z ${NO_SETUP} ]
38+
then
39+
python setup.py build_ext --inplace
40+
fi

scripts/start_container.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/bash
2+
3+
PORT=${PORT:-8888}
4+
SRC_DIR=${SRC_DIR:-`pwd`}
5+
NOTEBOOK_DIR=${NOTEBOOK_DIR:-$SRC_DIR/notebooks}
6+
7+
docker build -t pymc3 $SRC_DIR/scripts
8+
docker run -d \
9+
-p $PORT:8888 \
10+
-v $SRC_DIR:/home/jovyan/pymc3 \
11+
-v $NOTEBOOK_DIR:/home/jovyan/work/ \
12+
--name pymc3 pymc3

0 commit comments

Comments
 (0)