Judge an explicitly-named file by the same rules as a file found in a directory - #191
Open
Eljees wants to merge 1 commit into
Open
Judge an explicitly-named file by the same rules as a file found in a directory#191Eljees wants to merge 1 commit into
Eljees wants to merge 1 commit into
Conversation
…tory Walking a directory accepts every extension listed in --ext, but a file passed on the command line is matched against a hard-coded list, so the same file is interrogated when it is found in a directory and rejected with exit code 1 when it is named directly. Honour --ext for named files too, and accept an extension-less file whose first line is a Python shebang. Fixes econchick#104
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The same file gets a different answer depending on how it was named on the command line:
a.ipynb, run with--ext ipynbE: Invalid file …, exit code 1a.pyi, no--ext_filter_files()(used for a directory walk) matches againstself.extensions, so it honours--ext.get_filenames_from_paths()matches an explicitly-named file against the hard-codedVALID_EXTinstead, so--extis ignored there and the run aborts withsys.exit(1).This change gives the explicit path the union of
VALID_EXTand the--extvalues (a union, so a.pyifile named directly keeps working without--ext), and additionally accepts a file that has no extension when its first line is a Python shebang. Files that do have an extension are never sniffed, soscript.shis not picked up because of its contents. The directory walk is untouched — I did not wantinterrogatereading the first bytes of every file in a tree.Motivation and Context
Fixes #104, which reports the shebang half:
interrogate bin/postgres-readyrefuses a#!/usr/bin/env pythonscript because the name lacks.py, even thoughidentify-cliandfile(1)both call it Python.The
--exthalf showed up while reproducing it, and it seems the more clear-cut of the two: the 1.7.0 changelog promises "Support forpyifile extensions (and leave room for other file extensions to be added, like maybeipynb)", and that promise currently holds for one of the two code paths only.Have you tested this? If so, how?
I have included unit tests, and I ran
interrogateon the reporter's exact command before and after.tests/functional/test_issue_104.pyhas four cases:.ipynbnamed directly with--ext ipynband an extension-less shebang script both fail onmaster(SystemExit: 1) and pass with this change; the same.ipynbfound via a directory walk, and aREADMEwith neither a shebang nor an extension (still rejected), are controls that pass either way.master, 232 passed with this change, no failures either way. (Withtabulate0.10.0, fivetest_print_results*tests fail on plainmastertoo — that is Support (and require) tabulate version 0.10.0 #189, unrelated to this change.)interrogate -vv bin/postgres-readynow prints the coverage table and exits 1 because of genuinely missing docstrings, rather than refusing the file.Checklist for PR author(s)
tox -e docsorinterrogate -c pyproject.toml(I mean, we should set a good example 😄).README.rst. (No flag changed;--extsimply now behaves as documented. Happy to add a sentence if you would like one.)README.rstanddocs/index.rstfor any new/changed CLI flags. (No CLI flags added or changed.)versionadded,versionchanged, ordeprecateddirectives. (Both new methods are private and carry.. versionadded:: 1.8.0.)Release note