Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better method for managing python black package #674

Open
nedtwigg opened this issue Aug 25, 2020 · 6 comments
Open

Better method for managing python black package #674

nedtwigg opened this issue Aug 25, 2020 · 6 comments

Comments

@nedtwigg
Copy link
Member

We are able to call black by shelling out to it on the system path, and we are able to cache its results by enforcing a version check on the binary. However, if it isn't on the path, or the version is wrong, we just show a helpful error message and let the user figure it out from there:

.fixCantFind("Try running `pip install black=={version}`, or else tell Spotless where it is with `black().pathToExe('path/to/executable')`")
.fixWrongVersion("Try running `pip install --force-reinstall black=={version}`, or else specify `black('{versionFound}')` to Spotless")

It would be nice if we could handle this better, or at least have better instructions. There are a few python plugins in the gradle ecosystem, I'll reach out to them to see if they are interested.

@japoorv
Copy link

japoorv commented Jul 21, 2022

When this is run on linux the black --version gives output

black, 22.6.0 (compiled: yes)
Python (CPython) 3.9.6

This doesn't parse with the regex version (\S*) .
We should ideally have a way to enforce this regex as well, since different executable version can have different way of showing versions too.

I see this has already been fixed, sorry for the confusion

@leicmi
Copy link

leicmi commented Aug 20, 2022

One way to "bundle" black would be to bootstrap a python-environment with black using gradle-python-envs from JetBrains:
build.gradle:

plugins{
    id "com.jetbrains.python.envs" version "0.0.31"
}
envs {
    bootstrapDirectory = new File(buildDir, 'bootstrap')
    envsDirectory = file(buildDir)
    condaenv "py_env", "3.10", [condaPackage("black")]
}
task show_black_version(type: Exec, dependsOn: 'build_envs'){
    commandLine("./build/py_env/bin/black", "--version")
}

However, this always bootstraps MiniConda and the environment, independent of whether another python installation with black already exists.
What do you think about such an approach?

@nedtwigg
Copy link
Member Author

This would work for the Gradle plugin, but not the Maven one, and that's fine with me! One way to incorporate something like this would be to add documentation to the manual on how to glue the two plugins together: https://github.com/diffplug/spotless/tree/main/plugin-gradle#black

and then do black().pathToExe('./build/py_env/bin/black')

@leicmi
Copy link

leicmi commented Aug 22, 2022

Unfortunately, it seems like this approach won't work.
I tried to set a dependency on the python-environment using spotlessPythonApply.dependsOn('build_envs') (in build.gradle), however as of now ForeignExe.confirmVersionAndGetAbsolutePath() (of spotless) seems to be executed before any Gradle tasks.

@nedtwigg
Copy link
Member Author

Ahh, yes. confirmVersionAndGetAbsolutePath is called as part of up-to-date checking... I really hope the Gradle depenency model learns to play nice with PyPI/NPM/RubyGems/etc someday...

@nedtwigg
Copy link
Member Author

@ibabel-chwy if you have a specific problem you should open a new issue and include the requested info (version, logs, etc)

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

No branches or pull requests

3 participants