From e9f4c148ef35eed38cdbf8e9b1ff6541715b2502 Mon Sep 17 00:00:00 2001 From: Chris Mitchell Date: Sun, 21 May 2023 18:25:51 -0400 Subject: [PATCH 1/3] Add import shim to argparse parser --- clinto/parsers/argparse_.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clinto/parsers/argparse_.py b/clinto/parsers/argparse_.py index be3cec3..bc15836 100644 --- a/clinto/parsers/argparse_.py +++ b/clinto/parsers/argparse_.py @@ -337,6 +337,17 @@ def extract_parser(self): try: ast_source = source_parser.parse_source_file(self.script_path) python_code = source_parser.convert_to_python(list(ast_source)) + f.write(six.b(""" +import builtins + +def tryimport(name, globals={}, locals={}, fromlist=[], level=-1): + try: + return realimport(name, globals, locals, fromlist, level) + except (ImportError, ModuleNotFoundError): + pass + +realimport, builtins.__import__ = builtins.__import__, tryimport +""")) f.write(six.b("\n".join(python_code))) f.seek(0) module = imp.load_source("__main__", f.name) From 4a82cb53c7ea98e61ec4b3c11e79fee41350b215 Mon Sep 17 00:00:00 2001 From: Chris Mitchell Date: Sun, 21 May 2023 18:30:38 -0400 Subject: [PATCH 2/3] Fix build --- .github/workflows/build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04d2ab9..eb80118 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: max-parallel: 4 matrix: # Up to date compatibility matrix - python-version: [2.7, 3.5, 3.6, 3.7, 3.8] + python-version: [3.7, 3.8, 3.9, "3.10"] os: [ubuntu-latest, windows-latest] steps: @@ -20,8 +20,6 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install dependencies - env: - DJANGO_VERSION: ${{ matrix.django-version }} run: | python -m pip install --upgrade pip make testenv From 7018fdd8b46f63b65860015df0f3500665652a4c Mon Sep 17 00:00:00 2001 From: Chris Mitchell Date: Sun, 21 May 2023 18:44:26 -0400 Subject: [PATCH 3/3] Switch to pytest --- Makefile | 2 +- clinto/parsers/argparse_.py | 11 ++++++++++- requirements.txt | 3 ++- tox.ini | 5 ----- 4 files changed, 13 insertions(+), 8 deletions(-) delete mode 100644 tox.ini diff --git a/Makefile b/Makefile index 77d627f..de73690 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ testenv: pip install -e . test: - nosetests --with-coverage --cover-erase --cover-branches --cover-package=clinto clinto/tests/* + pytest --cov=clinto --cov-config=.coveragerc clinto/tests/* coverage report --omit='clinto/tests*' coverage xml --omit='clinto/tests*' diff --git a/clinto/parsers/argparse_.py b/clinto/parsers/argparse_.py index bc15836..a2bad59 100644 --- a/clinto/parsers/argparse_.py +++ b/clinto/parsers/argparse_.py @@ -339,16 +339,25 @@ def extract_parser(self): python_code = source_parser.convert_to_python(list(ast_source)) f.write(six.b(""" import builtins +from types import ModuleType + +class DummyModule(ModuleType): + def __getattr__(self, key): + return None + __all__ = [] # support wildcard imports def tryimport(name, globals={}, locals={}, fromlist=[], level=-1): try: return realimport(name, globals, locals, fromlist, level) except (ImportError, ModuleNotFoundError): - pass + return DummyModule(name) realimport, builtins.__import__ = builtins.__import__, tryimport """)) f.write(six.b("\n".join(python_code))) + f.write(six.b(""" +builtins.__import__ = realimport +""")) f.seek(0) module = imp.load_source("__main__", f.name) except Exception: diff --git a/requirements.txt b/requirements.txt index 4cd1c0f..3650850 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ coveralls -nose +pytest +pytest-cov diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 2a37a14..0000000 --- a/tox.ini +++ /dev/null @@ -1,5 +0,0 @@ -[tox] -envlist = py27,py35,py36 -[testenv] -deps=nose -commands=nosetests