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 asyncio
|
||||||
import collections
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
import gzip
|
import gzip
|
||||||
|
|
@ -317,9 +316,9 @@ class Summary:
|
||||||
if sum(stats) != 0:
|
if sum(stats) != 0:
|
||||||
log_filesystem_changed(log, *stats)
|
log_filesystem_changed(log, *stats)
|
||||||
with self.keep_selection():
|
with self.keep_selection():
|
||||||
self._column, self._cache, self.result_total, self.completed_total, \
|
(self._column, self._cache, self.result_total,
|
||||||
self._max_width, self._max_path_length, \
|
self.completed_total, self._max_width, self._max_path_length,
|
||||||
self.closest_placeholder_generator, self._all_results = (
|
self.closest_placeholder_generator, self._all_results) = (
|
||||||
new_column, new_cache, result_total, completed_total,
|
new_column, new_cache, result_total, completed_total,
|
||||||
max_width, max_path_length, None, all_results)
|
max_width, max_path_length, None, all_results)
|
||||||
if jobs_added:
|
if jobs_added:
|
||||||
|
|
@ -649,6 +648,7 @@ class Screen:
|
||||||
self._is_fullscreen = False
|
self._is_fullscreen = False
|
||||||
self._make_widgets()
|
self._make_widgets()
|
||||||
self._key_map = make_key_map(Screen._KEY_DATA)
|
self._key_map = make_key_map(Screen._KEY_DATA)
|
||||||
|
self._last_mouse_position = 0, 0
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
state = self.__dict__.copy()
|
state = self.__dict__.copy()
|
||||||
|
|
@ -901,10 +901,12 @@ class Screen:
|
||||||
|
|
||||||
def _is_switching_focus(self, x, y, view_width, view_height):
|
def _is_switching_focus(self, x, y, view_width, view_height):
|
||||||
return (not self._is_fullscreen and
|
return (not self._is_fullscreen and
|
||||||
(self._is_listing_portrait and (x > view_width and
|
(self._is_listing_portrait and
|
||||||
|
(x > view_width and
|
||||||
self._is_summary_focused or x <= view_width and
|
self._is_summary_focused or x <= view_width and
|
||||||
not self._is_summary_focused) or
|
not self._is_summary_focused) or
|
||||||
not self._is_listing_portrait and (y > view_height and
|
not self._is_listing_portrait and
|
||||||
|
(y > view_height and
|
||||||
self._is_summary_focused or y <= view_height and
|
self._is_summary_focused or y <= view_height and
|
||||||
not self._is_summary_focused)))
|
not self._is_summary_focused)))
|
||||||
|
|
||||||
|
|
@ -1072,8 +1074,8 @@ def load_state(pickle_path, jobs_added_event, appearance_changed_event,
|
||||||
return summary, screen, log, is_first_run
|
return summary, screen, log, is_first_run
|
||||||
|
|
||||||
|
|
||||||
def main(root_path, loop, worker_count=None, editor_command=None, theme=None, compression=None,
|
def main(root_path, loop, worker_count=None, editor_command=None, theme=None,
|
||||||
is_being_tested=False):
|
compression=None, is_being_tested=False):
|
||||||
if worker_count is None:
|
if worker_count is None:
|
||||||
worker_count = max(multiprocessing.cpu_count() - 1, 1)
|
worker_count = max(multiprocessing.cpu_count() - 1, 1)
|
||||||
if theme is None:
|
if theme is None:
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,6 @@ import eris.termstr as termstr
|
||||||
|
|
||||||
|
|
||||||
def appearance_is_valid(appearance):
|
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
|
return (all(isinstance(line, (str, termstr.TermStr)) and len(line) > 0
|
||||||
for line in appearance) and
|
for line in appearance) and
|
||||||
len(set(len(line) for line in appearance)) < 2)
|
len(set(len(line) for line in appearance)) < 2)
|
||||||
|
|
@ -45,9 +42,6 @@ def appearance_dimensions(appearance):
|
||||||
|
|
||||||
|
|
||||||
def join(seperator, parts):
|
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 == []:
|
if parts == []:
|
||||||
return ""
|
return ""
|
||||||
try:
|
try:
|
||||||
|
|
@ -179,8 +173,8 @@ class Filler:
|
||||||
|
|
||||||
class ScrollBar:
|
class ScrollBar:
|
||||||
|
|
||||||
_PARTIAL_CHARS = (["█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"]
|
_PARTIAL_CHARS = (["█", "▇", "▆", "▅", "▄", "▃", "▂", "▁"],
|
||||||
,[" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"])
|
[" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"])
|
||||||
DEFAULT_BAR_COLOR = termstr.Color.grey_100
|
DEFAULT_BAR_COLOR = termstr.Color.grey_100
|
||||||
DEFAULT_BACKGROUND_COLOR = termstr.Color.grey_30
|
DEFAULT_BACKGROUND_COLOR = termstr.Color.grey_30
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
This can be useful when initially reading a codebase.
|
This can be useful when initially reading a codebase.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ def get_color_codes(environment):
|
||||||
if "LS_COLORS" in environment:
|
if "LS_COLORS" in environment:
|
||||||
try:
|
try:
|
||||||
return _parse_ls_colors(environment["LS_COLORS"])
|
return _parse_ls_colors(environment["LS_COLORS"])
|
||||||
except:
|
except Exception:
|
||||||
syslog.syslog("Syntax error in LS_COLORS environment variable. "
|
syslog.syslog("Syntax error in LS_COLORS environment variable. "
|
||||||
"Using default colors.")
|
"Using default colors.")
|
||||||
return _DEFAULT_COLOR_CODES
|
return _DEFAULT_COLOR_CODES
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class PagedList:
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return self._len
|
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))
|
pickle_path = os.path.join(self.pages_dir, str(index))
|
||||||
with self.open_func(pickle_path, "rb") as file_:
|
with self.open_func(pickle_path, "rb") as file_:
|
||||||
return pickle.load(file_)
|
return pickle.load(file_)
|
||||||
|
|
@ -63,7 +63,8 @@ class PagedList:
|
||||||
return self._get_page(page_index)[page_offset]
|
return self._get_page(page_index)[page_offset]
|
||||||
|
|
||||||
def _setup_page_cache(self):
|
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.
|
def __getstate__(self): # Don't pickle the lru_cache.
|
||||||
state = self.__dict__.copy()
|
state = self.__dict__.copy()
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
# Licensed under the Artistic License 2.0.
|
# Licensed under the Artistic License 2.0.
|
||||||
|
|
||||||
|
|
||||||
"""Termstr strings contain characters that have color and style."""
|
|
||||||
|
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
import html
|
import html
|
||||||
|
|
@ -24,7 +21,6 @@ xterm_colormap = eris.ColorMap.XTermColorMap()
|
||||||
|
|
||||||
@functools.lru_cache()
|
@functools.lru_cache()
|
||||||
def xterm_color_to_rgb(color_index):
|
def xterm_color_to_rgb(color_index):
|
||||||
"""Return the rgb color of an xterm color."""
|
|
||||||
return eris.ColorMap._rgb(xterm_colormap.colors[color_index])
|
return eris.ColorMap._rgb(xterm_colormap.colors[color_index])
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,7 +35,6 @@ def _cache_first_result(user_function):
|
||||||
|
|
||||||
|
|
||||||
class Color:
|
class Color:
|
||||||
"""A list of common colors."""
|
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/Natural_Color_System
|
# https://en.wikipedia.org/wiki/Natural_Color_System
|
||||||
black = (0, 0, 0)
|
black = (0, 0, 0)
|
||||||
|
|
@ -61,10 +56,6 @@ class Color:
|
||||||
|
|
||||||
|
|
||||||
class CharStyle:
|
class CharStyle:
|
||||||
"""Characters have a foreground and background color, and styles.
|
|
||||||
|
|
||||||
The styles are bold, italic or underlined.
|
|
||||||
"""
|
|
||||||
|
|
||||||
_POOL = weakref.WeakValueDictionary()
|
_POOL = weakref.WeakValueDictionary()
|
||||||
_TERMINAL256_FORMATTER = \
|
_TERMINAL256_FORMATTER = \
|
||||||
|
|
@ -109,7 +100,7 @@ class CharStyle:
|
||||||
return (f"<CharStyle: fg:{self.fg_color} bg:{self.bg_color}"
|
return (f"<CharStyle: fg:{self.fg_color} bg:{self.bg_color}"
|
||||||
f" attr:{','.join(attributes)}>")
|
f" attr:{','.join(attributes)}>")
|
||||||
|
|
||||||
def termcode_of_color(self, color, is_foreground):
|
def _color_code(self, color, is_foreground):
|
||||||
if isinstance(color, int):
|
if isinstance(color, int):
|
||||||
return terminal.color(color, is_foreground)
|
return terminal.color(color, is_foreground)
|
||||||
else: # true color
|
else: # true color
|
||||||
|
|
@ -122,13 +113,15 @@ class CharStyle:
|
||||||
|
|
||||||
@_cache_first_result
|
@_cache_first_result
|
||||||
def code_for_term(self):
|
def code_for_term(self):
|
||||||
fg_termcode = terminal.ESC + self.termcode_of_color(self.fg_color, True)
|
fg_termcode = terminal.ESC + self._color_code(self.fg_color, True)
|
||||||
bg_termcode = terminal.ESC + self.termcode_of_color(self.bg_color, False)
|
bg_termcode = terminal.ESC + self._color_code(self.bg_color, False)
|
||||||
bold_code = (terminal.ESC + terminal.bold) if self.is_bold else ""
|
bold_code = (terminal.ESC + terminal.bold) if self.is_bold else ""
|
||||||
italic_code = (terminal.ESC + terminal.italic) if self.is_italic else ""
|
italic_code = ((terminal.ESC + terminal.italic)
|
||||||
underline_code = (terminal.ESC + terminal.underline) if self.is_underlined else ""
|
if self.is_italic else "")
|
||||||
return "".join([terminal.ESC, terminal.normal, fg_termcode, bg_termcode,
|
underline_code = ((terminal.ESC + terminal.underline)
|
||||||
bold_code, italic_code, underline_code])
|
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):
|
def as_html(self):
|
||||||
bold_code = "font-weight:bold; " if self.is_bold else ""
|
bold_code = "font-weight:bold; " if self.is_bold else ""
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import enum
|
import enum
|
||||||
import functools
|
import functools
|
||||||
import gzip
|
|
||||||
import importlib
|
import importlib
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
import math
|
import math
|
||||||
|
|
@ -325,7 +324,8 @@ def python_coverage(path):
|
||||||
return Status.not_applicable, f'No "{coverage_path}" file.'
|
return Status.not_applicable, f'No "{coverage_path}" file.'
|
||||||
if os.stat(path).st_mtime > os.stat(coverage_path).st_mtime:
|
if os.stat(path).st_mtime > os.stat(coverage_path).st_mtime:
|
||||||
return (Status.not_applicable,
|
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)
|
path = os.path.normpath(path)
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
_do_command([PYTHON_EXECUTABLE, "-m", "coverage",
|
_do_command([PYTHON_EXECUTABLE, "-m", "coverage",
|
||||||
|
|
@ -473,6 +473,7 @@ def make_tool_function(dependencies, command, url=None, success_status=None,
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
elinks, git_blame, git_log = None, None, None # For linters.
|
||||||
with importlib.resources.open_text(eris, "tools.toml") as tools_toml_file:
|
with importlib.resources.open_text(eris, "tools.toml") as tools_toml_file:
|
||||||
tools_toml = toml.load(tools_toml_file)
|
tools_toml = toml.load(tools_toml_file)
|
||||||
tools_for_extensions = tools_toml["tools_for_extensions"]
|
tools_for_extensions = tools_toml["tools_for_extensions"]
|
||||||
|
|
@ -556,8 +557,8 @@ class Result:
|
||||||
if self.status == Status.pending or self.compression is None:
|
if self.status == Status.pending or self.compression is None:
|
||||||
return unknown_label
|
return unknown_label
|
||||||
try:
|
try:
|
||||||
with compression_open_func(self.compression)(self.pickle_path, "rb") \
|
with compression_open_func(self.compression)(
|
||||||
as pickle_file:
|
self.pickle_path, "rb") as pickle_file:
|
||||||
return pickle.load(pickle_file)
|
return pickle.load(pickle_file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return unknown_label
|
return unknown_label
|
||||||
|
|
@ -614,7 +615,8 @@ class Result:
|
||||||
Result.result.fget.evict(self)
|
Result.result.fget.evict(self)
|
||||||
|
|
||||||
def as_html(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__}" '
|
return (f'<a title="{self.tool.__name__}" '
|
||||||
f'href="{self.path}/{self.tool.__name__}">{html}</a>', styles)
|
f'href="{self.path}/{self.tool.__name__}">{html}</a>', styles)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ tools_for_extensions = [
|
||||||
[pydocstyle]
|
[pydocstyle]
|
||||||
dependencies = ["pip/pydocstyle"]
|
dependencies = ["pip/pydocstyle"]
|
||||||
url = "http://www.pydocstyle.org/en/2.1.1/usage.html"
|
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]
|
[pyflakes]
|
||||||
dependencies = ["pip/pyflakes"]
|
dependencies = ["pip/pyflakes"]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
import eris.fill3 as fill3
|
import eris.fill3 as fill3
|
||||||
|
|
@ -37,7 +36,8 @@ class Worker:
|
||||||
os.setpriority(os.PRIO_PGRP, self.child_pgid, 19)
|
os.setpriority(os.PRIO_PGRP, self.child_pgid, 19)
|
||||||
|
|
||||||
async def run_tool(self, path, tool):
|
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()
|
data = await self.process.stdout.readline()
|
||||||
return tools.Status(int(data))
|
return tools.Status(int(data))
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ def main():
|
||||||
status, text = tools.run_tool_no_error(path, tool)
|
status, text = tools.run_tool_no_error(path, tool)
|
||||||
result.result = make_result_widget(text, result, compression)
|
result.result = make_result_widget(text, result, compression)
|
||||||
print(status.value, flush=True)
|
print(status.value, flush=True)
|
||||||
except:
|
except Exception:
|
||||||
tools.log_error()
|
tools.log_error()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ then to run:
|
||||||
Extensions({len(extension_set)-1}) | Tools({len(tool_set)})
|
Extensions({len(extension_set)-1}) | Tools({len(tool_set)})
|
||||||
----------:| -----""")
|
----------:| -----""")
|
||||||
for extensions, tools_ in all_tools:
|
for extensions, tools_ in all_tools:
|
||||||
print("%s | %s" % (" ".join("." + extension for extension in extensions),
|
print("%s | %s" % (
|
||||||
|
" ".join("." + extension for extension in extensions),
|
||||||
" • ".join(tool_markup(tool) for tool in tools_)))
|
" • ".join(tool_markup(tool) for tool in tools_)))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ def umount_squashfs_iso(mount_point):
|
||||||
|
|
||||||
def run_in_container(container, command):
|
def run_in_container(container, command):
|
||||||
option = "--directory" if os.path.isdir(container) else "--image"
|
option = "--directory" if os.path.isdir(container) else "--image"
|
||||||
cmd(f"sudo systemd-nspawn --quiet --chdir=/eris --overlay={ERIS_PATH}:/eris "
|
cmd(f"sudo systemd-nspawn --quiet --chdir=/eris --overlay={ERIS_PATH}:"
|
||||||
f'{option}={container} /bin/bash --login -c "{command}"')
|
f'/eris {option}={container} /bin/bash --login -c "{command}"')
|
||||||
|
|
||||||
|
|
||||||
def build_ubuntu():
|
def build_ubuntu():
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ class ScreenWidgetTestCase(unittest.TestCase):
|
||||||
appearance_changed_event = asyncio.Event()
|
appearance_changed_event = asyncio.Event()
|
||||||
summary = __main__.Summary(self.temp_dir, jobs_added_event)
|
summary = __main__.Summary(self.temp_dir, jobs_added_event)
|
||||||
log = __main__.Log(appearance_changed_event)
|
log = __main__.Log(appearance_changed_event)
|
||||||
self.main_widget = __main__.Screen(summary, log, appearance_changed_event,
|
self.main_widget = __main__.Screen(
|
||||||
_MockMainLoop())
|
summary, log, appearance_changed_event, _MockMainLoop())
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
|
|
@ -173,7 +173,7 @@ class SummarySyncWithFilesystem(unittest.TestCase):
|
||||||
# self.assertFalse(self.jobs_added_event.is_set())
|
# self.assertFalse(self.jobs_added_event.is_set())
|
||||||
|
|
||||||
def test_sync_linked_files(self):
|
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")
|
baz_path = os.path.join(self.temp_dir, "baz")
|
||||||
os.symlink(self.foo_path, baz_path)
|
os.symlink(self.foo_path, baz_path)
|
||||||
os.link(self.foo_path, self.zoo_path)
|
os.link(self.foo_path, self.zoo_path)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import eris.fill3 as fill3
|
import eris.fill3 as fill3
|
||||||
import eris.termstr as termstr
|
|
||||||
|
|
||||||
|
|
||||||
class WidgetTests(unittest.TestCase):
|
class WidgetTests(unittest.TestCase):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue