Skip to content

Commit

Permalink
Merge pull request #141 from bhosale2/101_poetry_setup
Browse files Browse the repository at this point in the history
Poetry setup for PyElastica (#101)
  • Loading branch information
skim0119 authored Jul 19, 2022
2 parents c3f4c5a + 973eb80 commit bea4153
Show file tree
Hide file tree
Showing 22 changed files with 1,675 additions and 267 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exclude_lines =
def __repr__
from
import
show_missing = true

[run]
branch = True
Expand All @@ -20,6 +20,7 @@ omit =
elastica/systems/analytical.py
# omit deprecation warning message
elastica/_elastica_numpy.py
elastica/_elastica_numba.py
# omit experimental modules
elastica/experimental/*
setup.py
18 changes: 7 additions & 11 deletions .github/workflows/ci-sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3.1.0
- name: Setup Poetry
uses: Gr1N/setup-poetry@v7
with:
python-version: "3.x"
poetry-preview: false
- name: Export requirements file for sphinx
run: |
poetry export -E docs --without-hashes -f requirements.txt --output docs/requirements.txt
- name: Sphinx Build
# You may pin to the exact commit or the version.
Expand All @@ -36,10 +38,4 @@ jobs:
# The folder containing your sphinx docs.
docs-folder: docs/
# The command used to build your documentation.
build-command: make html SPHINXOPTS+="-W --keep-going" # -n"
# Run before the build command, you can use this to install system level dependencies, for example with "apt-get update -y && apt-get install -y perl"
pre-build-command: |
pwd
python --version
pip install -r requirements.txt
pip install -r docs/requirements.txt
build-command: make html #"-W --keep-going" # -n"
144 changes: 73 additions & 71 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,112 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push request
# events for the master branch, and pull request events for all branches.
on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]
# Controls when the action will run.
on: [push, pull_request]
# Older settings:
# Triggers the workflow on push request events for the master branch,
# and pull request events for all branches.
#on:
# push:
# branches: [ master ]
# pull_request:
# branches: [ '**' ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }} #ubuntu-latest

runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-latest] #, windows-latest] # Run macos tests if really required, since they charge 10 times more for macos
python-version: [3.6, 3.7, 3.8]

include:
- os: ubuntu-latest
path: ~/.cache/pip
- os: macos-latest
path: ~/Library/Caches/pip
# - os: windows-latest
# path: ~\AppData\Local\pip\Cache
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Ref: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v2.2.2
with:
python-version: ${{ matrix.python-version }}

# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"

# Cache the pip requirmenets for other tests. If requirements cached use them to speed up the build.
# Ref: /~https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Cache pip Linux
uses: actions/cache@v2
if: startsWith(runner.os, 'Linux')
# Install Poetry and dependencies
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Set up cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache pip MacOS
uses: actions/cache@v2
if: startsWith(runner.os, 'macOS')
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
# Runs a single command using the runners shell
- name: Welcome message
run: echo Hello, world! Welcome PyElastica Build, lets start testing!
# Run style checks (black and flake8)
- name: Run style checks
run: |
make check-codestyle
# Test PyElastica using pytest
- name: Run tests
run: |
make test
report-coverage: # Report coverage from python 3.8 and mac-os. May change later
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8"]
os: [macos-latest]
include:
- os: macos-latest
path: ~/Library/Caches/pip
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.2.2
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache pip Windows
uses: actions/cache@v2
if: startsWith(runner.os, 'Windows')
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Set up cache
uses: actions/cache@v3
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
echo update pip
python -m pip install --upgrade pip
echo update requirments
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
echo update test requirements
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi
# Runs a single command using the runners shell
- name: Welcome message
run: echo Hello, world! Welcome PyElastica Build, lets start testing!

# Formatting test with black and flake8
- name: Black and Flake8 formatting tests
poetry config virtualenvs.in-project true
poetry install
- name: Run style checks
run: |
if [[ "${{ matrix.python-version }}" == "3.6" ]]; then
black --version
black --check elastica tests
flake8 --version
flake8 elastica tests
fi
# Set environment variables for coverage test. Coverage test is done using python 3.6
make check-codestyle
# Set environment variables for coverage test.
# For the coverage test we disable numba jit compilation, since it prevents generating coverage data.
- name: Set environment variables for coverage test
run: |
if [[ "${{ matrix.python-version }}" == "3.6" ]]; then
echo "NUMBA_DISABLE_JIT=1" >> $GITHUB_ENV
fi
# Test Pyelastica using pytest
echo "NUMBA_DISABLE_JIT=1" >> $GITHUB_ENV
- name: Test PyElastica using pytest
if: startsWith(runner.os, 'macOS')
run: |
if [[ "${{ matrix.python-version }}" == "3.6" ]]; then
python3 -m pytest --cov=elastica --cov-report=xml
codecov
else
python3 -m pytest
fi
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
poetry run pytest -c pyproject.toml --cov=elastica --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 4 additions & 3 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ jobs:
uses: actions/setup-python@v3.1.0
with:
python-version: "3.x"
- name: Install Poetry
uses: snok/install-poetry@v1.3
- name: Build
run: |
python setup.py sdist
ls dist
poetry build
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
File renamed without changes.
42 changes: 28 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,37 @@ The following is a set of guidelines for contributing to PyElastica. These are m

## Before I get started

### Installation and packages
### Setup development environment

Below are steps of how to setup development environment. We mainly use `poetry` to manage
the project, although most of the important commands will be provided in `Makefile`.

1. Clone!

First **create the fork repository and clone** to your local machine.
We provide [requirements.txt](requirements.txt) to include all the dependencies.

2. Virtual python workspace: `conda`, `pyenv`, or `venv`.

We recommend using python version above 3.8.0.

```bash
conda create --name pyelastica-dev
conda activate pyelastica-dev
conda install python==3.8
```

3. Setup [`poetry`](https://python-poetry.org) and `dependencies`!

```bash
$ pip install -r requirements.txt
make poetry-download
make install
```

> **Note:** Make sure that **PyElastica** is not installed using pip.
If you are planning to contribute on documentation, extra dependencies can be installed
using `poetry install -E docs`. The detail instruction is included
[here](/~https://github.com/GazzolaLab/PyElastica/blob/master/docs/README.md).

4. Now your working environment is set!

### Project workflow

Expand Down Expand Up @@ -116,7 +138,7 @@ Please follow these steps to have your contribution considered by the maintainer
In order to run pytest, run the following line from the top directory:

`
python3 -m pytest
make test
`

3. After you submit your pull request, verify that all status checks are passing <details><summary>What if the status checks are failing?</summary>If a status check is failing, and you believe that the failure is unrelated to your change, please leave a comment on the pull request explaining why you believe the failure is unrelated. A maintainer will re-run the status check for you. If we conclude that the failure was a false positive, then we will open an issue to track that problem with our status check suite.</details>
Expand All @@ -139,17 +161,9 @@ Ask any question about **how to use PyElastica and detail implementation** in th

We use [flake8](https://pypi.org/project/flake8/) and [Black](https://pypi.org/project/black/) for python style.

You can install flake8 using pip:

`pip install flake8==3.8.3`

You can install black using pip:

`pip install black`

In order to format the code:

`make all`
`make formatting`

> **Note:** Format/refactoring patches that are not anything substantial to the context or functionality will likely be rejected.
Expand Down
Loading

0 comments on commit bea4153

Please sign in to comment.