Skip to content

Commit

Permalink
Use pyproject.toml (#631)
Browse files Browse the repository at this point in the history
* Use pyproject.toml. Remove unnecesary files. Improve CI workflows

* name change

* stringify python version

* Take version from a file. Install optional deps from local as well

* Changelog.md -> CHANGELOG.md

* add pydata-sphinx-theme to dependencies

* try to fix test workflow

* lint

* Add 'bash -l {0}' to tests

* [no ci] update contributing.md

* Update CHANGELOG.md

Co-authored-by: Ravin Kumar <[email protected]>

---------

Co-authored-by: Ravin Kumar <[email protected]>
  • Loading branch information
tomicapretto and canyon289 authored Feb 2, 2023
1 parent 07e6f77 commit c610691
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 258 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

30 changes: 15 additions & 15 deletions .github/workflows/publish-docs-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: r-lib/actions/setup-pandoc@v1
- name: Checkout Source
- name: Set up Pandoc
uses: r-lib/actions/setup-pandoc@v1

- name: Checkout source
uses: actions/checkout@v2
with:
# require all of history to see all tagged versions' docs
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.9
# statsmodels is needed to build docs for old releases
- name: Install Dependencies
python-version: "3.10"

- name: Install Bambi and all its dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install statsmodels
python setup.py build
python setup.py install
conda install -c conda-forge python-graphviz
conda install pip
pip install .
pip install .[dev]
pip install .[jax]
- name: Checkout gh-pages
uses: actions/checkout@v2
Expand All @@ -45,7 +45,7 @@ jobs:
sphinx-build docs docs/_build/html
touch docs/_build/html/.nojekyll
- name: Publish Docs to gh-pages
- name: Publish docs to gh-pages
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: peaceiris/actions-gh-pages@bbdfb200618d235585ad98e965f4aafc39b4c501 # v3.7.3
Expand Down
38 changes: 17 additions & 21 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,42 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: r-lib/actions/setup-pandoc@v1
- name: Checkout Source
- name: Set up Pandoc
uses: r-lib/actions/setup-pandoc@v1

- name: Checkout source
uses: actions/checkout@v2
with:
# require all of history to see all tagged versions' docs
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: "3.10"

- name: Install Dependencies
- name: Install Bambi and all its dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
python setup.py build
python setup.py install
conda install -c conda-forge python-graphviz
conda install pip
pip install .
pip install .[dev]
pip install .[jax]
- name: Checkout gh-pages
# As we already did a deploy of gh-pages above, it is guaranteed to be there
# so check it out so we can selectively build docs below
uses: actions/checkout@v2
with:
ref: gh-pages
path: docs/_build/html

- name: Test Build Docs
- name: Test build docs
if: github.ref != 'refs/heads/main' && ! startsWith(github.ref, 'refs/tags')
run: |
BUILDDIR=_build/html/main make -C docs/ local
run: BUILDDIR=_build/html/main make -C docs/ local

- name: Build Docs
- name: Build docs
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')
run: |
sphinx-build docs docs/_build/html
touch docs/_build/html/.nojekyll
- name: Publish Docs to gh-pages
- name: Publish docs to gh-pages
# Only once from main or a tag
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')
# We pin to the SHA, not the tag, for security reasons.
Expand Down
82 changes: 70 additions & 12 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,82 @@ on:
- created

jobs:
deploy:
build:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: "3.8"
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
run: python3 -m pip install --upgrade build

- name: Build
run: python3 -m build

- name: Upload source distribution artifact
uses: actions/upload-artifact@v3
with:
name: artifact
path: dist/*

test:
name: Upload release to test PyPI
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Download source distribution artifact
uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install twine
run: python3 -m pip install --upgrade twine

- name: Publish library
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
run: python3 -m twine upload --skip-existing --repository testpypi dist/*

- name: Test pip install from test.pypi
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
python -m venv venv-test-pypi
venv-test-pypi/bin/python -m pip install --index-url https://test.pypi.org/simple/ bambi
venv-test-pypi/bin/python -c "import bambi; assert bambi.__version__ == '${{ github.ref_name }}'"
publish:
name: Upload release to PyPI
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Download source distribution artifact
uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install twine
run: python3 -m pip install --upgrade twine

- name: Publish library
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: python3 -m twine upload dist/*
24 changes: 14 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:

name: Set up Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Checkout source
uses: actions/checkout@v2
with:
fetch-depth: 0

Expand All @@ -27,15 +28,19 @@ jobs:
python-version: ${{ matrix.python-version }}
auto-update-conda: true

- name: Install dev environment & bambi
- shell: bash -l {0}
run: |
conda info
conda list
- name: Install Bambi and all its dependencies
shell: bash -l {0}
run: |
conda install -c conda-forge python-graphviz
conda install pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -r requirements-optional.txt
pip install .
pip install .[dev]
pip install .[jax]
python --version
conda list
Expand All @@ -44,16 +49,15 @@ jobs:
- name: Run linters
shell: bash -l {0}
run: |
python -m black bambi --check
echo "Success!"
echo "Running black..."
black bambi --check
echo "Checking code style with pylint..."
python -m pylint bambi/
pylint bambi
- name: Run tests
shell: bash -l {0}
run: |
python -m pytest -vv --cov=bambi --cov-report=term --cov-report=xml tests
run: python -m pytest -vv --cov=bambi --cov-report=term --cov-report=xml tests
env:
PYTHON_VERSION: ${{ matrix.python-version }}

Expand Down
1 change: 1 addition & 0 deletions Changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* Moved the `tests` directory to the root of the repository (#607)
* Don't pass `dims` to the response of the likelihood distribution anymore (#629)
* Remove requirements.txt and replace with `pyproject.toml` config file to distribute the package (#631)

### Documentation

Expand Down
24 changes: 15 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,36 @@ Please reasonably document any additions or changes to the codebase, when in dou

1. Fork the [project repository](https://github.com/bambinos/bambi/) by clicking on the 'Fork' button near the top right of the main repository page. This creates a copy of the code under your GitHub user account.

2. Clone your fork of the Bambi repo from your GitHub account to your local disk, and add the base repository as a remote:
1. Clone your fork of the Bambi repo from your GitHub account to your local disk, and add the base repository as a remote:

```bash
git clone [email protected]:<your GitHub handle>/bambi.git
cd bambi
git remote add upstream [email protected]:bambinos/bambi.git
```

3. Create a feature branch (e.g. `my-feature`) to hold your development changes:
1. Create a feature branch (e.g. `my-feature`) to hold your development changes:

```bash
git checkout -b my-feature
```

Always use a feature branch. It's good practice to never routinely work on the `main` 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 run:
1. Install the package in editable mode and its development dependencies.

```bash
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .
pip install .[dev]
```

5. Develop the feature on your feature branch. Add changed files using `git add` and then `git commit` files:
If you're going to develop futures related to JAX, install jax-related dependencies.

```bash
pip install .[jax]
```

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

```bash
git add modified_files
Expand Down Expand Up @@ -117,19 +123,19 @@ We recommend that your contribution complies with the following guidelines befor
- Code coverage **cannot** decrease. Coverage can be checked with **pytest-cov** package:

```bash
pytest --cov=bambi --cov-report=html tests/
pytest --cov=bambi --cov-report=html tests
```

- Your code passes black

```bash
black bambi/
black bambi
```

- Your code passes pylint

```bash
pylint bambi/
pylint bambi
```

**This guide was derived from the [ArviZ guide to contributing](https://github.com/arviz-devs/arviz/blob/master/CONTRIBUTING.md)**
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Alternatively, if you want the bleeding edge version of the package you can inst

### Dependencies

Bambi requires working versions of ArviZ, formulae, NumPy, pandas and PyMC. Dependencies are listed in `requirements.txt`, and should all be installed by the Bambi installer; no further action should be required.
Bambi requires working versions of ArviZ, formulae, NumPy, pandas and PyMC. Dependencies are listed in `pyproject.toml` and should all be installed by the Bambi installer; no further action should be required.

## Example

Expand Down
1 change: 1 addition & 0 deletions bambi/VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.9.3
13 changes: 12 additions & 1 deletion bambi/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
__version__ = "0.9.3"
import os

here = os.path.dirname(os.path.realpath(__file__))


def read_version():
version_file = os.path.join(here, "VERSION.txt")
with open(version_file, encoding="utf-8") as buff:
return buff.read()


__version__ = read_version()
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Bambi is a high-level Bayesian model-building interface written in Python. It wo

Dependencies
============
Bambi is tested on Python 3.8+ and depends on ArviZ, formulae, NumPy, pandas and PyMC (see `requirements.txt <https://github.com/bambinos/bambi/blob/main/requirements.txt>`_ for version information).
Bambi is tested on Python 3.8+ and depends on ArviZ, formulae, NumPy, pandas and PyMC (see `pyproject.toml <https://github.com/bambinos/bambi/blob/main/pyproject.toml>`_ for version information).

Installation
============
Expand Down
Loading

0 comments on commit c610691

Please sign in to comment.