Skip to content

Commit

Permalink
bump version, merge pull request #14 from casperdcl/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl authored Mar 1, 2021
2 parents e4849a5 + af66f93 commit 01864d8
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 146 deletions.
9 changes: 0 additions & 9 deletions .coveragerc

This file was deleted.

69 changes: 33 additions & 36 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,29 @@ jobs:
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: set PYSHA
- name: Prepare cache
run: echo "PYSHA=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PYSHA }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Test
- name: Dependencies
run: |
pip install -U tox
tox -e setup.py
- name: Self install
run: pip install -U .[dev]
- name: Build
run: |
python setup.py sdist bdist_wheel
twine check dist/*
pip install -U pre-commit
- uses: reviewdog/action-setup@v1
- if: github.event_name != 'schedule'
name: flake8
name: Comment
run: |
pre-commit run -a flake8 | reviewdog -f=pep8 -name=Format -tee -reporter=github-check -filter-mode nofilter
if [[ $EVENT == pull_request ]]; then
REPORTER=github-pr-review
else
REPORTER=github-check
fi
pre-commit run -a todo | reviewdog -efm="%f:%l: %m" -name=TODO -tee -reporter=$REPORTER -filter-mode nofilter
pre-commit run -a flake8 | reviewdog -f=pep8 -name=flake8 -tee -reporter=$REPORTER -filter-mode nofilter
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT: ${{ github.event_name }}
- name: Lint
run: pre-commit run -a --show-diff-on-failure
test:
Expand Down Expand Up @@ -66,22 +64,25 @@ jobs:
fi
env:
PYVER: ${{ matrix.python }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Coveralls Parallel
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
COVERALLS_FLAG_NAME: py${{ matrix.python }}
COVERALLS_PARALLEL: true
COVERALLS_SERVICE_NAME: github
# coveralls needs explicit token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
finish:
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
name: Coverage
continue-on-error: ${{ github.event_name != 'push' }}
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v2
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
run: |
pip install -U coveralls
coveralls --finish || :
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy:
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
name: Deploy
Expand All @@ -91,20 +92,16 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
uses: casperdcl/deploy-pypi@v1
- uses: actions/setup-python@v2
- id: dist
uses: casperdcl/deploy-pypi@v2
with:
build: true
gpg_key: ${{ secrets.GPG_KEY }}
password: ${{ secrets.PYPI_TOKEN }}
skip_existing: true
- id: collect_assets
name: Collect assets
gpg_key: ${{ secrets.GPG_KEY }}
upload: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') }}
- name: Changelog
run: |
echo "::set-output name=asset_path::$(ls dist/*.whl)"
echo "::set-output name=asset_name::$(basename dist/*.whl)"
echo "::set-output name=asset_path_sig::$(ls dist/*.whl.asc 2>/dev/null)"
echo "::set-output name=asset_name_sig::$(basename dist/*.whl.asc 2>/dev/null)"
git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD > _CHANGES.md
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
id: create_release
Expand All @@ -122,15 +119,15 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.collect_assets.outputs.asset_path }}
asset_name: ${{ steps.collect_assets.outputs.asset_name }}
asset_path: dist/${{ steps.dist.outputs.whl }}
asset_name: ${{ steps.dist.outputs.whl }}
asset_content_type: application/zip
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.collect_assets.outputs.asset_path_sig }}
asset_name: ${{ steps.collect_assets.outputs.asset_name_sig }}
asset_path: dist/${{ steps.dist.outputs.whl_asc }}
asset_name: ${{ steps.dist.outputs.whl_asc }}
asset_content_type: text/plain
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
*.py[co]
__pycache__/

# build
/argopt/_dist_ver.py
/.eggs/
/*.egg-info
/*.egg*/
/build/
/dist/

# test
.tox/
.coverage
__pycache__/
/.tox/
/.coverage*
/coverage.xml
36 changes: 29 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,49 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v3.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-toml
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: sort-simple-yaml
- id: trailing-whitespace
- hooks:
- repo: local
hooks:
- id: todo
name: Check TODO
language: pygrep
entry: WIP
args: [-i]
types: [text]
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- id: nose
name: Run tests
language: python
entry: nosetests
args: ['-d', tests/]
types: [python]
pass_filenames: false
additional_dependencies:
- nose
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
args: ['-j8']
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format
repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
- hooks:
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
hooks:
- id: isort
repo: https://github.com/timothycrosley/isort
rev: 5.6.4
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ test:
tox --skip-missing-interpreters -p all

testnose:
nosetests argopt -d -v
nosetests -d -v tests/

testsetup:
python setup.py check --metadata --restructuredtext --strict
python setup.py make none

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

testtimer:
nosetests argopt --with-timer -d -v
nosetests --with-timer -d -v tests/

distclean:
@+make coverclean
Expand All @@ -78,13 +78,14 @@ prebuildclean:
@+python -c "import os; os.remove('argopt/_dist_ver.py') if os.path.exists('argopt/_dist_ver.py') else None"
coverclean:
@+python -c "import os; os.remove('.coverage') if os.path.exists('.coverage') else None"
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('.coverage.*')]"
@+python -c "import shutil; shutil.rmtree('argopt/__pycache__', True)"
@+python -c "import shutil; shutil.rmtree('argopt/tests/__pycache__', True)"
@+python -c "import shutil; shutil.rmtree('tests/__pycache__', True)"
clean:
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('*.py[co]')]"
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('argopt/*.py[co]')]"
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('examples/*.py[co]')]"
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('argopt/tests/*.py[co]')]"
@+python -c "import os, glob; [os.remove(i) for i in glob.glob('tests/*.py[co]')]"
toxclean:
@+python -c "import shutil; shutil.rmtree('.tox', True)"

Expand Down
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ checking and default positional arguments.
__version__ = "0.1.2-3.4"
parser = argopt(__doc__, version=__version__).parse_args()
parser = argopt(__doc__, version=__version__)
args = parser.parse_args()
if args.force:
print(args)
else:
Expand Down
1 change: 0 additions & 1 deletion argopt/_argopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def docopt_parser(doc='', logLevel=logging.NOTSET, **_kwargs):

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

Expand Down
27 changes: 13 additions & 14 deletions argopt/_docopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,21 @@ def __init__(self, name, value=None, desc=None, typ=None):
self.value = value
self.desc = desc
self.type = typ
self._fix_value_type()

def _fix_value_type(self):
value, typ = self.value, self.type
if (value is not None) and (typ is None):
if type(value) is bool:
self.type = bool
elif type(value) is str:
i = value.rfind(':')
if i >= 0:
self.type = eval(value[i + 1:])
self.value = typecast(value[:i], value[i + 1:])
elif hasattr(value, 'rsplit'):
i = value.rsplit(':', 1)
if len(i) == 2:
# potentially used in `eval`, e.g. `partial(open, mode="w")`
from functools import partial # NOQA: F401

self.type = eval(i[1])
self.value = typecast(i[0], i[1])

def __repr__(self):
return '%s(%r, %r, %r)' % (self.__class__.__name__, self.name,
Expand Down Expand Up @@ -208,15 +215,7 @@ def __init__(self, short=None, long=None, argcount=0, value=False,
self.type = typ
self.desc = desc
self.meta = meta

if (value is not None) and (typ is None):
if type(value) is bool:
self.type = bool
else:
i = value.rfind(':')
if i >= 0:
self.type = eval(value[i + 1:])
self.value = typecast(value[:i], value[i + 1:])
self._fix_value_type()

@classmethod
def parse(class_, option_description):
Expand Down
21 changes: 16 additions & 5 deletions argopt/_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import logging
import subprocess

# potentially used in `eval`, e.g. `partial(open, mode="w")`
from functools import partial # NOQA: F401

__all__ = ["_range", "typecast", "set_nargs", "_sh", "DictAttrWrap"]

try: # pragma: no cover
try: # py2
_range = xrange
except NameError: # pragma: no cover
except NameError: # py3
_range = range
file = open

log = logging.getLogger(__name__)


class DictAttrWrap(object):
"""Converting docopt-style dictionaries to argparse-style"""
Expand All @@ -26,19 +32,24 @@ def typecast(val, typ):
return None
if not isinstance(typ, str):
typ = str(typ).lstrip("<type '").lstrip("<class '").rstrip("'>")
return eval(typ + '(' + str(val) + ')')
try:
return eval(typ + '(' + str(val) + ')')
except Exception:
log.error("Could not evaluate `%s(%s)`. Maybe missing quotes?", typ, val)
raise


def set_nargs(all_args, args, n):
for a in args:
a.nargs = n
try:
_a = [i for i in all_args if i.name == a.name][0]
except IndexError:
pass
else:
a.value = _a.value
a.desc = _a.desc
a.type = _a.type
except IndexError:
pass


def _sh(*cmd, **kwargs):
Expand Down
Loading

0 comments on commit 01864d8

Please sign in to comment.