black icon indicating copy to clipboard operation
black copied to clipboard

typing_extensions module not installed under Python3.10

Open Skyline124 opened this issue 4 years ago • 4 comments

Hey there!

I just noticed that under the following configuration:

  • Ubuntu 20.04 with the following kernel: Linux ubuntu 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • Using python 3.10 installed via apt from the ppa:deadsnakes/ppa repository:
    • Python 3.10.8 (main, Oct 12 2022, 19:14:26) [GCC 9.4.0] on linux
    • pip 22.3.1 from ~/black_test/lib/python3.10/site-packages/pip (python 3.10)

Installing black on version 22.10.0 under python3.10 does not propagate the installation of typing-extensions, and one of our calls to python3.10 -m black ... seems to be failing in this case. Until we manually install the typing-extensions module via pip, and then everything seems back on track.

In the versions 3.8 and 3.9 of python, the command pip install black==22.10.0 properly propagates the typing-extension (version 4.4.0).

So my questions here are:

  • Is this expected?
  • If it is, is there something special about python3.10 that enables black not to rely on typing-extensions that I'm missing?

Skyline124 avatar Nov 30 '22 05:11 Skyline124

Yes, this is expected. When running using Python 3.10 black does not import typing_extensions, so it does not declare a dependency either. What is the failure you are seeing?

hauntsaninja avatar Nov 30 '22 08:11 hauntsaninja

Thanks for the super fast response! I figured as such, I will have a little more dig then, trying to figure out more precisely what is going on...

Skyline124 avatar Nov 30 '22 20:11 Skyline124

As a matter of fact, the problem was an awkward python subprocess call from our side.

We were calling subprocess.run("python3 -m black ...files...") from within a python file, running with python3.10 properly configured under bazel run.

However, the python3 executable used inside the subprocess.run function call was actually using whatever python3 binary was setup in the terminal where we started the bazel run command, but it was not using the bazel python environment we expected, hence the failure. It was somehow working with the previous versions of python which is probably due to some configuration luck. But we fixed it by importing and calling the main function from the black module inside out python instead of calling an external subprocess:

from black import main
main(["...files..."])

Apologies for this, I'm closing, thanks for the attention @hauntsaninja!

Skyline124 avatar Dec 01 '22 01:12 Skyline124

You may want to learn to use sys.executable :)

JelleZijlstra avatar Dec 01 '22 03:12 JelleZijlstra