1010from twyn .base .constants import (
1111 DEFAULT_PROJECT_TOML_FILE ,
1212 DEFAULT_SELECTOR_METHOD ,
13+ DEFAULT_TOP_PYPI_PACKAGES ,
1314 AvailableLoggingLevels ,
1415)
1516from twyn .core .exceptions import (
@@ -29,6 +30,7 @@ class TwynConfiguration:
2930 selector_method : str
3031 logging_level : AvailableLoggingLevels
3132 allowlist : set [str ]
33+ pypi_reference : str
3234
3335
3436@dataclass (frozen = True )
@@ -39,6 +41,7 @@ class ReadTwynConfiguration:
3941 selector_method : Optional [str ]
4042 logging_level : Optional [AvailableLoggingLevels ]
4143 allowlist : set [str ]
44+ pypi_reference : Optional [str ]
4245
4346
4447class ConfigHandler :
@@ -71,6 +74,7 @@ def resolve_config(
7174 selector_method = selector_method or twyn_config_data .get ("selector_method" , DEFAULT_SELECTOR_METHOD ),
7275 logging_level = _get_logging_level (verbosity , twyn_config_data .get ("logging_level" )),
7376 allowlist = set (twyn_config_data .get ("allowlist" , set ())),
77+ pypi_reference = twyn_config_data .get ("pypi_reference" , DEFAULT_TOP_PYPI_PACKAGES ),
7478 )
7579
7680 def add_package_to_allowlist (self , package_name : str ) -> None :
@@ -85,6 +89,7 @@ def add_package_to_allowlist(self, package_name: str) -> None:
8589 selector_method = config .selector_method ,
8690 logging_level = config .logging_level ,
8791 allowlist = config .allowlist | {package_name },
92+ pypi_reference = config .pypi_reference ,
8893 )
8994 self ._write_config (toml , new_config )
9095 logger .info (f"Package '{ package_name } ' successfully added to allowlist" )
@@ -101,6 +106,7 @@ def remove_package_from_allowlist(self, package_name: str) -> None:
101106 selector_method = config .selector_method ,
102107 logging_level = config .logging_level ,
103108 allowlist = config .allowlist - {package_name },
109+ pypi_reference = config .pypi_reference ,
104110 )
105111 self ._write_config (toml , new_config )
106112 logger .info (f"Package '{ package_name } ' successfully removed from allowlist" )
@@ -113,6 +119,7 @@ def _get_read_config(self, toml: TOMLDocument) -> ReadTwynConfiguration:
113119 selector_method = twyn_config_data .get ("selector_method" ),
114120 logging_level = twyn_config_data .get ("logging_level" ),
115121 allowlist = set (twyn_config_data .get ("allowlist" , set ())),
122+ pypi_reference = twyn_config_data .get ("pypi_reference" ),
116123 )
117124
118125 def _write_config (self , toml : TOMLDocument , config : ReadTwynConfiguration ) -> None :
0 commit comments