Skip to content

Remove black as a dependency #36

Closed
benhowes wants to merge 4 commits intoMadoshakalaka:masterfrom
benhowes:patch-1
Closed

Remove black as a dependency #36
benhowes wants to merge 4 commits intoMadoshakalaka:masterfrom
benhowes:patch-1

Conversation

@benhowes
Copy link

@benhowes benhowes commented Nov 14, 2020

Fixes #34

Originally this PR just attempted to relax the version pinning, however, that did not work as expected.

Looking at the code in more detail it seems that this library includes support for not having black present in any case, so it's probably better to not have it as a hard dependency.

@benhowes benhowes marked this pull request as ready for review November 14, 2020 08:52
@codecov-io
Copy link

codecov-io commented Nov 14, 2020

Codecov Report

Merging #36 (9d8c812) into master (2b66c23) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #36   +/-   ##
=======================================
  Coverage   94.63%   94.63%           
=======================================
  Files          10       10           
  Lines         745      745           
=======================================
  Hits          705      705           
  Misses         40       40           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b66c23...a334b3c. Read the comment docs.

@benhowes benhowes changed the title Relax black version pinning Remove black as a dependency Nov 15, 2020
"pytest-xdist~=1.29",
"tox~=3.14",
"autopep8~=1.4",
"black~=20.8b1; python_version >= '3.6'",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that an update to the latest version would not be a problem!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black formats differently based on its version, so black should probably be pinned in the projects using this library, not here. If it must be here, then probably having it be any version makes more sense?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Madoshakalaka thoughts? This issue (#34) is causing problems for us.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grizz I've moved the requirement to the dev requirements in this PR, so it won't attempt to install black at all when you use it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also running into this issue. Wouldn't upgrading the dev black dependency require reformatting this code base (though I suppose a follow-up PR would be appropriate for that)?

Aside from that, I def like this solution, FWIW.

Comment on lines +150 to +164
else:
with Popen(
[sys.executable, "-m", "black", str(file)], stdout=PIPE, stderr=PIPE
) as p:
p.communicate()

except ImportError:
# use autopep8
import autopep8

code = autopep8.fix_code(file.read_text())
file.write_text(code)
try:
import autopep8
else:
code = autopep8.fix_code(file.read_text())
file.write_text(code)
except ImportError:
raise RuntimeError("Either black or autopep8 must be installed.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else before except block is a syntax error; I'd recommend the following:

    except ImportError:
        # use autopep8
        try:
            # third party
            import autopep8
        except ImportError:
            raise RuntimeError("Either black or autopep8 must be installed.")
        else:
            code = autopep8.fix_code(file.read_text())
            file.write_text(code)
    else:
        with Popen(
            [sys.executable, "-m", "black", str(file)], stdout=PIPE, stderr=PIPE
        ) as p:
            p.communicate()

@benhowes
Copy link
Author

benhowes commented Feb 2, 2022

Solved better in #88

@benhowes benhowes closed this Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict dependency on black prevents usage of the latest black

4 participants