Skip to content

Commit 3759676

Browse files
authored
Add github actions (#97)
* Added invoke. * Fix minimum dependency * Disable minimum * fix file encoding * Fixed bug
1 parent 7249628 commit 3759676

5 files changed

Lines changed: 136 additions & 17 deletions

File tree

.github/workflows/tests.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
python-version: [3.6, 3.7, 3.8]
15+
os: [ubuntu-latest, macos-latest, windows-latest]
16+
steps:
17+
- uses: actions/checkout@v1
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- if: matrix.os == 'windows-latest'
23+
name: Install dependencies - Windows
24+
run: pip install 'torch>=1,<2' -f https://download.pytorch.org/whl/torch_stable.html
25+
- name: Install package
26+
run: pip install invoke .[dev]
27+
- name: invoke lint
28+
run: invoke lint
29+
30+
readme:
31+
runs-on: ${{ matrix.os }}
32+
strategy:
33+
matrix:
34+
python-version: [3.6, 3.7, 3.8]
35+
os: [ubuntu-latest, macos-latest]
36+
steps:
37+
- uses: actions/checkout@v1
38+
- name: Set up Python ${{ matrix.python-version }}
39+
uses: actions/setup-python@v1
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
- name: Install package and dependencies
43+
run: pip install invoke rundoc .
44+
- name: invoke readme
45+
run: invoke readme
46+
47+
unit:
48+
runs-on: ${{ matrix.os }}
49+
strategy:
50+
matrix:
51+
python-version: [3.6, 3.7, 3.8]
52+
os: [ubuntu-latest, macos-latest, windows-latest]
53+
steps:
54+
- uses: actions/checkout@v1
55+
- name: Set up Python ${{ matrix.python-version }}
56+
uses: actions/setup-python@v1
57+
with:
58+
python-version: ${{ matrix.python-version }}
59+
- if: matrix.os == 'windows-latest'
60+
name: Install dependencies - Windows
61+
run: pip install 'torch>=1,<2' -f https://download.pytorch.org/whl/torch_stable.html
62+
- name: Install package and dependencies
63+
run: pip install invoke .[test]
64+
- name: invoke pytest
65+
run: invoke pytest

Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ install-minimum: ## install the minimum supported versions of the package depend
9393

9494
.PHONY: lint
9595
lint: ## check style with flake8 and isort
96-
flake8 ctgan tests
97-
isort -c --recursive ctgan tests
96+
invoke lint
9897

9998
.PHONY: fix-lint
10099
fix-lint: ## fix lint issues using autoflake, autopep8, and isort
@@ -107,13 +106,11 @@ fix-lint: ## fix lint issues using autoflake, autopep8, and isort
107106

108107
.PHONY: test
109108
test: ## run tests quickly with the default Python
110-
python -m pytest --cov=ctgan
109+
invoke pytest
111110

112111
.PHONY: test-readme
113112
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
113+
invoke readme
117114

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

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from setuptools import setup, find_packages
77

8-
with open('README.md') as readme_file:
8+
with open('README.md', encoding='utf-8') as readme_file:
99
readme = readme_file.read()
1010

11-
with open('HISTORY.md') as history_file:
11+
with open('HISTORY.md', encoding='utf-8') as history_file:
1212
history = history_file.read()
1313

1414
install_requires = [
@@ -58,6 +58,8 @@
5858
# Advanced testing
5959
'coverage>=4.5.1,<6',
6060
'tox>=2.9.1,<4',
61+
62+
'invoke',
6163
]
6264

6365
setup(

tasks.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import shutil
3+
import stat
4+
from pathlib import Path
5+
6+
from invoke import task
7+
8+
9+
@task
10+
def pytest(c):
11+
c.run('python -m pytest --cov=ctgan')
12+
13+
14+
@task
15+
def readme(c):
16+
test_path = Path('tests/readme_test')
17+
if test_path.exists() and test_path.is_dir():
18+
shutil.rmtree(test_path)
19+
20+
cwd = os.getcwd()
21+
os.makedirs(test_path, exist_ok=True)
22+
shutil.copy('README.md', test_path / 'README.md')
23+
os.chdir(test_path)
24+
c.run('rundoc run --single-session python3 -t python3 README.md')
25+
os.chdir(cwd)
26+
shutil.rmtree(test_path)
27+
28+
29+
@task
30+
def lint(c):
31+
c.run('flake8 ctgan')
32+
c.run('flake8 tests --ignore=D,SFS2')
33+
c.run('isort -c --recursive ctgan tests')
34+
35+
36+
def remove_readonly(func, path, _):
37+
"Clear the readonly bit and reattempt the removal"
38+
os.chmod(path, stat.S_IWRITE)
39+
func(path)
40+
41+
42+
@task
43+
def rmdir(c, path):
44+
try:
45+
shutil.rmtree(path, onerror=remove_readonly)
46+
except PermissionError:
47+
pass

tox.ini

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

44
[travis]
55
python =
6-
3.8: py38-test, py38-readme, py38-devel
7-
3.7: py37-test, py37-readme, py37-devel
8-
3.6: py36-test, py36-readme, py36-devel
6+
3.8: py38-lint, py38-pytest, py38-readme
7+
3.7: py37-lint, py37-pytest, py37-readme
8+
3.6: py36-lint, py36-pytest, py36-readme
9+
10+
[gh-actions]
11+
python =
12+
3.8: py38-lint, py38-pytest, py38-readme
13+
3.7: py37-lint, py37-pytest, py37-readme
14+
3.6: py36-lint, py36-pytest, py36-readme
915

1016
[testenv]
1117
passenv = CI TRAVIS TRAVIS_*
1218
skipsdist = false
1319
skip_install = false
1420
deps =
21+
invoke
1522
readme: rundoc
1623
extras =
17-
test: test
18-
devel: dev
24+
lint: dev
25+
pytest: test
1926
commands =
20-
readme: /usr/bin/env make test-readme
21-
test: /usr/bin/env make test
22-
devel: /usr/bin/env make test-devel
27+
lint: invoke lint
28+
pytest: invoke pytest
29+
readme: invoke readme
30+
invoke rmdir --path {envdir}

0 commit comments

Comments
 (0)