First time here? Check out the FAQ!
1

Auto-format stops working after upgrade from 7 to 8

I recently upgraded from Wing 7 to Wing 8. Auto-formating using any of Black, PEP8 or Yapf no longer works.

I've checked the settings in both "Edit -> Preferences -> Editor -> Auto-formatting" and "Project -> Project Properties -> Options -> Auto-reformat". They both agree with "Auto-Reformat: Whole Files Before Save", and "Reformatter: Black".

I start Wing on Ubuntu 21.10 in a Python 3.10.2 virtual env. I have confirmed that all of black, pep8, yapf are installed and import properly in the Wing Python Shell under Py3.10.

Suggestions?

K Lars Lohn's avatar
11
K Lars Lohn
asked 2022-02-11 16:05:52 -0500
Wingware Support's avatar
4.1k
Wingware Support
updated 2022-02-12 10:43:31 -0500
edit flag offensive 0 remove flag close merge delete

Comments

Could you please send us a bug report from Wing's Help menu or the end of the ide.log file from the Settings Directory listed in Wing's about box, right after trying and failing to do a reformat? That may show us what is failing. Thanks!

Wingware Support's avatar Wingware Support (2022-02-12 11:44:35 -0500) edit

Thanks for the pointer to the log file.

The reformat fails because the version of "black" that the IDE invokes doesn't understand the 3.10.2 structural pattern matching construct. It gives this error: "error: cannot format /home/lars/.cache/wingpro8/tmp/3564325/tmpkuw8lchg.py: Cannot parse: 53:14: match the_other, len(the_other):".

If I invoke "black" from the command line in my venv, "black" succeeds in reformatting.

Further exploration of the log show that the IDE is invoking black with '--target-version', 'py39' parameters.

Have I missed a config parameter that is supposed to inform the IDE as to the version of Python I want?

I checked my "Project -> Environment" setup where I have the Python Executable set to "Activated Env: /home/lars/venv/py310/bin/activate"

I realize that there is another parallel problem going on that could stem from the same issue. Syntax highlighting in the ... (more)

K Lars Lohn's avatar K Lars Lohn (2022-02-12 13:55:46 -0500) edit

I think black did not have --target-version py310 the last time I looked at this, but perhaps it's available now. This has been an annoying part of supporting black -- the fact that it lags behind Python and does weird things with what Python version it's checking for. We'll revisit this since maybe specifying --target-version at all is a mistake, but I seem to remember there was some reason it was needed.

That said, Wing runs black with /path/to/your/python -m black so it seems like it should be running the right one. Is the Python Shell in Wing showing that it's running Python 3.10?

In terms of Wing not understanding 3.10.2 patterning matching construct: It may be something we missed, and need to add support for, but I need to check with someone else here and can't right at the ... (more)

Wingware Support's avatar Wingware Support (2022-02-12 21:02:46 -0500) edit

Is the Python Shell in Wing showing that it's running Python 3.10? yes, the Python Shell in Wing is correctly running Python 3.10 from my venv

I think black did not have --target-version py310 black added support for py310 structural pattern matching in May 2021: https://github.com/psf/black/issues/2242

...an annoying part of supporting black...it lags behind Python I believe that much of Python versioning, distribution, packaging, etc is chaos. I commend you for staying as current as you do.

K Lars Lohn's avatar K Lars Lohn (2022-02-13 10:18:21 -0500) edit

Yup, looks like this shipped in Black in Nov 2021... times does fly. We'll try to fix this soon to send the py310 flag. Or perhaps to not send any flag if that works now.

Wingware Support's avatar Wingware Support (2022-02-14 09:41:00 -0500) edit
add a comment see more comments

1 Answer

0

Invocation of Black when using Python 3.10 should be fixed in our next release (version 8.2). We will still end up sending --target-version on the command line when we invoke it, since its default is to auto-detect based on the file contents and it seems better to be explicit about which Python version is being used. We may revisit later, though, as it'll probably become an issue again with Python 3.11.

Wingware Support's avatar
4.1k
Wingware Support
answered 2022-02-14 09:51:56 -0500
edit flag offensive 0 remove flag delete link

Comments

great, thank you for your attention to this.

K Lars Lohn's avatar K Lars Lohn (2022-02-14 10:40:37 -0500) edit

I confirm that formating now works properly under 8.2

K Lars Lohn's avatar K Lars Lohn (2022-02-20 15:57:55 -0500) edit

Thanks, good to know.

Wingware Support's avatar Wingware Support (2022-02-21 11:09:23 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer