@@ -25,6 +25,7 @@ def dependency_check(session: Session) -> None:
2525class Dependencies :
2626 def __init__ (self , illegal : Dict [str , List [str ]] | None ):
2727 self ._illegal = illegal or {}
28+
2829 @staticmethod
2930 def parse (pyproject_toml : str ) -> "Dependencies" :
3031 def _source_filter (version ) -> bool :
@@ -34,29 +35,30 @@ def _source_filter(version) -> bool:
3435 for specifier in ILLEGAL_SPECIFIERS
3536 )
3637
37- def _extract_dependencies (section ) -> List [str ]:
38- dependencies = []
39- for name , version in section . items ():
40- if _source_filter ( version ):
41- dependencies . append ( f" { name } = { version } " )
42- return dependencies
38+ def find_illegal (section ) -> List [str ]:
39+ return [
40+ f" { name } = { version } "
41+ for name , version in section . items ()
42+ if _source_filter ( version )
43+ ]
4344 illegal : Dict [str , List [str ]] = {}
4445 toml = tomlkit .loads (pyproject_toml )
4546 poetry = toml .get ("tool" , {}).get ("poetry" , {})
4647 part = poetry .get ("dependencies" , {})
47- dependencies_list = _extract_dependencies (part )
48- if dependencies_list :
49- illegal ["tool.poetry.dependencies" ] = dependencies_list
48+ illegal_group = find_illegal (part )
49+ if illegal_group :
50+ illegal ["tool.poetry.dependencies" ] = illegal_group
5051 part = poetry .get ("dev" , {}).get ("dependencies" , {})
51- dependencies_list = _extract_dependencies (part )
52- if dependencies_list :
53- illegal ["tool.poetry.dev.dependencies" ] = dependencies_list
52+ illegal_group = find_illegal (part )
53+ if illegal_group :
54+ illegal ["tool.poetry.dev.dependencies" ] = illegal_group
5455 part = poetry .get ("group" , {})
5556 for group , content in part .items ():
56- dependencies_list = _extract_dependencies (content .get ("dependencies" , {}))
57- if dependencies_list :
58- illegal [f"tool.poetry.group.{ group } .dependencies" ] = dependencies_list
57+ illegal_group = find_illegal (content .get ("dependencies" , {}))
58+ if illegal_group :
59+ illegal [f"tool.poetry.group.{ group } .dependencies" ] = illegal_group
5960 return Dependencies (illegal )
61+
6062 @property
6163 def illegal (self ) -> Dict [str , List [str ]]:
6264 return self ._illegal
0 commit comments