Skip to content

added test of full command line use.#98

Merged
ngam merged 20 commits intoconda-forge:mainfrom
PythonCHB:main
Feb 22, 2023
Merged

added test of full command line use.#98
ngam merged 20 commits intoconda-forge:mainfrom
PythonCHB:main

Conversation

@PythonCHB
Copy link
Copy Markdown
Contributor

@PythonCHB PythonCHB commented Feb 20, 2023

Fix #97

Due to the issue with pytype packages being broken for ages -- thanks to the ninja python wrapper, I thought it would be handy to have a test in the recipe that tests if you can actually run pytype.

So here it is -- It's failing now, which is the point. I *think( it will pass if the issue gets resolved upstream -- but we'll see, it's hard to test that.

@conda-forge-webservices
Copy link
Copy Markdown

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

@ngam
Copy link
Copy Markdown
Contributor

ngam commented Feb 21, 2023

Hi @PythonCHB, thank you for this. If you could identify which pytype versions are "broken" with your test, then we will mark them as broken en masse. For now, I stopped releasing pytype until we figure out what to do about ninja, see #99

@conda-forge-webservices
Copy link
Copy Markdown

Hi! This is the friendly automated conda-forge-linting service.

I was trying to look for recipes to lint for you, but it appears we have a merge conflict.
Please try to merge or rebase with the base branch to resolve this conflict.

Please ping the 'conda-forge/core' team (using the @ notation in a comment) if you believe this is a bug.

@conda-forge-webservices
Copy link
Copy Markdown

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

@ngam
Copy link
Copy Markdown
Contributor

ngam commented Feb 21, 2023

@PythonCHB @eli-schwartz @henryiii could you have a look if this hacky solution is good enough?

I think I will want to mark everything before this as broken, but I am happy to hear your thoughts. Thanks!

Comment thread recipe/patches/patch-ninja-exe.patch Outdated
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")]
Copy link
Copy Markdown

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?

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.

Well, it never falls back on None when inside a conda env, but good question! What should it fall on then?

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.

I will skip the logic if CONDA_PREFIX isn’t available. I think that’s the goal.

Copy link
Copy Markdown
Contributor Author

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:

try:
    subprocess.call('ninja')
    ninja_exe = 'ninja'
except FileNotFoundError:
    ninja_exe = 'python -m ninja'

or

try:
    import ninja
    ninja_exe = 'python -m ninja'
except ImportError:
    ninja_exe = 'ninja'

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.

Copy link
Copy Markdown

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:

TypeError: expected str, bytes or os.PathLike object, not NoneType

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(), use os.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 a KeyError: '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-installed ninja is always in $PATH whenever the conda-installed pytype is.

Copy link
Copy Markdown

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.

Indeed.

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.

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.ninja files are parsed -- it's totally invisible.

Copy link
Copy Markdown
Contributor Author

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

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.

Feedback well taken. I obvz was only thinking about conda-forge (because does anything else exist?!?!?!)

will incorporate edits soon

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.

I think I addressed your feedback. Will merge in ~2–3 days unless there are more issues

@PythonCHB
Copy link
Copy Markdown
Contributor Author

Hi @PythonCHB, thank you for this. If you could identify which pytype versions are "broken" with your test, then we will mark them as broken en masse.

I went back to a year ago -- and no luck, I think this has been broken for a long time :-(

I"m kinda surprised there haven't been nore complaints -- maybe folks aren't using the pacakge, or they are either:

  • pip instalilng ninja and being done with it
    or
  • using some other pacakge that installed the python ninja package

I"ll try to go back an find a working version tonight.

@ngam
Copy link
Copy Markdown
Contributor

ngam commented Feb 22, 2023

Most people would use in the ci, that’s how I used it :) and in the ci, you would just get it from pypi

Comment thread recipe/patches/patch-ninja-exe.patch Outdated
Comment on lines +20 to +23
+ 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)

])
- 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.

@ngam ngam merged commit d51d80e into conda-forge:main Feb 22, 2023
@ngam
Copy link
Copy Markdown
Contributor

ngam commented Feb 22, 2023

Thanks @eli-schwartz and @PythonCHB. (You're welcome to add yourselves as maintainers if you'd like.)

Learned quite a bit from you, and had good fun doing this, albeit with a headache after a lengthy day with crazy numerical models...

@PythonCHB
Copy link
Copy Markdown
Contributor Author

@ngam: Thanks for making the pytype PR -- that's great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pytype package is broken due to missing python ninja package.

3 participants