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

Running diff-quality with a tool which is not installed gives FIleNotFoundError rather than helpful "<tool> is not installed" error message #378

Closed
dperl-dls opened this issue Dec 13, 2023 · 2 comments · Fixed by #380

Comments

@dperl-dls
Copy link
Contributor

dperl-dls commented Dec 13, 2023

Steps to reproduce:

  • make an empy Python3.10 virtual environment
  • install diff_cover
  • navigate to a repo with something in the diff
  • run e.g. diff-quality --violations=pydocstyle
    • Output: Failure: '[Errno 2] No such file or directory: 'pydocstyle''

Expected behaviour:

The output is instead Failure: 'pydocstyle is not installed'

Suggested resolution:

If diff_cover.command_runner.run_command_for_code is edited to be:

def run_command_for_code(command):
    """
    Returns command's exit code.
    """
    try:
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        process.communicate()
    except FileNotFoundError:
        return 1
    return process.returncode

Then the output is as expected. Setting shell=True in Popen equally works. See https://docs.python.org/3.11/library/subprocess.html#exceptions

Edit: I see this is actually a dupe of #303, sorry about that

@Bachmann1234
Copy link
Owner

I dont mind a dupe when Ican get more details (not to mention a pr).

Running the test suite now

dperl-dls added a commit to dperl-dls/diff_cover that referenced this issue Dec 14, 2023
Bachmann1234 added a commit that referenced this issue Dec 16, 2023
…hich is not installed (#380)

* #378 Add shell=True to check for program existence

* Update command_runner.py

Black is upset, looks like the change is simple enough

* #378 Explicitly check for FileNotFound instead

---------

Co-authored-by: Matt Bachmann <Bachmann1234@users.noreply.github.com>
@Bachmann1234
Copy link
Owner

@dperl-dls https://pypi.org/project/diff-cover/8.0.2/ is released with your PR in it. Thanks again!

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