Skip to content

Commit

Permalink
Handle files being deleted and remove old problem_files file
Browse files Browse the repository at this point in the history
  • Loading branch information
daphtdazz committed Dec 16, 2021
1 parent 6fc5050 commit dbc2fdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
23 changes: 10 additions & 13 deletions lintmon/monitor_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ def dirpath(self):
def problem_lines_filepath(self):
return os.path.join(self.dirpath, 'problem_lines')

@property
def problem_files_filepath(self):
return os.path.join(self.dirpath, 'problem_files')

def __init__(self, config, files):
self.state = self.States.initial
self.config = config
Expand All @@ -54,18 +50,23 @@ def start(self):
self.skip()
return

files = [f for f in self.files if os.path.exists(f)]

if len(files) == 0:
# all files were deleted, so mark as clear
self.problem_lines = {f: [] for f in self.files}
self.state = self.States.complete
return

self.state = self.States.running
log.debug('Starting %s on %d files', self.config.command, len(self.files))
log.debug('Starting %s on %d files', self.config.command, len(files))
self.output_file = TemporaryFile(mode='w+')
try:
self.process = Popen(
[*self.config.command, *self.files],
stdout=self.output_file,
stderr=self.output_file,
[*self.config.command, *files], stdout=self.output_file, stderr=self.output_file,
)
except Exception as exc:
self.problem_lines = {'.': [str(exc).replace('\n', ' ')]}
# self.problem_files = []
self.process = None

def join(self):
Expand Down Expand Up @@ -133,10 +134,6 @@ def save(self):
]

self._write_lines_filepath(self.problem_lines_filepath, expanded_sorted_lines)
self._write_lines_filepath(
self.problem_files_filepath,
sorted([k for k in new_problem_lines_by_file.keys() if k is not None]),
)

def __str__(self):
return self.config.name
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip-string-normalization = true

[tool.poetry]
name = "lintmon"
version = "0.1.0"
version = "0.1.1"
description = "Monitor project files in the background for lint issues and flag issues in your prompt"
authors = ["David Park <david@greenparksoftware.co.uk>"]
license = "Apache-2.0"
Expand Down

0 comments on commit dbc2fdb

Please sign in to comment.