Skip to content

Update contributing guide, fail fast #4280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/arviz_compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
pytest:
strategy:
matrix:
python-version: ["3.8"]
os: [ubuntu-18.04]
floatx: [float64]
test-subset:
- pymc3/tests/test_sampling.py
fail-fast: false
runs-on: ${{ matrix.os }}
env:
TEST_SUBSET: ${{ matrix.test-subset }}
Expand All @@ -34,12 +34,19 @@ jobs:
hashFiles('environment-dev.yml') }}
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: testenv
activate-environment: pymc3-dev
channel-priority: strict
environment-file: environment-dev.yml
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
- run: |
conda activate testenv
- name: Install pymc3
run: |
conda activate pymc3-dev
pip install -e .
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably good to check this works, in case there are any errors in setup.py - it only takes about 5 seconds during CI anyway

- name: Install latest arviz
run: |
conda activate pymc3-dev
conda remove arviz -y
pip install git+git://github.com/arviz-devs/arviz.git
- name: Run tests
run: |
python -m pytest -vv --cov=pymc3 --cov-report=xml --cov-report term --durations=50 $TEST_SUBSET
13 changes: 9 additions & 4 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
pytest:
strategy:
matrix:
python-version: ["3.6"]
os: [ubuntu-18.04]
floatx: [float32, float64]
test-subset:
Expand Down Expand Up @@ -54,6 +53,7 @@ jobs:
pymc3/tests/test_distributions.py
pymc3/tests/test_gp.py
pymc3/tests/test_sampling.py
fail-fast: false
runs-on: ${{ matrix.os }}
env:
TEST_SUBSET: ${{ matrix.test-subset }}
Expand All @@ -74,12 +74,17 @@ jobs:
hashFiles('environment-dev.yml') }}
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: testenv
activate-environment: pymc3-dev
channel-priority: strict
environment-file: environment-dev.yml
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
- run: |
conda activate testenv
- name: Install-pymc3
run: |
conda activate pymc3-dev
pip install -e .
- name: Run tests
run: |
conda activate pymc3-dev
python -m pytest -vv --cov=pymc3 --cov-report=xml --cov-report term --durations=50 $TEST_SUBSET
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
37 changes: 13 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@ The preferred workflow for contributing to PyMC3 is to fork the [GitHub reposito
3. Create a ``feature`` branch to hold your development changes:

```bash
$ git checkout -b my-feature
$ git switch -c my-feature
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git's new way of switching branches - git checkout still works, but this is meant to be more intuitive to beginners

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this creates a new branch too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, -c for "create"

```

Always use a ``feature`` branch. It's good practice to never routinely work on the ``master`` branch of any repository.

4. Project requirements are in ``requirements.txt``, and libraries used for development are in ``requirements-dev.txt``. To set up a development environment, you may (probably in a [virtual environment](https://docs.python-guide.org/dev/virtualenvs/)) run:
4. Project requirements are in ``requirements.txt``, and libraries used for development are in ``requirements-dev.txt``. The easiest (and recommended) way to set up a development environment is via [miniconda](https://docs.conda.io/en/latest/miniconda.html):

```bash
$ pip install -r requirements.txt
$ conda env create -f environment-dev.yml
$ conda activate pymc3-dev
$ pip install -e .
```

_Alternatively_ you may (probably in a [virtual environment](https://docs.python-guide.org/dev/virtualenvs/)) run:

```bash
$ pip install -e .
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this includes all the requirements.txt already + gives a local editable install

$ pip install -r requirements-dev.txt
```

Alternatively, there is a script to create a docker environment for development. See: [Developing in Docker](#Developing-in-Docker).
Yet another alternative is to create a docker environment for development. See: [Developing in Docker](#Developing-in-Docker).

5. Develop the feature on your feature branch. Add changed files using ``git add`` and then ``git commit`` files:

Expand Down Expand Up @@ -103,26 +111,7 @@ tools:
$ pytest --cov=pymc3 pymc3/tests/<name of test>.py
```

* No `pyflakes` warnings, check with:

```bash
$ pip install pyflakes
$ pyflakes path/to/module.py
```

* No PEP8 warnings, check with:

```bash
$ pip install pycodestyle
$ pycodestyle path/to/module.py
```

* AutoPEP8 can help you fix some of the easy redundant errors:

```bash
$ pip install autopep8
$ autopep8 path/to/pep8.py
```
* No `pre-commit` errors: see the [Python code style](https://github.com/pymc-devs/pymc3/wiki/PyMC3-Python-Code-Style) and [Jupyter Notebook style](https://github.com/pymc-devs/pymc3/wiki/PyMC's-Jupyter-Notebook-Style) page from our Wiki on how to install and run it.

## Developing in Docker

Expand Down
19 changes: 3 additions & 16 deletions environment-dev.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
name: testenv
name: pymc3-dev
channels:
- conda-forge
- defaults
dependencies:
- python>=3.6
- python=3.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting conflicts when I removed that, made an environment with Python 3.7, and then updated from the file, see #4281

I think we should maybe make three different environment files: environment-dev-py36.yml, environment-dev-py37.yml, and environment-dev-py38.yml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just tried that, and it works fine (no conflicts!), so that's what I've pushed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's necessary. Can't we pin 38 here instead?

Copy link
Contributor Author

@MarcoGorelli MarcoGorelli Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in, pin 3.8 here and then run the tests using that?

could do, but I would've thought it would be better to run the tests on the earliest supported version of Python, else someone could accidentally use something modern (e.g. the walrus operator), tests pass, but then pymc3 breaks when people install it using Python3.6. On the other hand, if the tests pass on Python3.6, it's far less likely that they'll break on Python3.8

Like this, the full test suite can be run with environment-dev-py36.yml, the arviz compatitiblity tests with environment-dev-py38.yml, and hopefully most bases will be covered

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so dev is used to specify the GH action env?

I was thinking this is for people who want to set up a dev environment locally. I suppose it can be both in which case your suggestion of having different envs for different python versions would make sense.

Copy link
Contributor Author

@MarcoGorelli MarcoGorelli Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that's right - check .github/workflows/pytest.yml

      - uses: conda-incubator/setup-miniconda@v2
        with:
          activate-environment: pymc3-dev-py36
          channel-priority: strict
          environment-file: conda-envs/environment-dev-py36.yml
          use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!

(on master it's currently environment-dev.yml)

- arviz>=0.9
- theano-pymc==1.0.11
- numpy>=1.13
- scipy>=0.18
- pandas >=0.18
- pandas>=0.18
- patsy>=0.5
- fastprogress>=0.2
- h5py>=2.7
- typing-extensions>=3.7
- bokeh>=0.12
- coverage>=5.1
- python-graphviz
- ipython>=7.16
- nbsphinx>=0.4
- nose>=1.3
- nose-parameterized>=0.6
- numpydoc>=0.9
- pre-commit>=2.8.0
- pytest-cov>=2.5
- pytest>=3.0
- recommonmark>=0.4
- seaborn>=0.8
- sphinx-autobuild>=0.7
- sphinx>=1.5
Copy link
Contributor Author

@MarcoGorelli MarcoGorelli Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to have all these documentation-related dependencies in here or can they be removed? I don't know how the docs are built, but maybe these could live in a separate environment-docs.yml environment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can move these to a separate env file, but shouldn't just drop them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - ended up putting them back an, as they don't take up much extra time anyway, all I've removed now are some nose/unittest-related ones (which shouldn't be necessary any more, given that pytest is used?), and some (bokeh and seaborn) which are only used in a handful of notebooks

- watermark
- parameterized
- ipywidgets
- dataclasses # python_version < 3.7
- contextvars # python_version < 3.7
- mkl-service
Expand Down