Skip to content

Commit

Permalink
Use Poetry for Managing Dependencies, Tasks, and Package Builds (py-w…
Browse files Browse the repository at this point in the history
…hy#584)

* replace legacy build and dependency systems with poetry

Signed-off-by: Chris Trevino <[email protected]>

* remove style=semver config

Signed-off-by: Chris Trevino <[email protected]>

* update pip install of poetry-dynamic-versioning

Signed-off-by: Chris Trevino <[email protected]>

* pin llvmlite to version used by causalml; update python range accordingly

Signed-off-by: Chris Trevino <[email protected]>

* add note about networkx requirement; remove pandas-stubs, pytest-xdist for futures PRs

Signed-off-by: Chris Trevino <[email protected]>

* update poetry.lock

Signed-off-by: Chris Trevino <[email protected]>

* remove import from _version

Signed-off-by: Chris Trevino <[email protected]>

* PR comments

Signed-off-by: Chris Trevino <[email protected]>

* move sphinx, sphinxscontrib-googleanalytics to poetry

Signed-off-by: Chris Trevino <[email protected]>

* add some missing Sphinx dependencies; ignore generated documentation path

Signed-off-by: Chris Trevino <[email protected]>

* add pandoc dependency for documentation generation

Signed-off-by: Chris Trevino <[email protected]>

* add rpy2 to build-and-publish-docs action

Signed-off-by: Chris Trevino <[email protected]>

* add cuda, r dependencies

Signed-off-by: Chris Trevino <[email protected]>

* use the original image for the docs build

Signed-off-by: Chris Trevino <[email protected]>

* use updated docker image for generating docs

Signed-off-by: Chris Trevino <[email protected]>

* move documentation dependencies into poetry as 'docs' optional

Signed-off-by: Chris Trevino <[email protected]>

Signed-off-by: Chris Trevino <[email protected]>
  • Loading branch information
darthtrevino authored Aug 13, 2022
1 parent eba2c1c commit 2b4832a
Show file tree
Hide file tree
Showing 21 changed files with 4,746 additions and 2,996 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 127
max-complexity = 10
16 changes: 6 additions & 10 deletions .github/workflows/build-and-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ jobs:
build:
runs-on: ubuntu-latest
container:
image: pego/dowhy-examples-notebooks-deps
image: darthtrevino/dowhy-docs
steps:
- uses: actions/setup-python@v2
- uses: actions/checkout@main
with:
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- name: Install dependencies
run: |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-plotting.txt ]; then pip install -r requirements-plotting.txt; fi
pip3 install 'scikit-learn==1.0.2' --force-reinstall
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt --use-deprecated=legacy-resolver; fi
pip install 'numpy<=1.21' --force-reinstall
pip install 'git+https://github.com/petergtz/googleanalytics.git@master'

- name: Install Python Dependencies
run: poetry install -E plotting -E causalml -E docs

- name: Build
run: |
# sphinx-multiversion invokes git internally. Its call to "git rev-parse --show-toplevel" throws the
# following error: "fatal: detected dubious ownership in repository at '/__w/dowhy/dowhy'"
# The following command avoids this.
git config --global --add safe.directory /__w/dowhy/dowhy
./docs/generate_docs.sh
- name: Commit and push to gh-pages branch
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
46 changes: 25 additions & 21 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions


name: DoWhy CI

on:
Expand All @@ -12,39 +10,45 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9]
poetry-version: [1.1.14]

steps:
- uses: actions/checkout@v2

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

- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Install Poetry Dynamic Versioning Plugin
run: pip install poetry-dynamic-versioning

- name: Install graphviz
run: |
sudo apt install graphviz libgraphviz-dev graphviz-dev pkg-config
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-plotting.txt ]; then pip install -r requirements-plotting.txt; fi
pip install 'scikit-learn==1.0.2' --force-reinstall
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt --use-deprecated=legacy-resolver; fi
pip install 'numpy<=1.21' --force-reinstall
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -v -m "not advanced"
- name: Check package consistency with twine
echo "installing poetry dependencies"
poetry install -E plotting -E causalml
- name: Lint
run: poetry run poe lint

- name: Test
run: poetry run poe test

- name: Check package consistency
run: |
python setup.py check sdist bdist_wheel
twine check dist/*
poetry build
poetry run poe verifyPackage
24 changes: 17 additions & 7 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: '3.8'

- name: Install Poetry 1.1.14
uses: abatilo/[email protected]
with:
poetry-version: '1.1.14'

- name: Install Poetry Dynamic Versioning Plugin
run: pip install poetry-dynamic-versioning

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
run: poetry install

- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
poetry-dynamic-versioning
poetry build
poetry run poe uploadPackage
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ instance/

# Sphinx documentation
docs/_build/
dowhy_docs/

# PyBuilder
target/
Expand Down Expand Up @@ -104,6 +105,6 @@ venv.bak/
*.py.swpa

# custom values
docs/source/example_notebooks/causal_model.png
docs/source/example_notebooks/*.png
docs/source/_templates/versions.html
dowhy-docs
10 changes: 0 additions & 10 deletions MANIFEST.in

This file was deleted.

11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

40 changes: 0 additions & 40 deletions azure-pipelines.yml

This file was deleted.

9 changes: 9 additions & 0 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# This dockerfile was used to generate darthtrevino/dowhy-docs, used in the
# build-and-publish-docs.yml workflow
#
FROM pego/dowhy-examples-notebooks-deps

RUN DEBIAN_FRONTEND=noninteractive apt install --yes --quiet curl
RUN curl -sSL https://install.python-poetry.org | python3 -
ENV PATH=$PATH:/root/.local/share/pypoetry/venv/bin
11 changes: 4 additions & 7 deletions docs/generate_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ mv source/conf.py source/conf.py.orig
cp source/conf-rtd.py source/conf.py
cp source/_templates/versions-rtd.html source/_templates/versions.html

PYTHONPATH=$(pwd)/.. sphinx-multiversion --dump-metadata source ${OUTPUT_DIR}

PYTHONPATH=$(pwd)/.. sphinx-multiversion source ${OUTPUT_DIR}
poetry run sphinx-multiversion --dump-metadata source ${OUTPUT_DIR}
poetry run sphinx-multiversion source ${OUTPUT_DIR}

mv source/conf.py.orig source/conf.py

cp source/_templates/versions-pydata.html source/_templates/versions.html

PYTHONPATH=$(pwd)/.. sphinx-multiversion --dump-metadata source ${OUTPUT_DIR}

PYTHONPATH=$(pwd)/.. sphinx-multiversion source ${OUTPUT_DIR}
poetry run sphinx-multiversion --dump-metadata source ${OUTPUT_DIR}
poetry run sphinx-multiversion source ${OUTPUT_DIR}

STABLE_VERSION=$(git describe --tags --abbrev=0 --match='v*')

Expand Down
6 changes: 5 additions & 1 deletion docs/update_docs.sh
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
sphinx-apidoc -f -o source ../dowhy
#!/bin/bash -ex

cd $( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

poetry run sphinx-apidoc -f -o source ../dowhy
7 changes: 5 additions & 2 deletions dowhy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
from dowhy.causal_model import CausalModel
from . import _version

logging.getLogger(__name__).addHandler(logging.NullHandler())

__version__ = _version.get_versions()["version"]
#
# 0.0.0 is standard placeholder for poetry-dynamic-versioning
# any changes to this should not be checked in
#
__version__ = "0.0.0"
Loading

0 comments on commit 2b4832a

Please sign in to comment.