Skip to content

Commit

Permalink
Fixing bug in type hints that caused Statick with Python 3.5 to stop …
Browse files Browse the repository at this point in the history
…working.
  • Loading branch information
tdenewiler committed Mar 19, 2020
1 parent 0b96003 commit eb85f61
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dist: xenial
sudo: required
language: python
python:
- '3.5'
- '3.6'
- '3.7'
- '3.8'
Expand Down
10 changes: 5 additions & 5 deletions src/statick_tex/plugins/discovery/tex_discovery_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def get_name(self) -> str:

def scan(self, package: Package, level: str, exceptions: Exceptions = None): # pylint: disable=too-many-locals
"""Scan package looking for TeX files."""
tex_files: List[str] = []
globs: List[str] = ["*.tex", "*.bib"]
tex_files = [] # type: List[str]
globs = ["*.tex", "*.bib"] # type: List[str]

file_cmd_exists: bool = True
file_cmd_exists = True # type: bool
if not DiscoveryPlugin.file_command_exists():
file_cmd_exists = False

root: str = ''
root = '' # type: str
for root, _, files in os.walk(package.path):
for glob in globs:
for f in fnmatch.filter(files, glob):
Expand All @@ -55,7 +55,7 @@ def scan(self, package: Package, level: str, exceptions: Exceptions = None): #

print(" {} TeX files found.".format(len(tex_files)))
if exceptions:
original_file_count: int = len(tex_files)
original_file_count = len(tex_files) # type: int
tex_files = exceptions.filter_file_exceptions_early(package,
tex_files)
if original_file_count > len(tex_files):
Expand Down
28 changes: 14 additions & 14 deletions src/statick_tex/plugins/tool/chktex_tool_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def get_name(self) -> str:

def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
"""Run tool and gather output."""
flags: List[str] = []
user_flags: List[str] = self.get_user_flags(level)
flags = [] # type: List[str]
user_flags = self.get_user_flags(level) # type: List[str]
flags += user_flags
total_output: List[str] = []
total_output = [] # type: List[str]

tool_bin: str = "chktex"
tool_bin = "chktex" # type: str
for src in package["tex"]:
try:
subproc_args: List[str] = [tool_bin, src] + flags
subproc_args = [tool_bin, src] + flags # type: List[str]
output = subprocess.check_output(subproc_args,
stderr=subprocess.STDOUT,
universal_newlines=True)
Expand All @@ -58,22 +58,22 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
for output in total_output:
fname.write(output)

issues: List[Issue] = self.parse_output(total_output)
issues = self.parse_output(total_output) # type: List[Issue]
return issues

def parse_output(self, total_output: List[str]) -> List[Issue]:
"""Parse tool output and report issues."""
tool_re: str = r"(.+)\s(\d+)\s(.+)\s(.+)\s(.+)\s(\d+):\s(.+)"
parse: Pattern[str] = re.compile(tool_re)
issues: List[Issue] = []
filename: str = ''
line_number: str = "0"
issue_type: str = ''
message: str = ''
tool_re = r"(.+)\s(\d+)\s(.+)\s(.+)\s(.+)\s(\d+):\s(.+)" # type: str
parse = re.compile(tool_re) # type: Pattern[str]
issues = [] # type: List[Issue]
filename = '' # type: str
line_number = "0" # type: str
issue_type = '' # type: str
message = '' # type: str

for output in total_output:
for line in output.splitlines():
match: Optional[Match[str]] = parse.match(line)
match = parse.match(line) # type: Optional[Match[str]]
if match:
if match.group(1) == "Warning":
filename = match.group(4)
Expand Down
28 changes: 14 additions & 14 deletions src/statick_tex/plugins/tool/lacheck_tool_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def get_name(self) -> str:

def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
"""Run tool and gather output."""
flags: List[str] = []
user_flags: List[str] = self.get_user_flags(level)
flags = [] # type: List[str]
user_flags = self.get_user_flags(level) # type: List[str]
flags += user_flags
total_output: List[str] = []
total_output = [] # type: List[str]

tool_bin: str = "lacheck"
tool_bin = "lacheck" # type: str
for src in package["tex"]:
try:
subproc_args: List[str] = [tool_bin, src] + flags
subproc_args = [tool_bin, src] + flags # type: List[str]
output = subprocess.check_output(subproc_args,
stderr=subprocess.STDOUT,
universal_newlines=True)
Expand All @@ -54,22 +54,22 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
for output in total_output:
fname.write(output)

issues: List[Issue] = self.parse_output(total_output)
issues = self.parse_output(total_output) # type: List[Issue]
return issues

def parse_output(self, total_output: List[str]) -> List[Issue]:
"""Parse tool output and report issues."""
tool_re: str = r"(.+)\s(.+)\s(\d+):\s(.+)"
parse: Pattern[str] = re.compile(tool_re)
issues: List[Issue] = []
filename: str = ''
line_number: str = "0"
issue_type: str = ''
message: str = ''
tool_re = r"(.+)\s(.+)\s(\d+):\s(.+)" # type: str
parse = re.compile(tool_re) # type: Pattern[str]
issues = [] # type: List[Issue]
filename = '' # type: str
line_number = "0" # type: str
issue_type = '' # type: str
message = '' # type: str

for output in total_output:
for line in output.splitlines():
match: Optional[Match[str]] = parse.match(line)
match = parse.match(line) # type: Optional[Match[str]]
if match:
filename = match.group(1)[1:-2]
issue_type = "lacheck"
Expand Down

0 comments on commit eb85f61

Please sign in to comment.