Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 25 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,48 +81,51 @@ install-test: clean-build clean-pyc ## install the package and test dependencies
install-develop: clean-build clean-pyc ## install the package in editable mode and dependencies for development
pip install -e .[dev]

MINIMUM := $(shell sed -n '/install_requires = \[/,/]/p' setup.py | head -n-1 | tail -n+2 | sed 's/ *\(.*\),$?$$/\1/g' | tr '>' '=')

.PHONY: install-minimum
install-minimum: ## install the minimum supported versions of the package dependencies
pip install $(MINIMUM)

# LINT TARGETS

.PHONY: lint
lint: ## check style with flake8 and isort
flake8 sigpro
flake8 tests --ignore=D
isort -c --recursive sigpro tests
pylint sigpro --rcfile=setup.cfg
invoke lint

.PHONY: fix-lint
fix-lint: ## fix lint issues using autoflake, autopep8, and isort
find sigpro tests -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
autopep8 --in-place --recursive --aggressive sigpro tests
isort --apply --atomic --recursive sigpro tests
find sigpro -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
autopep8 --in-place --recursive --aggressive sigpro
isort --apply --atomic --recursive sigpro

find tests -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
autopep8 --in-place --recursive --aggressive tests
isort --apply --atomic --recursive tests

# TEST TARGETS

.PHONY: test-unit
test-unit: ## run tests quickly with the default Python
python -m pytest --cov=sigpro
invoke pytest

.PHONY: test-readme
test-readme: ## run the readme snippets
rm -rf tests/readme_test && mkdir tests/readme_test
cd tests/readme_test && rundoc run --single-session python3 -t python3 ../../README.md
rm -rf tests/readme_test
invoke readme


.PHONY: test-tutorials
test-tutorials: ## run the tutorial notebooks
invoke tutorials


.PHONY: test
test: test-unit test-readme ## test everything that needs test dependencies
test: test-unit test-readme test-tutorials ## test everything that needs test dependencies

.PHONY: check-dependencies
check-dependencies: ## test if there are any broken dependencies
pip check

.PHONY: test-devel
test-devel: lint docs ## test everything that needs development dependencies
test-devel: check-dependencies lint docs ## test everything that needs development dependencies

.PHONY: test-all
test-all: ## test using tox
test-all:
tox -r

.PHONY: coverage
Expand All @@ -132,12 +135,11 @@ coverage: ## check code coverage quickly with the default Python
coverage html
$(BROWSER) htmlcov/index.html


# DOCS TARGETS

.PHONY: docs
docs: clean-docs ## generate Sphinx HTML documentation, including API docs
sphinx-apidoc --separate --no-toc -o docs/api/ sigpro
sphinx-apidoc --module-first --separate -T -o docs/api/ sigpro
$(MAKE) -C docs html

.PHONY: view-docs
Expand All @@ -146,7 +148,7 @@ view-docs: docs ## view docs in browser

.PHONY: serve-docs
serve-docs: view-docs ## compile the docs watching for changes
watchmedo shell-command -W -R -D -p '*.rst;*.md' -c '$(MAKE) -C docs html' docs
watchmedo shell-command -W -R -D -p '*.rst;*.md' -c '$(MAKE) -C docs html' .


# RELEASE TARGETS
Expand All @@ -170,7 +172,7 @@ publish-test: dist publish-confirm ## package and upload a release on TestPyPI

.PHONY: publish
publish: dist publish-confirm ## package and upload a release
twine upload --repository-url https://pypi.dailab.ml:8080 dist/*
twine upload dist/*

.PHONY: bumpversion-release
bumpversion-release: ## Merge master to stable and bumpversion release
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
install_requires = [
'mlblocks>=0.4.0,<0.5',
'pandas>=1,<2',
'numpy>=1.17.1,<1.19',
'numpy>=1.17.4,<1.19',
'scipy>=1.3.3,<2',
]

Expand Down Expand Up @@ -61,6 +61,7 @@
'coverage>=4.5.1,<6',
'tox>=2.9.1,<4',
'importlib-metadata<2,>=0.12',
'invoke',
]

setup(
Expand Down
92 changes: 92 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import glob
import os
import re
import shutil
import stat
from pathlib import Path

from invoke import task


@task
def pytest(c):
c.run('python -m pytest --cov=sigpro')


@task
def install_minimum(c):
with open('setup.py', 'r') as setup_py:
lines = setup_py.read().splitlines()

versions = []
started = False
for line in lines:
if started:
if line == ']':
break

line = line.strip()
line = re.sub(r',?<=?[\d.]*,?', '', line)
line = re.sub(r'>=?', '==', line)
line = re.sub(r"""['",]""", '', line)
versions.append(line)

elif line.startswith('install_requires = ['):
started = True

c.run(f'python -m pip install {" ".join(versions)}')


@task
def minimum(c):
install_minimum(c)
c.run('python -m pip check')
c.run('python -m pytest')


@task
def readme(c):
test_path = Path('tests/readme_test')
if test_path.exists() and test_path.is_dir():
shutil.rmtree(test_path)

cwd = os.getcwd()
os.makedirs(test_path, exist_ok=True)
shutil.copy('README.md', test_path / 'README.md')
os.chdir(test_path)
c.run('rundoc run --single-session python3 -t python3 README.md')
os.chdir(cwd)
shutil.rmtree(test_path)


@task
def tutorials(c):
for ipynb_file in glob.glob('tutorials/*.ipynb') + glob.glob('tutorials/**/*.ipynb'):
if '.ipynb_checkpoints' not in ipynb_file:
c.run((
'jupyter nbconvert --execute --ExecutePreprocessor.timeout=3600 '
f'--to=html --stdout {ipynb_file}'
), hide='out')


@task
def lint(c):
c.run('flake8 sigpro')
c.run('flake8 tests --ignore=D,SFS2')
c.run('isort -c --recursive sigpro tests')
# c.run('pydocstyle sigpro')
c.run('pylint sigpro --rcfile=setup.cfg')


def remove_readonly(func, path, _):
"Clear the readonly bit and reattempt the removal"
os.chmod(path, stat.S_IWRITE)
func(path)


@task
def rmdir(c, path):
try:
shutil.rmtree(path, onerror=remove_readonly)
except PermissionError:
pass
36 changes: 22 additions & 14 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
[tox]
envlist = py3{6,7,8}, test-devel
envlist = py3{6,7,8}-{lint,readme,pytest,minimum}

[travis]
python =
3.8: py38, test-devel
3.7: py37
3.6: py36
3.8: py38-lint, py38-readme, py38-pytest, py38-minimum, py38-tutorials
3.7: py37-lint, py37-readme, py37-pytest, py37-minimum, py37-tutorials
3.6: py36-lint, py36-readme, py36-pytest, py36-minimum, py36-tutorials

[gh-actions]
python =
3.8: py38, test-devel
3.7: py37,
3.6: py36
3.8: py38-lint, py38-readme, py38-pytest, py38-minimum, py38-tutorials
3.7: py37-lint, py37-readme, py37-pytest, py37-minimum, py37-tutorials
3.6: py36-lint, py36-readme, py36-pytest, py36-minimum, py36-tutorials

[testenv]
passenv = CI TRAVIS TRAVIS_*
skipsdist = false
skip_install = false
extras = test
deps =
invoke
readme: rundoc
tutorials: jupyter
extras =
lint: dev
pytest: test
minimum: test
tutorials: ctgan
commands =
/usr/bin/env make test

[testenv:test-devel]
extras = dev
commands =
/usr/bin/env make test-devel
lint: invoke lint
readme: invoke readme
pytest: invoke pytest
minimum: invoke minimum
tutorials: invoke tutorials
invoke rmdir --path {envdir}