diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 1f86102..8ce5caf 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -9,7 +9,10 @@ package: source: - url: https://github.com/google/pytype/archive/refs/tags/{{ version }}.tar.gz sha256: 5ad6439e5631077310a3217442bc9f13e91910d66755356828dbf15a3aacd2db - + patches: + - patches/patch-ninja-exe.patch + - patches/remove-ninja-req.patch + - url: https://github.com/google/googletest/archive/e82d320.tar.gz sha256: 7acdbac36f80ca68126c9112cf1e60132372aff81db7a14f08cb49e6e00af536 folder: googletest @@ -21,7 +24,7 @@ source: folder: typeshed build: - number: 0 + number: 1 skip: true # [win] # no windows builds here: https://pypi.org/project/pytype/#files entry_points: @@ -59,6 +62,8 @@ test: imports: - pytype - pytype.overlays + files: + - run_pytype.py commands: - annotate-ast --help - merge-pyi --help @@ -66,8 +71,7 @@ test: - pytype --help - pytype-single --help - pyxref --help - # enable after https://github.com/conda-forge/staged-recipes/pull/19098 - # this fails; guarding against providing broken? pytype from now on + - python run_pytype.py # checks that pytype can actually run with a file input. - pip check requires: - pip diff --git a/recipe/patches/patch-ninja-exe.patch b/recipe/patches/patch-ninja-exe.patch new file mode 100644 index 0000000..f37dec8 --- /dev/null +++ b/recipe/patches/patch-ninja-exe.patch @@ -0,0 +1,30 @@ +From 53db9310cca269d6c65ebaaf92f560879b4202f8 Mon Sep 17 00:00:00 2001 +From: ngam <67342040+ngam@users.noreply.github.com> +Date: Tue, 21 Feb 2023 22:53:58 -0500 +Subject: [PATCH] use ninja importability when python-ninja isn't available + +--- + pytype/tools/analyze_project/pytype_runner.py | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/pytype/tools/analyze_project/pytype_runner.py b/pytype/tools/analyze_project/pytype_runner.py +index 9d09d8d0..c4579978 100644 +--- a/pytype/tools/analyze_project/pytype_runner.py ++++ b/pytype/tools/analyze_project/pytype_runner.py +@@ -1,5 +1,6 @@ + """Use pytype to analyze and infer types for an entire project.""" + ++import importlib + import collections + import itertools + import logging +@@ -46,7 +47,8 @@ def _get_executable(binary, module=None): + path_utils.abspath(path_utils.dirname(custom_bin)), + 'pytype-single') + ]) +- if sys.executable is not None: ++ importable = importlib.util.find_spec(module or binary) ++ if sys.executable is not None and importable is not None: + return [sys.executable, '-m', module or binary] + else: + return [binary] diff --git a/recipe/patches/remove-ninja-req.patch b/recipe/patches/remove-ninja-req.patch new file mode 100644 index 0000000..e44797d --- /dev/null +++ b/recipe/patches/remove-ninja-req.patch @@ -0,0 +1,13 @@ +diff --git a/setup.cfg b/setup.cfg +--- setup.cfg ++++ setup.cfg +@@ -35,9 +35,8 @@ + importlab>=0.8 + jinja2>=3.1.2 + libcst>=0.4.9 + networkx<2.8.4 +- ninja>=1.10.0.post2 + pydot>=1.4.2 + tabulate>=0.8.10 + toml>=0.10.2 + typed_ast>=1.5.0; python_version < '3.8' diff --git a/recipe/run_pytype.py b/recipe/run_pytype.py new file mode 100644 index 0000000..bd19208 --- /dev/null +++ b/recipe/run_pytype.py @@ -0,0 +1,44 @@ +""" +A short script to run pytype with a real file to check + +This should catch whether you can actually run pytype + +(in particular if pytypw works with the conda-installed ninja) + +NOTE: I suppose it would be more robust to see if it actually + does the check correctly, but that's really pytype's problem +""" +import sys +import subprocess +from pathlib import Path + +TEST_FILE = """ + +def fun(x: int): + return x * 2 + +# this should type check with no errors +y = fun(2) + +# this should type check with an error +# z = fun(2.0) +""" + +filepath = Path("python_test_file.py") + +with open(filepath, 'w', encoding='utf-8') as pyfile: + pyfile.write(TEST_FILE) + +try: + subprocess.check_call(("pytype", str(filepath))) + # it worked + sys.exit(0) +except subprocess.CalledProcessError: + # something went wrong + print("Something went wrong running pytype") + raise +finally: + filepath.unlink(missing_ok=False) + + +