Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert config dependencies #42

Open
girotobial opened this issue Jun 5, 2022 · 0 comments
Open

Invert config dependencies #42

girotobial opened this issue Jun 5, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@girotobial
Copy link

girotobial commented Jun 5, 2022

Add present, every module imports the config module. In turn the config module imports other modules, and then, runs code that imports the config file and changes local variables in the modules it imported. This makes testing more difficult as now most modules are dependant on the configuration file being loaded and tested correctly.

I propose that config should be held in a Config class which has sensible defaults and validates read values. With functions in the config module for reading and writing to file.

Something like

@dataclass
class Config:
    verbosity: int = 1
    cleaning_level: int = 1
    skip_downlodas: bool = False


def read_config(file_path: Optional[Union[Path, str]] = DEFAULT_CONFIG_FILEPATH) -> Config:
    ...

def write_config(config: Config, file_path: Union[Path, str]) -> None:
    ...

The Config class can then be imported and used in tests, but read from file and loaded at run time.

@girotobial girotobial added the bug Something isn't working label Jun 5, 2022
@girotobial girotobial self-assigned this Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant