Coding style.
- Linting.
This commit is contained in:
parent
b2e6ab2c3e
commit
4a2f99d795
16 changed files with 55 additions and 64 deletions
|
|
@ -17,7 +17,6 @@ directory.
|
|||
|
||||
|
||||
import asyncio
|
||||
import collections
|
||||
import contextlib
|
||||
import functools
|
||||
import gzip
|
||||
|
|
@ -317,9 +316,9 @@ class Summary:
|
|||
if sum(stats) != 0:
|
||||
log_filesystem_changed(log, *stats)
|
||||
with self.keep_selection():
|
||||
self._column, self._cache, self.result_total, self.completed_total, \
|
||||
self._max_width, self._max_path_length, \
|
||||
self.closest_placeholder_generator, self._all_results = (
|
||||
(self._column, self._cache, self.result_total,
|
||||
self.completed_total, self._max_width, self._max_path_length,
|
||||
self.closest_placeholder_generator, self._all_results) = (
|
||||
new_column, new_cache, result_total, completed_total,
|
||||
max_width, max_path_length, None, all_results)
|
||||
if jobs_added:
|
||||
|
|
@ -649,6 +648,7 @@ class Screen:
|
|||
self._is_fullscreen = False
|
||||
self._make_widgets()
|
||||
self._key_map = make_key_map(Screen._KEY_DATA)
|
||||
self._last_mouse_position = 0, 0
|
||||
|
||||
def __getstate__(self):
|
||||
state = self.__dict__.copy()
|
||||
|
|
@ -876,7 +876,7 @@ class Screen:
|
|||
self._log.log_message([in_green("Opening "), path_colored,
|
||||
in_green("…")])
|
||||
subprocess.Popen(["xdg-open", path], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
def save(self):
|
||||
worker.Worker.unsaved_jobs_total = 0
|
||||
|
|
@ -901,12 +901,14 @@ class Screen:
|
|||
|
||||
def _is_switching_focus(self, x, y, view_width, view_height):
|
||||
return (not self._is_fullscreen and
|
||||
(self._is_listing_portrait and (x > view_width and
|
||||
self._is_summary_focused or x <= view_width and
|
||||
not self._is_summary_focused) or
|
||||
not self._is_listing_portrait and (y > view_height and
|
||||
self._is_summary_focused or y <= view_height and
|
||||
not self._is_summary_focused)))
|
||||
(self._is_listing_portrait and
|
||||
(x > view_width and
|
||||
self._is_summary_focused or x <= view_width and
|
||||
not self._is_summary_focused) or
|
||||
not self._is_listing_portrait and
|
||||
(y > view_height and
|
||||
self._is_summary_focused or y <= view_height and
|
||||
not self._is_summary_focused)))
|
||||
|
||||
def _on_mouse_event(self, event):
|
||||
x, y = event[2:4]
|
||||
|
|
@ -1072,8 +1074,8 @@ def load_state(pickle_path, jobs_added_event, appearance_changed_event,
|
|||
return summary, screen, log, is_first_run
|
||||
|
||||
|
||||
def main(root_path, loop, worker_count=None, editor_command=None, theme=None, compression=None,
|
||||
is_being_tested=False):
|
||||
def main(root_path, loop, worker_count=None, editor_command=None, theme=None,
|
||||
compression=None, is_being_tested=False):
|
||||
if worker_count is None:
|
||||
worker_count = max(multiprocessing.cpu_count() - 1, 1)
|
||||
if theme is None:
|
||||
|
|
|
|||
|
|
@ -20,9 +20,6 @@ import eris.termstr as termstr
|
|||
|
||||
|
||||
def appearance_is_valid(appearance):
|
||||
"""An appearance is a list of strings of equal length.
|
||||
|
||||
An empty list is valid. Empty strings are not allowed."""
|
||||
return (all(isinstance(line, (str, termstr.TermStr)) and len(line) > 0
|
||||
for line in appearance) and
|
||||
len(set(len(line) for line in appearance)) < 2)
|
||||
|
|
@ -45,9 +42,6 @@ def appearance_dimensions(appearance):
|
|||
|
||||
|
||||
def join(seperator, parts):
|
||||
"""Returns a string if all the parts and the seperator are plain strings.
|
||||
|
||||
In other words it returns a TermStr if anything is a TermStr."""
|
||||
if parts == []:
|
||||
return ""
|
||||
try:
|
||||
|
|
@ -179,8 +173,8 @@ class Filler:
|
|||
|
||||
class ScrollBar:
|
||||
|
||||
_PARTIAL_CHARS = (["█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"]
|
||||
,[" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"])
|
||||
_PARTIAL_CHARS = (["█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"],
|
||||
[" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"])
|
||||
DEFAULT_BAR_COLOR = termstr.Color.grey_100
|
||||
DEFAULT_BACKGROUND_COLOR = termstr.Color.grey_30
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
This can be useful when initially reading a codebase.
|
||||
"""
|
||||
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ def get_color_codes(environment):
|
|||
if "LS_COLORS" in environment:
|
||||
try:
|
||||
return _parse_ls_colors(environment["LS_COLORS"])
|
||||
except:
|
||||
except Exception:
|
||||
syslog.syslog("Syntax error in LS_COLORS environment variable. "
|
||||
"Using default colors.")
|
||||
return _DEFAULT_COLOR_CODES
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class PagedList:
|
|||
def __len__(self):
|
||||
return self._len
|
||||
|
||||
def _get_page(self, index): # This is cached, see setup_page_cache.
|
||||
def _get_page_org(self, index): # This is cached, see setup_page_cache.
|
||||
pickle_path = os.path.join(self.pages_dir, str(index))
|
||||
with self.open_func(pickle_path, "rb") as file_:
|
||||
return pickle.load(file_)
|
||||
|
|
@ -63,7 +63,8 @@ class PagedList:
|
|||
return self._get_page(page_index)[page_offset]
|
||||
|
||||
def _setup_page_cache(self):
|
||||
self._get_page = functools.lru_cache(self.cache_size)(self._get_page)
|
||||
self._get_page = functools.lru_cache(self.cache_size)(
|
||||
self._get_page_org)
|
||||
|
||||
def __getstate__(self): # Don't pickle the lru_cache.
|
||||
state = self.__dict__.copy()
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
# Licensed under the Artistic License 2.0.
|
||||
|
||||
|
||||
"""Termstr strings contain characters that have color and style."""
|
||||
|
||||
|
||||
import collections
|
||||
import functools
|
||||
import html
|
||||
|
|
@ -24,7 +21,6 @@ xterm_colormap = eris.ColorMap.XTermColorMap()
|
|||
|
||||
@functools.lru_cache()
|
||||
def xterm_color_to_rgb(color_index):
|
||||
"""Return the rgb color of an xterm color."""
|
||||
return eris.ColorMap._rgb(xterm_colormap.colors[color_index])
|
||||
|
||||
|
||||
|
|
@ -39,7 +35,6 @@ def _cache_first_result(user_function):
|
|||
|
||||
|
||||
class Color:
|
||||
"""A list of common colors."""
|
||||
|
||||
# https://en.wikipedia.org/wiki/Natural_Color_System
|
||||
black = (0, 0, 0)
|
||||
|
|
@ -61,10 +56,6 @@ class Color:
|
|||
|
||||
|
||||
class CharStyle:
|
||||
"""Characters have a foreground and background color, and styles.
|
||||
|
||||
The styles are bold, italic or underlined.
|
||||
"""
|
||||
|
||||
_POOL = weakref.WeakValueDictionary()
|
||||
_TERMINAL256_FORMATTER = \
|
||||
|
|
@ -109,7 +100,7 @@ class CharStyle:
|
|||
return (f"<CharStyle: fg:{self.fg_color} bg:{self.bg_color}"
|
||||
f" attr:{','.join(attributes)}>")
|
||||
|
||||
def termcode_of_color(self, color, is_foreground):
|
||||
def _color_code(self, color, is_foreground):
|
||||
if isinstance(color, int):
|
||||
return terminal.color(color, is_foreground)
|
||||
else: # true color
|
||||
|
|
@ -122,13 +113,15 @@ class CharStyle:
|
|||
|
||||
@_cache_first_result
|
||||
def code_for_term(self):
|
||||
fg_termcode = terminal.ESC + self.termcode_of_color(self.fg_color, True)
|
||||
bg_termcode = terminal.ESC + self.termcode_of_color(self.bg_color, False)
|
||||
fg_termcode = terminal.ESC + self._color_code(self.fg_color, True)
|
||||
bg_termcode = terminal.ESC + self._color_code(self.bg_color, False)
|
||||
bold_code = (terminal.ESC + terminal.bold) if self.is_bold else ""
|
||||
italic_code = (terminal.ESC + terminal.italic) if self.is_italic else ""
|
||||
underline_code = (terminal.ESC + terminal.underline) if self.is_underlined else ""
|
||||
return "".join([terminal.ESC, terminal.normal, fg_termcode, bg_termcode,
|
||||
bold_code, italic_code, underline_code])
|
||||
italic_code = ((terminal.ESC + terminal.italic)
|
||||
if self.is_italic else "")
|
||||
underline_code = ((terminal.ESC + terminal.underline)
|
||||
if self.is_underlined else "")
|
||||
return "".join([terminal.ESC, terminal.normal, fg_termcode,
|
||||
bg_termcode, bold_code, italic_code, underline_code])
|
||||
|
||||
def as_html(self):
|
||||
bold_code = "font-weight:bold; " if self.is_bold else ""
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
import contextlib
|
||||
import enum
|
||||
import functools
|
||||
import gzip
|
||||
import importlib
|
||||
import importlib.resources
|
||||
import math
|
||||
|
|
@ -325,7 +324,8 @@ def python_coverage(path):
|
|||
return Status.not_applicable, f'No "{coverage_path}" file.'
|
||||
if os.stat(path).st_mtime > os.stat(coverage_path).st_mtime:
|
||||
return (Status.not_applicable,
|
||||
f'File has been modified since "{coverage_path}" file was generated.')
|
||||
f'File has been modified since "{coverage_path}"'
|
||||
' file was generated.')
|
||||
path = os.path.normpath(path)
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
_do_command([PYTHON_EXECUTABLE, "-m", "coverage",
|
||||
|
|
@ -473,6 +473,7 @@ def make_tool_function(dependencies, command, url=None, success_status=None,
|
|||
return func
|
||||
|
||||
|
||||
elinks, git_blame, git_log = None, None, None # For linters.
|
||||
with importlib.resources.open_text(eris, "tools.toml") as tools_toml_file:
|
||||
tools_toml = toml.load(tools_toml_file)
|
||||
tools_for_extensions = tools_toml["tools_for_extensions"]
|
||||
|
|
@ -556,8 +557,8 @@ class Result:
|
|||
if self.status == Status.pending or self.compression is None:
|
||||
return unknown_label
|
||||
try:
|
||||
with compression_open_func(self.compression)(self.pickle_path, "rb") \
|
||||
as pickle_file:
|
||||
with compression_open_func(self.compression)(
|
||||
self.pickle_path, "rb") as pickle_file:
|
||||
return pickle.load(pickle_file)
|
||||
except FileNotFoundError:
|
||||
return unknown_label
|
||||
|
|
@ -614,7 +615,8 @@ class Result:
|
|||
Result.result.fget.evict(self)
|
||||
|
||||
def as_html(self):
|
||||
html, styles = termstr.TermStr(STATUS_TO_TERMSTR[self.status]).as_html()
|
||||
html, styles = termstr.TermStr(
|
||||
STATUS_TO_TERMSTR[self.status]).as_html()
|
||||
return (f'<a title="{self.tool.__name__}" '
|
||||
f'href="{self.path}/{self.tool.__name__}">{html}</a>', styles)
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ tools_for_extensions = [
|
|||
[pydocstyle]
|
||||
dependencies = ["pip/pydocstyle"]
|
||||
url = "http://www.pydocstyle.org/en/2.1.1/usage.html"
|
||||
command = "python3.8 -m pydocstyle --ignore=D1"
|
||||
command = "python3.8 -m pydocstyle --ignore=D1,D213"
|
||||
|
||||
[pyflakes]
|
||||
dependencies = ["pip/pyflakes"]
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ Example:
|
|||
def make_page(body_html, title):
|
||||
return (f"<html><head><title>{title}</title></head><body><style>body "
|
||||
f"{{ background-color: black; }} </style>{body_html}</body></html>"
|
||||
).encode("utf-8")
|
||||
).encode("utf-8")
|
||||
|
||||
|
||||
class Webserver(http.server.BaseHTTPRequestHandler):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
import asyncio
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
|
||||
import eris.fill3 as fill3
|
||||
|
|
@ -37,12 +36,13 @@ class Worker:
|
|||
os.setpriority(os.PRIO_PGRP, self.child_pgid, 19)
|
||||
|
||||
async def run_tool(self, path, tool):
|
||||
self.process.stdin.write(f"{tool.__qualname__}\n{path}\n".encode("utf-8"))
|
||||
self.process.stdin.write(
|
||||
f"{tool.__qualname__}\n{path}\n".encode("utf-8"))
|
||||
data = await self.process.stdout.readline()
|
||||
return tools.Status(int(data))
|
||||
|
||||
async def job_runner(self, screen, summary, log, jobs_added_event,
|
||||
appearance_changed_event):
|
||||
appearance_changed_event):
|
||||
await self.create_process()
|
||||
self.process.stdin.write(f"{self.compression}\n".encode("utf-8"))
|
||||
while True:
|
||||
|
|
@ -108,7 +108,7 @@ def main():
|
|||
status, text = tools.run_tool_no_error(path, tool)
|
||||
result.result = make_result_widget(text, result, compression)
|
||||
print(status.value, flush=True)
|
||||
except:
|
||||
except Exception:
|
||||
tools.log_error()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,9 @@ then to run:
|
|||
Extensions({len(extension_set)-1}) | Tools({len(tool_set)})
|
||||
----------:| -----""")
|
||||
for extensions, tools_ in all_tools:
|
||||
print("%s | %s" % (" ".join("." + extension for extension in extensions),
|
||||
" • ".join(tool_markup(tool) for tool in tools_)))
|
||||
print("%s | %s" % (
|
||||
" ".join("." + extension for extension in extensions),
|
||||
" • ".join(tool_markup(tool) for tool in tools_)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ def umount_squashfs_iso(mount_point):
|
|||
|
||||
def run_in_container(container, command):
|
||||
option = "--directory" if os.path.isdir(container) else "--image"
|
||||
cmd(f"sudo systemd-nspawn --quiet --chdir=/eris --overlay={ERIS_PATH}:/eris "
|
||||
f'{option}={container} /bin/bash --login -c "{command}"')
|
||||
cmd(f"sudo systemd-nspawn --quiet --chdir=/eris --overlay={ERIS_PATH}:"
|
||||
f'/eris {option}={container} /bin/bash --login -c "{command}"')
|
||||
|
||||
|
||||
def build_ubuntu():
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ class ScreenWidgetTestCase(unittest.TestCase):
|
|||
appearance_changed_event = asyncio.Event()
|
||||
summary = __main__.Summary(self.temp_dir, jobs_added_event)
|
||||
log = __main__.Log(appearance_changed_event)
|
||||
self.main_widget = __main__.Screen(summary, log, appearance_changed_event,
|
||||
_MockMainLoop())
|
||||
self.main_widget = __main__.Screen(
|
||||
summary, log, appearance_changed_event, _MockMainLoop())
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
|
@ -173,7 +173,7 @@ class SummarySyncWithFilesystem(unittest.TestCase):
|
|||
# self.assertFalse(self.jobs_added_event.is_set())
|
||||
|
||||
def test_sync_linked_files(self):
|
||||
"""Symbolic and hard-linked files are given distinct entry objects"""
|
||||
"""Symbolic and hard-linked files are given distinct entry objects."""
|
||||
baz_path = os.path.join(self.temp_dir, "baz")
|
||||
os.symlink(self.foo_path, baz_path)
|
||||
os.link(self.foo_path, self.zoo_path)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
import unittest
|
||||
|
||||
import eris.fill3 as fill3
|
||||
import eris.termstr as termstr
|
||||
|
||||
|
||||
class WidgetTests(unittest.TestCase):
|
||||
|
|
@ -78,7 +77,7 @@ class WidgetTests(unittest.TestCase):
|
|||
def assert_string2(self, appearance, expected_string):
|
||||
self.assertEqual(
|
||||
("\n".join(line.data for line in appearance),
|
||||
"".join("i" if style.fg_color==
|
||||
"".join("i" if style.fg_color ==
|
||||
fill3.ScrollBar.DEFAULT_BACKGROUND_COLOR else " "
|
||||
for line in appearance for style in line.style)),
|
||||
expected_string)
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class ToolsTestCase(unittest.TestCase):
|
|||
self._test_tool(tools.perl_syntax,
|
||||
[("perl.pl", tools.Status.ok),
|
||||
# ("perl6.pl", tools.Status.problem)
|
||||
])
|
||||
])
|
||||
|
||||
def test_perldoc(self):
|
||||
# FIX: This is failing in an Appimage, inside a nspawn container,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue