gabykim commited on
Commit
c20abe2
·
1 Parent(s): 71fa0c7

minor refactor

Browse files
src/know_lang_bot/config.py CHANGED
@@ -40,10 +40,6 @@ class LanguageConfig(BaseSettings):
40
  description="Maximum file size to process in bytes"
41
  )
42
 
43
- def supports_extension(self, ext: str) -> bool:
44
- """Check if the language supports a given file extension"""
45
- return ext in self.file_extensions
46
-
47
  class ParserConfig(BaseSettings):
48
  languages: Dict[str, LanguageConfig] = Field(
49
  default={
 
40
  description="Maximum file size to process in bytes"
41
  )
42
 
 
 
 
 
43
  class ParserConfig(BaseSettings):
44
  languages: Dict[str, LanguageConfig] = Field(
45
  default={
src/know_lang_bot/parser/base/parser.py CHANGED
@@ -23,4 +23,9 @@ class LanguageParser(ABC):
23
  @abstractmethod
24
  def parse_file(self, file_path: Path) -> List[CodeChunk]:
25
  """Parse a single file and return code chunks"""
 
 
 
 
 
26
  pass
 
23
  @abstractmethod
24
  def parse_file(self, file_path: Path) -> List[CodeChunk]:
25
  """Parse a single file and return code chunks"""
26
+ pass
27
+
28
+ @abstractmethod
29
+ def supports_extension(self, ext: str) -> bool:
30
+ """Check if this parser supports a given file extension"""
31
  pass
src/know_lang_bot/parser/factory.py CHANGED
@@ -30,7 +30,7 @@ class CodeParserFactory():
30
  continue
31
 
32
  parser = parser_class(self.config)
33
- if extension in parser.supported_extensions():
34
  if lang not in self._parsers:
35
  parser.setup()
36
  self._parsers[lang] = parser
 
30
  continue
31
 
32
  parser = parser_class(self.config)
33
+ if parser.supports_extension(extension):
34
  if lang not in self._parsers:
35
  parser.setup()
36
  self._parsers[lang] = parser
src/know_lang_bot/parser/languages/python/parser.py CHANGED
@@ -105,7 +105,8 @@ class PythonParser(LanguageParser):
105
 
106
  def parse_file(self, file_path: Path) -> List[CodeChunk]:
107
  """Parse a single Python file and return list of code chunks"""
108
- if not self.language_config.supports_extension(file_path.suffix):
 
109
  return []
110
 
111
  # Check file size limit
@@ -143,4 +144,8 @@ class PythonParser(LanguageParser):
143
 
144
  except Exception as e:
145
  LOG.error(f"Error parsing file {file_path}: {str(e)}")
146
- return []
 
 
 
 
 
105
 
106
  def parse_file(self, file_path: Path) -> List[CodeChunk]:
107
  """Parse a single Python file and return list of code chunks"""
108
+ if not self.supports_extension(file_path.suffix):
109
+ LOG.debug(f"Skipping file {file_path}: unsupported extension")
110
  return []
111
 
112
  # Check file size limit
 
144
 
145
  except Exception as e:
146
  LOG.error(f"Error parsing file {file_path}: {str(e)}")
147
+ return []
148
+
149
+ def supports_extension(self, ext: str) -> bool:
150
+ """Check if this parser supports a given file extension"""
151
+ return ext in self.language_config.file_extensions