{"id":16567928,"url":"https://github.com/drorata/config-example","last_synced_at":"2026-05-10T15:42:44.786Z","repository":{"id":150667495,"uuid":"152474259","full_name":"drorata/config-example","owner":"drorata","description":"experimenting with configs in package","archived":false,"fork":false,"pushed_at":"2018-10-11T16:40:13.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-05T10:41:12.739Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drorata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-10T18:56:51.000Z","updated_at":"2018-10-11T16:40:14.000Z","dependencies_parsed_at":"2023-04-29T12:17:27.101Z","dependency_job_id":null,"html_url":"https://github.com/drorata/config-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drorata/config-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fconfig-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fconfig-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fconfig-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fconfig-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drorata","download_url":"https://codeload.github.com/drorata/config-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorata%2Fconfig-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32862091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"ssl_error","status_checked_at":"2026-05-10T13:40:02.145Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T21:07:48.819Z","updated_at":"2026-05-10T15:42:44.760Z","avatar_url":"https://github.com/drorata.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Passing configuration in a \"package\"\n\n## Objective:\n\nYou want to load a configuration file ([`test.json`](./test.json)) into a run of an application.\nMinimzing the passing of parameters, objects, etc. is desired.\n\n## Solution\n\nDefine a [`Config`](./config.py) class (following the [borg design pattern](http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/)).\nIn the CLI part of your application, instantiate an instance of `Config` and set its `env` attribute as per [`test.json`](./test.json).\nNext, in the actual logic which [`app.py`](./app.py) calls, and is implemented in [`mod.py`](./mod.py), instansitate another instance of `Config`.\nThis second instance will have the same shared state, and in turn will hold the same configuration in it `env` attribute.\n\n## Testing\n\nLet us run some tests, which also give better feeling to how this solution actually works.\nCheck out `test3` and `test4` in [`test_config1.py`](./test_config1.py); the two instances have different IDs but their underlying `__dict__` is the same.\n\n## Open problem and limitations\n\nAn issue arises with `test2` of [`test_config2.py`](./test_config2.py).\nAlthough in this second test case `foo` and `bar` are swapped, the `Config` objects which are instantiated have the same value for `env` as the one defined in `test_config1.py`.\nIt seems like, somehow, the shared state which is created during the run of `test_config1.py`, is not removed / garbage collected /etc., and is still there when running the second test case.\n\nThe problem with the tests, suggests further problems with this solution in case of distributed setting, multi-thread/processes, etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorata%2Fconfig-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrorata%2Fconfig-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorata%2Fconfig-example/lists"}