microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
158 stars 36 forks source link

Black 24.4.2 is not compatible Black 24.8.0 #530

Closed KelvinChung2000 closed 3 months ago

KelvinChung2000 commented 3 months ago

Diagnostic Data

Behaviour

Expected Behavior

Format with the extension will not fail the linting with latest Black

Actual Behavior

Black 24.4.2 does not passing the CI that uses Black 24.8.0

Logs:

Information on the failing CI

@@ -872,19 +871,17 @@
                 logger.warning(
                     f"Faulty padding argument, defaulting to {paddingDefault}"
                 )
                 padding = paddingDefault
         else:
-            logger.info(
-                f"No padding specified, defaulting to {paddingDefault}")
+            logger.info(f"No padding specified, defaulting to {paddingDefault}")
             padding = paddingDefault

         if 4 <= padding <= 32:
             self.fabricGen.genGeometry(padding)
             logger.info("Geometry generation complete")
-            logger.info(
-                f"{geomFile} can now be imported into the FABulous Editor")
+            logger.info(f"{geomFile} can now be imported into the FABulous Editor")
         else:
             logger.error("padding has to be between 4 and 32 inclusively!")
karthiknadig commented 3 months ago

@KelvinChung2000 If you want to use latest black, you can set black-formatter.importStrategy to fromEnvironment, and install latest black in your environment. The extension provides various ways for you to configure it so that it always matches your CI.

Here are the options:

  1. black-formatter.importStrategy allows you to use black from the environment. This means if you have different versions of black used in different projects, this will pick black from environment so always matching the project.
  2. black-formatter.path this setting allows you to set path to a black formatter. If you us the same black formatter, you can install it into a global tools environment using tools like pipx. Then point the extension to use black from that environment.

The extension itself ships with black but sometimes tools might release newer versions, and the above settings can help you use the one that works for you.