{"id":16131505,"url":"https://github.com/thislight/pydyimport","last_synced_at":"2025-04-06T14:32:58.931Z","repository":{"id":62580055,"uuid":"289695621","full_name":"thislight/pydyimport","owner":"thislight","description":"Dynamically import python file to aviod mess when you are using a different directory structure from python suggested.","archived":false,"fork":false,"pushed_at":"2020-08-25T10:23:16.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T20:37:58.825Z","etag":null,"topics":["aviod-mess","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pydyimport/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thislight.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-23T13:50:56.000Z","updated_at":"2020-08-25T10:26:24.000Z","dependencies_parsed_at":"2022-11-03T21:02:45.174Z","dependency_job_id":null,"html_url":"https://github.com/thislight/pydyimport","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thislight%2Fpydyimport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thislight%2Fpydyimport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thislight%2Fpydyimport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thislight%2Fpydyimport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thislight","download_url":"https://codeload.github.com/thislight/pydyimport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247496117,"owners_count":20948163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["aviod-mess","python"],"created_at":"2024-10-09T22:25:25.581Z","updated_at":"2025-04-06T14:32:58.914Z","avatar_url":"https://github.com/thislight.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyDyImport\nDynamically import python file to aviod mess when you are using a different directory structure from python suggested.\n\n## Usage\nJust construct a `DynamicImport` instance and call `DynamicImport.require` \n````python\nfrom pydyimport import DynamicImport\nrequire = DynamicImport(__file__).require\n\nmod = require(\"path/to/file.py\")\n````\n\nIf you only need some of fields in the module, use `DynamicImport.require_only`, which *always* return a tuple.\n````python\nfrom pydyimport import DynamicImport\nrequire_only = DynamicImport(__file__).require_only\n\nfoo, = require_only(\"path/to/file.py\", 'foo') # still return tuple even if only one field described\nSpam1, Spam2 = require_only(\"path/to/file.py\", 'Spam1', 'Spam2')\n````\n\nYou can inject environment variables to the modules you will import by the use of `env_injector` option of `DynamicImport`.\n````python\nfrom pydyimport import DynamicImport\n\ndef meaningless_env_injector(path: str, code: bytes):\n    return {\n        '__meaning__': 'no',\n    }\n\nimporter = DynamicImport(__file__, env_injector=meaningless_env_injector)\nimporter.require(\"path/to/file.py\")\n````\n\nYou can inject require* functions by `RequireEnvInjector`,\n````python\nfrom pydyimport import DynamicImport\nfrom pydyimport.injector import RequireEnvInjector\nrequire = DynamicImport(__file__, env_injector=RequireEnvInjector(next_injector=None))\n\nrequire('path/to/module.py')\n````\nor just set `inject_require` `True`.\n````python\nfrom pydyimport import DynamicImport\nrequire = DynamicImport(__file__, inject_require=True)\n\nrequire('path/to/module.py')\n````\nIf your source contains `# inject_require`, the require* functions will automatically inject require* functions to the module.\n````python\n#!/usr/bin/env python\n# inject_require\n\nrequire('path/to/module.py')\nSpam1, foo = require_only('path/to/module2.py', 'Spam1', 'foo')\n````\n\n\n## License\nGNU GENERAL PUBLIC LICENSE, version 3 or later.\n````\n    PyDyImport - dynamically importing and avoid mess in python\n    Copyright (C) 2020 thisLight\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see \u003chttps://www.gnu.org/licenses/\u003e.\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthislight%2Fpydyimport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthislight%2Fpydyimport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthislight%2Fpydyimport/lists"}