Skip to content

Commit

Permalink
Merge pull request #513 from camptocamp/backport/512-to-1.1
Browse files Browse the repository at this point in the history
[Backport 1.1] Handle text/x-script.python mime type
  • Loading branch information
sbrunner authored Mar 31, 2022
2 parents f301abc + 94c37a0 commit de132fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def graphql(query_file: str, variables: Dict[str, Any], default: Any = None) ->


def get_git_files_mime(
mime_type: str = "text/x-python", ignore_patterns_re: Optional[List[str]] = None
mime_type: Optional[List[str]] = None, ignore_patterns_re: Optional[List[str]] = None
) -> List[str]:
"""
Get list of paths from git with all the files that have the specified mime type.
Expand All @@ -640,11 +640,13 @@ def get_git_files_mime(
mime_type: The considered MIME type
ignore_patterns_re: A list of regular expressions of files that we should ignore
"""
if mime_type is None:
mime_type = ["text/x-python", "text/x-script.python"]
ignore_patterns_compiled = [re.compile(p) for p in ignore_patterns_re or []]
result = []

for filename in subprocess.check_output(["git", "ls-files"]).decode().strip().split("\n"):
if os.path.isfile(filename) and magic.from_file(filename, mime=True) == mime_type:
if os.path.isfile(filename) and magic.from_file(filename, mime=True) in mime_type:
accept = True
for pattern in ignore_patterns_compiled:
if pattern.search(filename):
Expand Down
2 changes: 1 addition & 1 deletion c2cciutils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def black_config(
# If there is no python file the check is disabled
python = False
for filename in subprocess.check_output(["git", "ls-files"]).decode().strip().split("\n"):
if os.path.isfile(filename) and magic.from_file(filename, mime=True) == "text/x-python":
if os.path.isfile(filename) and magic.from_file(filename, mime=True) in ["text/x-python", "text/x-script.python"]:
python = True
break

Expand Down

0 comments on commit de132fa

Please sign in to comment.