Skip to content

Commit 01864d8

Browse files
authored
bump version, merge pull request #14 from casperdcl/devel
2 parents e4849a5 + af66f93 commit 01864d8

File tree

13 files changed

+165
-146
lines changed

13 files changed

+165
-146
lines changed

.coveragerc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,29 @@ jobs:
1414
with:
1515
fetch-depth: 0
1616
- uses: actions/setup-python@v2
17-
with:
18-
python-version: '3.x'
19-
- name: set PYSHA
17+
- name: Prepare cache
2018
run: echo "PYSHA=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
2119
- uses: actions/cache@v1
2220
with:
2321
path: ~/.cache/pre-commit
2422
key: pre-commit|${{ env.PYSHA }}|${{ hashFiles('.pre-commit-config.yaml') }}
25-
- name: Test
23+
- name: Dependencies
2624
run: |
27-
pip install -U tox
28-
tox -e setup.py
29-
- name: Self install
30-
run: pip install -U .[dev]
31-
- name: Build
32-
run: |
33-
python setup.py sdist bdist_wheel
34-
twine check dist/*
25+
pip install -U pre-commit
3526
- uses: reviewdog/action-setup@v1
3627
- if: github.event_name != 'schedule'
37-
name: flake8
28+
name: Comment
3829
run: |
39-
pre-commit run -a flake8 | reviewdog -f=pep8 -name=Format -tee -reporter=github-check -filter-mode nofilter
30+
if [[ $EVENT == pull_request ]]; then
31+
REPORTER=github-pr-review
32+
else
33+
REPORTER=github-check
34+
fi
35+
pre-commit run -a todo | reviewdog -efm="%f:%l: %m" -name=TODO -tee -reporter=$REPORTER -filter-mode nofilter
36+
pre-commit run -a flake8 | reviewdog -f=pep8 -name=flake8 -tee -reporter=$REPORTER -filter-mode nofilter
4037
env:
4138
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
EVENT: ${{ github.event_name }}
4240
- name: Lint
4341
run: pre-commit run -a --show-diff-on-failure
4442
test:
@@ -66,22 +64,25 @@ jobs:
6664
fi
6765
env:
6866
PYVER: ${{ matrix.python }}
69-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
70-
- name: Coveralls Parallel
71-
uses: AndreMiras/coveralls-python-action@develop
72-
with:
73-
parallel: true
67+
COVERALLS_FLAG_NAME: py${{ matrix.python }}
68+
COVERALLS_PARALLEL: true
69+
COVERALLS_SERVICE_NAME: github
70+
# coveralls needs explicit token
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7472
finish:
7573
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
7674
name: Coverage
7775
continue-on-error: ${{ github.event_name != 'push' }}
7876
needs: test
7977
runs-on: ubuntu-latest
8078
steps:
79+
- uses: actions/setup-python@v2
8180
- name: Coveralls Finished
82-
uses: AndreMiras/coveralls-python-action@develop
83-
with:
84-
parallel-finished: true
81+
run: |
82+
pip install -U coveralls
83+
coveralls --finish || :
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8586
deploy:
8687
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
8788
name: Deploy
@@ -91,20 +92,16 @@ jobs:
9192
- uses: actions/checkout@v2
9293
with:
9394
fetch-depth: 0
94-
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
95-
uses: casperdcl/deploy-pypi@v1
95+
- uses: actions/setup-python@v2
96+
- id: dist
97+
uses: casperdcl/deploy-pypi@v2
9698
with:
9799
build: true
98-
gpg_key: ${{ secrets.GPG_KEY }}
99100
password: ${{ secrets.PYPI_TOKEN }}
100-
skip_existing: true
101-
- id: collect_assets
102-
name: Collect assets
101+
gpg_key: ${{ secrets.GPG_KEY }}
102+
upload: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') }}
103+
- name: Changelog
103104
run: |
104-
echo "::set-output name=asset_path::$(ls dist/*.whl)"
105-
echo "::set-output name=asset_name::$(basename dist/*.whl)"
106-
echo "::set-output name=asset_path_sig::$(ls dist/*.whl.asc 2>/dev/null)"
107-
echo "::set-output name=asset_name_sig::$(basename dist/*.whl.asc 2>/dev/null)"
108105
git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD > _CHANGES.md
109106
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
110107
id: create_release
@@ -122,15 +119,15 @@ jobs:
122119
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
123120
with:
124121
upload_url: ${{ steps.create_release.outputs.upload_url }}
125-
asset_path: ${{ steps.collect_assets.outputs.asset_path }}
126-
asset_name: ${{ steps.collect_assets.outputs.asset_name }}
122+
asset_path: dist/${{ steps.dist.outputs.whl }}
123+
asset_name: ${{ steps.dist.outputs.whl }}
127124
asset_content_type: application/zip
128125
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
129126
uses: actions/upload-release-asset@v1
130127
env:
131128
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
132129
with:
133130
upload_url: ${{ steps.create_release.outputs.upload_url }}
134-
asset_path: ${{ steps.collect_assets.outputs.asset_path_sig }}
135-
asset_name: ${{ steps.collect_assets.outputs.asset_name_sig }}
131+
asset_path: dist/${{ steps.dist.outputs.whl_asc }}
132+
asset_name: ${{ steps.dist.outputs.whl_asc }}
136133
asset_content_type: text/plain

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
*.py[co]
2+
__pycache__/
3+
24
# build
35
/argopt/_dist_ver.py
46
/.eggs/
5-
/*.egg-info
7+
/*.egg*/
68
/build/
79
/dist/
10+
811
# test
9-
.tox/
10-
.coverage
11-
__pycache__/
12+
/.tox/
13+
/.coverage*
14+
/coverage.xml

.pre-commit-config.yaml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,49 @@ default_language_version:
22
python: python3
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v3.3.0
5+
rev: v3.4.0
66
hooks:
77
- id: check-added-large-files
88
- id: check-case-conflict
99
- id: check-docstring-first
1010
- id: check-executables-have-shebangs
1111
- id: check-toml
12+
- id: check-merge-conflict
1213
- id: check-yaml
14+
- id: debug-statements
1315
- id: end-of-file-fixer
1416
- id: mixed-line-ending
17+
- id: sort-simple-yaml
1518
- id: trailing-whitespace
16-
- hooks:
19+
- repo: local
20+
hooks:
21+
- id: todo
22+
name: Check TODO
23+
language: pygrep
24+
entry: WIP
25+
args: [-i]
26+
types: [text]
27+
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
28+
- id: nose
29+
name: Run tests
30+
language: python
31+
entry: nosetests
32+
args: ['-d', tests/]
33+
types: [python]
34+
pass_filenames: false
35+
additional_dependencies:
36+
- nose
37+
- repo: https://gitlab.com/pycqa/flake8
38+
rev: 3.8.4
39+
hooks:
1740
- id: flake8
41+
args: ['-j8']
1842
additional_dependencies:
1943
- flake8-bugbear
2044
- flake8-comprehensions
2145
- flake8-debugger
2246
- flake8-string-format
23-
repo: https://gitlab.com/pycqa/flake8
24-
rev: 3.8.4
25-
- hooks:
47+
- repo: https://github.com/PyCQA/isort
48+
rev: 5.7.0
49+
hooks:
2650
- id: isort
27-
repo: https://github.com/timothycrosley/isort
28-
rev: 5.6.4

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ test:
5353
tox --skip-missing-interpreters -p all
5454

5555
testnose:
56-
nosetests argopt -d -v
56+
nosetests -d -v tests/
5757

5858
testsetup:
5959
python setup.py check --metadata --restructuredtext --strict
6060
python setup.py make none
6161

6262
testcoverage:
6363
@make coverclean
64-
nosetests argopt --with-coverage --cover-package=argopt --cover-erase --cover-min-percentage=80 -d -v
64+
nosetests --with-coverage --cover-package=argopt --cover-erase --cover-min-percentage=80 -d -v tests/
6565

6666
testtimer:
67-
nosetests argopt --with-timer -d -v
67+
nosetests --with-timer -d -v tests/
6868

6969
distclean:
7070
@+make coverclean
@@ -78,13 +78,14 @@ prebuildclean:
7878
@+python -c "import os; os.remove('argopt/_dist_ver.py') if os.path.exists('argopt/_dist_ver.py') else None"
7979
coverclean:
8080
@+python -c "import os; os.remove('.coverage') if os.path.exists('.coverage') else None"
81+
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('.coverage.*')]"
8182
@+python -c "import shutil; shutil.rmtree('argopt/__pycache__', True)"
82-
@+python -c "import shutil; shutil.rmtree('argopt/tests/__pycache__', True)"
83+
@+python -c "import shutil; shutil.rmtree('tests/__pycache__', True)"
8384
clean:
8485
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('*.py[co]')]"
8586
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('argopt/*.py[co]')]"
8687
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('examples/*.py[co]')]"
87-
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('argopt/tests/*.py[co]')]"
88+
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('tests/*.py[co]')]"
8889
toxclean:
8990
@+python -c "import shutil; shutil.rmtree('.tox', True)"
9091

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ checking and default positional arguments.
9595
__version__ = "0.1.2-3.4"
9696
9797
98-
parser = argopt(__doc__, version=__version__).parse_args()
98+
parser = argopt(__doc__, version=__version__)
99+
args = parser.parse_args()
99100
if args.force:
100101
print(args)
101102
else:

argopt/_argopt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def docopt_parser(doc='', logLevel=logging.NOTSET, **_kwargs):
106106

107107
set_nargs(args, once_args, None) # setting to `1` creates single-item list
108108
set_nargs(args, qest_args, '?')
109-
set_nargs(args, qest_args, '?')
110109
set_nargs(args, star_args, '*')
111110
set_nargs(args, plus_args, '+')
112111

argopt/_docopt.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,21 @@ def __init__(self, name, value=None, desc=None, typ=None):
111111
self.value = value
112112
self.desc = desc
113113
self.type = typ
114+
self._fix_value_type()
115+
116+
def _fix_value_type(self):
117+
value, typ = self.value, self.type
114118
if (value is not None) and (typ is None):
115119
if type(value) is bool:
116120
self.type = bool
117-
elif type(value) is str:
118-
i = value.rfind(':')
119-
if i >= 0:
120-
self.type = eval(value[i + 1:])
121-
self.value = typecast(value[:i], value[i + 1:])
121+
elif hasattr(value, 'rsplit'):
122+
i = value.rsplit(':', 1)
123+
if len(i) == 2:
124+
# potentially used in `eval`, e.g. `partial(open, mode="w")`
125+
from functools import partial # NOQA: F401
126+
127+
self.type = eval(i[1])
128+
self.value = typecast(i[0], i[1])
122129

123130
def __repr__(self):
124131
return '%s(%r, %r, %r)' % (self.__class__.__name__, self.name,
@@ -208,15 +215,7 @@ def __init__(self, short=None, long=None, argcount=0, value=False,
208215
self.type = typ
209216
self.desc = desc
210217
self.meta = meta
211-
212-
if (value is not None) and (typ is None):
213-
if type(value) is bool:
214-
self.type = bool
215-
else:
216-
i = value.rfind(':')
217-
if i >= 0:
218-
self.type = eval(value[i + 1:])
219-
self.value = typecast(value[:i], value[i + 1:])
218+
self._fix_value_type()
220219

221220
@classmethod
222221
def parse(class_, option_description):

argopt/_utils.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
import logging
12
import subprocess
23

4+
# potentially used in `eval`, e.g. `partial(open, mode="w")`
5+
from functools import partial # NOQA: F401
6+
37
__all__ = ["_range", "typecast", "set_nargs", "_sh", "DictAttrWrap"]
48

5-
try: # pragma: no cover
9+
try: # py2
610
_range = xrange
7-
except NameError: # pragma: no cover
11+
except NameError: # py3
812
_range = range
913
file = open
1014

15+
log = logging.getLogger(__name__)
16+
1117

1218
class DictAttrWrap(object):
1319
"""Converting docopt-style dictionaries to argparse-style"""
@@ -26,19 +32,24 @@ def typecast(val, typ):
2632
return None
2733
if not isinstance(typ, str):
2834
typ = str(typ).lstrip("<type '").lstrip("<class '").rstrip("'>")
29-
return eval(typ + '(' + str(val) + ')')
35+
try:
36+
return eval(typ + '(' + str(val) + ')')
37+
except Exception:
38+
log.error("Could not evaluate `%s(%s)`. Maybe missing quotes?", typ, val)
39+
raise
3040

3141

3242
def set_nargs(all_args, args, n):
3343
for a in args:
3444
a.nargs = n
3545
try:
3646
_a = [i for i in all_args if i.name == a.name][0]
47+
except IndexError:
48+
pass
49+
else:
3750
a.value = _a.value
3851
a.desc = _a.desc
3952
a.type = _a.type
40-
except IndexError:
41-
pass
4253

4354

4455
def _sh(*cmd, **kwargs):

0 commit comments

Comments
 (0)