Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
27 changes: 27 additions & 0 deletions recipe/patches/patch-ninja-exe.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/pytype/tools/analyze_project/pytype_runner.py b/pytype/tools/analyze_project/pytype_runner.py
--- pytype/tools/analyze_project/pytype_runner.py
+++ pytype/tools/analyze_project/pytype_runner.py
@@ -45,12 +45,20 @@
path_utils.join(
path_utils.abspath(path_utils.dirname(custom_bin)),
'pytype-single')
])
- if sys.executable is not None:
- return [sys.executable, '-m', module or binary]
+ elif binary == 'ninja':
+ try:
+ import ninja
+ to_return = [sys.executable, '-m', module or binary]
+ except ImportError:
+ to_return = [binary]
+ return to_return
else:
- return [binary]
+ if sys.executable is not None:
+ return [sys.executable, '-m', module or binary]
+ else:
+ return [binary]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The diff hunk would be slightly smaller here if you preserved the indentation for the sys.executable check and just switched it to an elif, rather than nesting it inside of an else.

That's really just style, so it doesn't matter one way or another, just thought I'd mention it.

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.

Ugh, something isn't working...

TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
Something went wrong running pytype

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.

what in this is returning a None? I had a loooooong day... :(

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.

(Will incorporate your suggestion once confirmed to work btw)

PYTYPE_SINGLE = _get_executable('pytype-single', 'pytype.single')


def resolved_file_to_module(f):
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)