Skip to content

Commit 0e52463

Browse files
Add invoke for windows support. (#9)
* Add invoke for windows support. * Update tox.ini * Upgrade Numpy minimum version.
1 parent 45f44e1 commit 0e52463

File tree

4 files changed

+141
-38
lines changed

4 files changed

+141
-38
lines changed

Makefile

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,51 @@ install-test: clean-build clean-pyc ## install the package and test dependencies
8181
install-develop: clean-build clean-pyc ## install the package in editable mode and dependencies for development
8282
pip install -e .[dev]
8383

84-
MINIMUM := $(shell sed -n '/install_requires = \[/,/]/p' setup.py | head -n-1 | tail -n+2 | sed 's/ *\(.*\),$?$$/\1/g' | tr '>' '=')
85-
86-
.PHONY: install-minimum
87-
install-minimum: ## install the minimum supported versions of the package dependencies
88-
pip install $(MINIMUM)
8984

9085
# LINT TARGETS
9186

9287
.PHONY: lint
9388
lint: ## check style with flake8 and isort
94-
flake8 sigpro
95-
flake8 tests --ignore=D
96-
isort -c --recursive sigpro tests
97-
pylint sigpro --rcfile=setup.cfg
89+
invoke lint
9890

9991
.PHONY: fix-lint
10092
fix-lint: ## fix lint issues using autoflake, autopep8, and isort
101-
find sigpro tests -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
102-
autopep8 --in-place --recursive --aggressive sigpro tests
103-
isort --apply --atomic --recursive sigpro tests
93+
find sigpro -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
94+
autopep8 --in-place --recursive --aggressive sigpro
95+
isort --apply --atomic --recursive sigpro
10496

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

106101
# TEST TARGETS
107102

108103
.PHONY: test-unit
109104
test-unit: ## run tests quickly with the default Python
110-
python -m pytest --cov=sigpro
105+
invoke pytest
111106

112107
.PHONY: test-readme
113108
test-readme: ## run the readme snippets
114-
rm -rf tests/readme_test && mkdir tests/readme_test
115-
cd tests/readme_test && rundoc run --single-session python3 -t python3 ../../README.md
116-
rm -rf tests/readme_test
109+
invoke readme
110+
111+
112+
.PHONY: test-tutorials
113+
test-tutorials: ## run the tutorial notebooks
114+
invoke tutorials
115+
117116

118117
.PHONY: test
119-
test: test-unit test-readme ## test everything that needs test dependencies
118+
test: test-unit test-readme test-tutorials ## test everything that needs test dependencies
119+
120+
.PHONY: check-dependencies
121+
check-dependencies: ## test if there are any broken dependencies
122+
pip check
120123

121124
.PHONY: test-devel
122-
test-devel: lint docs ## test everything that needs development dependencies
125+
test-devel: check-dependencies lint docs ## test everything that needs development dependencies
123126

124127
.PHONY: test-all
125-
test-all: ## test using tox
128+
test-all:
126129
tox -r
127130

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

135-
136138
# DOCS TARGETS
137139

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

143145
.PHONY: view-docs
@@ -146,7 +148,7 @@ view-docs: docs ## view docs in browser
146148

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

151153

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

171173
.PHONY: publish
172174
publish: dist publish-confirm ## package and upload a release
173-
twine upload --repository-url https://pypi.dailab.ml:8080 dist/*
175+
twine upload dist/*
174176

175177
.PHONY: bumpversion-release
176178
bumpversion-release: ## Merge master to stable and bumpversion release

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
install_requires = [
1515
'mlblocks>=0.4.0,<0.5',
1616
'pandas>=1,<2',
17-
'numpy>=1.17.1,<1.19',
17+
'numpy>=1.17.4,<1.19',
1818
'scipy>=1.3.3,<2',
1919
]
2020

@@ -61,6 +61,7 @@
6161
'coverage>=4.5.1,<6',
6262
'tox>=2.9.1,<4',
6363
'importlib-metadata<2,>=0.12',
64+
'invoke',
6465
]
6566

6667
setup(

tasks.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import glob
2+
import os
3+
import re
4+
import shutil
5+
import stat
6+
from pathlib import Path
7+
8+
from invoke import task
9+
10+
11+
@task
12+
def pytest(c):
13+
c.run('python -m pytest --cov=sigpro')
14+
15+
16+
@task
17+
def install_minimum(c):
18+
with open('setup.py', 'r') as setup_py:
19+
lines = setup_py.read().splitlines()
20+
21+
versions = []
22+
started = False
23+
for line in lines:
24+
if started:
25+
if line == ']':
26+
break
27+
28+
line = line.strip()
29+
line = re.sub(r',?<=?[\d.]*,?', '', line)
30+
line = re.sub(r'>=?', '==', line)
31+
line = re.sub(r"""['",]""", '', line)
32+
versions.append(line)
33+
34+
elif line.startswith('install_requires = ['):
35+
started = True
36+
37+
c.run(f'python -m pip install {" ".join(versions)}')
38+
39+
40+
@task
41+
def minimum(c):
42+
install_minimum(c)
43+
c.run('python -m pip check')
44+
c.run('python -m pytest')
45+
46+
47+
@task
48+
def readme(c):
49+
test_path = Path('tests/readme_test')
50+
if test_path.exists() and test_path.is_dir():
51+
shutil.rmtree(test_path)
52+
53+
cwd = os.getcwd()
54+
os.makedirs(test_path, exist_ok=True)
55+
shutil.copy('README.md', test_path / 'README.md')
56+
os.chdir(test_path)
57+
c.run('rundoc run --single-session python3 -t python3 README.md')
58+
os.chdir(cwd)
59+
shutil.rmtree(test_path)
60+
61+
62+
@task
63+
def tutorials(c):
64+
for ipynb_file in glob.glob('tutorials/*.ipynb') + glob.glob('tutorials/**/*.ipynb'):
65+
if '.ipynb_checkpoints' not in ipynb_file:
66+
c.run((
67+
'jupyter nbconvert --execute --ExecutePreprocessor.timeout=3600 '
68+
f'--to=html --stdout {ipynb_file}'
69+
), hide='out')
70+
71+
72+
@task
73+
def lint(c):
74+
c.run('flake8 sigpro')
75+
c.run('flake8 tests --ignore=D,SFS2')
76+
c.run('isort -c --recursive sigpro tests')
77+
# c.run('pydocstyle sigpro')
78+
c.run('pylint sigpro --rcfile=setup.cfg')
79+
80+
81+
def remove_readonly(func, path, _):
82+
"Clear the readonly bit and reattempt the removal"
83+
os.chmod(path, stat.S_IWRITE)
84+
func(path)
85+
86+
87+
@task
88+
def rmdir(c, path):
89+
try:
90+
shutil.rmtree(path, onerror=remove_readonly)
91+
except PermissionError:
92+
pass

tox.ini

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
[tox]
2-
envlist = py3{6,7,8}, test-devel
2+
envlist = py3{6,7,8}-{lint,readme,pytest,minimum}
33

44
[travis]
55
python =
6-
3.8: py38, test-devel
7-
3.7: py37
8-
3.6: py36
6+
3.8: py38-lint, py38-readme, py38-pytest, py38-minimum, py38-tutorials
7+
3.7: py37-lint, py37-readme, py37-pytest, py37-minimum, py37-tutorials
8+
3.6: py36-lint, py36-readme, py36-pytest, py36-minimum, py36-tutorials
99

1010
[gh-actions]
1111
python =
12-
3.8: py38, test-devel
13-
3.7: py37,
14-
3.6: py36
12+
3.8: py38-lint, py38-readme, py38-pytest, py38-minimum, py38-tutorials
13+
3.7: py37-lint, py37-readme, py37-pytest, py37-minimum, py37-tutorials
14+
3.6: py36-lint, py36-readme, py36-pytest, py36-minimum, py36-tutorials
1515

1616
[testenv]
1717
passenv = CI TRAVIS TRAVIS_*
1818
skipsdist = false
1919
skip_install = false
20-
extras = test
20+
deps =
21+
invoke
22+
readme: rundoc
23+
tutorials: jupyter
24+
extras =
25+
lint: dev
26+
pytest: test
27+
minimum: test
28+
tutorials: ctgan
2129
commands =
22-
/usr/bin/env make test
23-
24-
[testenv:test-devel]
25-
extras = dev
26-
commands =
27-
/usr/bin/env make test-devel
30+
lint: invoke lint
31+
readme: invoke readme
32+
pytest: invoke pytest
33+
minimum: invoke minimum
34+
tutorials: invoke tutorials
35+
invoke rmdir --path {envdir}

0 commit comments

Comments
 (0)