-
-
Notifications
You must be signed in to change notification settings - Fork 8
added test of full command line use. #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f228c26
added test of full command line use.
PythonCHB 642acbe
try patching ninja exe
ngam 62a2464
add patch
ngam 090b22b
Merge branch 'main' into main
ngam 40a7ea0
fix typo
ngam e21fe9e
Create remove-ninja-req.patch
ngam 141b6f0
Update meta.yaml
ngam 83f9241
fix indent
ngam dabe931
return list to be consistent
ngam 3d945da
only change when getting the ninja exe
ngam bb71424
remove from setup.cfg not reqs.txt
ngam f0b9e94
fix patch after feedback
ngam 86b3a71
fix patch again
ngam bb3a81f
typo
ngam 79812a8
modulenotfound
ngam 35ff226
better?
ngam 944bea3
import lib
ngam bf8da73
finally...
ngam 76a2a69
typo
ngam 2246cd4
format patch
ngam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 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 | ||
| @@ -1,6 +1,7 @@ | ||
| """Use pytype to analyze and infer types for an entire project.""" | ||
|
|
||
| +import os | ||
| import collections | ||
| import itertools | ||
| import logging | ||
| import subprocess | ||
| @@ -36,8 +37,10 @@ | ||
|
|
||
|
|
||
| def _get_executable(binary, module=None): | ||
| """Get the path to the executable with the given name.""" | ||
| + if binary == "ninja": | ||
| + return [os.path.join(os.environ.get("CONDA_PREFIX", None), "bin", "ninja")] | ||
| if binary == 'pytype-single': | ||
| custom_bin = path_utils.join('out', 'bin', 'pytype') | ||
| if sys.argv[0] == custom_bin: | ||
| # The Travis type-check step uses custom binaries in pytype/out/bin/. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
|
|
||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this actually supposed to do when os.environ.get() falls back on None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it never falls back on None when inside a conda env, but good question! What should it fall on then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will skip the logic if CONDA_PREFIX isn’t available. I think that’s the goal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a patch specifically for the conda package, it may be OK. But ideally, we'd have a patch that the pytype folks could apply for universal use, So relying on CONDA_PREFIX is not great.
How about something like:
or
which would prioritize teh pip-installed ninja if it's there.
But ideally this would get fixed upstream -- if pytype actually relies on something specific about the python ninja package, or even is only tested with it, then maybe we should jsut follow theri wishes and provide the package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you can't join None, that's just going to print a completely bizarre:
If the environment variable ever doesn't exist.
This is why I asked what it's supposed to do. Supposed to! I'm not asking what it does, I know what it does.
I think asking "what should it fall back on then" is approaching the question from the wrong direction. The question is not what default to use to avoid a KeyError for an unset environment variable. The question instead is...
... When and why can that environment variable be unset? Is there ever a valid reason for it to be unset?
If it can't ever be unset, then don't use
.get(), useos.environ['CONDA_PREFIX']. And if that ever fails, then the user gets a much clearer error. Instead of "expected str, bytes or os.Pathlike", they get aKeyError: 'CONDA_PREFIX'which points the finger at conda's environment setup.Falling back on None actually makes the error message worse.
...
Is there any specific reason to not just return
'ninja'without a full path? My assumption is that the conda-installedninjais always in $PATH whenever the conda-installedpytypeis.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed.
The python ninja package is effectively identical to regular C++ ninja with the exception of a couple patches from an open PR to ninja, which add support for detecting a parent GNU make process and attach to GNU make's jobserver. This doesn't change how users interact with ninja, and doesn't change how
build.ninjafiles are parsed -- it's totally invisible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's hope the pytype folks appreciate that and fix their code then.
But in any case, it would be better find a solution that is not conda-specific -- could it use "which" on *nix and "where" on Windows?
Better yet:
shutil.which-CHB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feedback well taken. I obvz was only thinking about conda-forge (because does anything else exist?!?!?!)
will incorporate edits soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I addressed your feedback. Will merge in ~2–3 days unless there are more issues