Skip to content

Add ninja.__main__ #36

Description

It's weird that after installing ninja in a virtual environment one can invoke it with ./my_venv/bin/ninja but not also with ./my_venv/bin/python -m ninja.

ENVIRONMENT:
Ubuntu 20.04 LTS

STEPS TO REPRODUCE:

  1. python3.8 -m venv my_venv
  2. ./my_venv/bin/python -m pip install --upgrade pip
  3. ./my_venv/bin/python -m pip install --upgrade ninja
  4. ./my_venv/bin/ninja --version
  5. ./my_venv/bin/python -m ninja --version

EXPECTED RESULTS:
I would expect that the ./my_venv/bin/python -m ninja --version execution would produce the same output as that produced by the ./my_venv/bin/ninja --version execution.

OBSERVED RESULTS:
./my_venv/bin/python -m ninja --version outputs /home/nathaniel/temp-temp/my_venv/bin/python: No module named ninja.__main__; 'ninja' is a package and cannot be directly executed.

Activity

  1. gpshead commented on Aug 3, 2020

    @gpshead

    Why is this weird? ninja isn't Python. https://ninja-build.org/ it's a command line tool.

  2. adamchainz commented on Sep 4, 2020

    @adamchainz
    Contributor

    It makes it impossible to run ninja given only the path to a venv python executable, which can happen in another python command in that venv wanting to use sys.executable to subprocess another command known to be in that venv, e.g. google/pytype#642 (comment)

  3. jcfr commented on Sep 4, 2020

    @jcfr
    Contributor

    Thanks for the feedback 🙏

  4. linked a pull request that will close this issueAdd support for running ninja as python module #37on Sep 4, 2020
  5. nathanielmanistaatgoogle commented on Sep 7, 2020

    @nathanielmanistaatgoogle
    Author

    @gpshead: Two reasons:

    1. Given

      user@host:~/temp-temp$ ./my_venv/bin/pip --version
      pip 20.2.2 from /usr/local/google/home/nathaniel/temp-temp/my_venv/lib/python3.8/site-packages/pip (python 3.8)
      user@host:~/temp-temp$ ./my_venv/bin/python -m pip --version
      pip 20.2.2 from /usr/local/google/home/nathaniel/temp-temp/my_venv/lib/python3.8/site-packages/pip (python 3.8)
      user@host:~/temp-temp$ ./my_venv/bin/pytype --version
      2020.08.28
      user@host:~/temp-temp$ ./my_venv/bin/python -m pytype --version
      2020.08.28
      user@host:~/temp-temp$ ./my_venv/bin/pylint --version
      pylint 2.6.0
      astroid 2.4.2
      Python 3.8.5 (default, Jul 20 2020, 18:32:44) 
      [GCC 9.3.0]
      user@host:~/temp-temp$ ./my_venv/bin/python -m pylint --version
      pylint 2.6.0
      astroid 2.4.2
      Python 3.8.5 (default, Jul 20 2020, 18:32:44) 
      [GCC 9.3.0]
      user@host:~/temp-temp$ ./my_venv/bin/nuitka3 --version
      0.6.8.4
      Python: 3.8.5 (default, Jul 20 2020, 18:32:44) 
      Executable: /usr/local/google/home/nathaniel/temp-temp/my_venv/bin/python3
      OS: Linux
      Arch: x86_64
      user@host:~/temp-temp$ ./my_venv/bin/python -m nuitka --version
      0.6.8.4
      Python: 3.8.5 (default, Jul 20 2020, 18:32:44) 
      Executable: /usr/local/google/home/nathaniel/temp-temp/my_venv/bin/python
      OS: Linux
      Arch: x86_64
      user@host:~/temp-temp$ ./my_venv/bin/pyinstaller --version
      4.0
      user@host:~/temp-temp$ ./my_venv/bin/python -m PyInstaller --version
      4.0
      user@host:~/temp-temp$ ./my_venv/bin/pytest --version
      pytest 6.0.1
      user@host:~/temp-temp$ ./my_venv/bin/python -m pytest --version
      pytest 6.0.1

      one can see how one might sense a pattern, yes? ... and even if it isn't yet a convention, having played around with these utilities for a while now, it certainly is useful; it's something I'd definitely advocate promoting to be a convention.

    2. This code is hosted on PyPI not at "ninja-but-only-the-command-line-executable" but rather at "ninja". If I were looking for a library that afforded Python-language programmatic access to ninja, this would definitely be the first place where I would think to look for it, and I would be surprised if I were told that such functionality would be considered out-of-scope (rather than merely "no one has yet needed it so no one has yet implemented it", which I'm guessing is more the actual case?).

    @jcfr: thank you for #37! 🙂 It looks like it may unblock pytype issue 642.

  6. jcfr commented on Sep 10, 2020

    @jcfr
    Contributor

    it's something I'd definitely advocate promoting to be a convention.

    👍 I will add support for python -m to the cmake and castxml wheels as well

    If I were looking for a library that afforded Python-language programmatic access to ninja [...] this would definitely be the first place where I would think to look for it, and I would be surprised if I were told that such functionality would be considered out-of-scope

    Makes complete sense.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions