Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -59,15 +62,16 @@ test:
imports:
- pytype
- pytype.overlays
files:
- run_pytype.py
commands:
- annotate-ast --help
- merge-pyi --help
- pytd --help
- 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
Expand Down
30 changes: 30 additions & 0 deletions recipe/patches/patch-ninja-exe.patch
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eli-schwartz I hope you're damn proud of this 😆

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a pretty good idea, yes.

return [sys.executable, '-m', module or binary]
else:
return [binary]
13 changes: 13 additions & 0 deletions recipe/patches/remove-ninja-req.patch
Original file line number Diff line number Diff line change
@@ -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'
44 changes: 44 additions & 0 deletions recipe/run_pytype.py
Original file line number Diff line number Diff line change
@@ -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)