{"id":32558302,"url":"https://github.com/grv96/syspathmodif","last_synced_at":"2026-01-20T16:59:07.349Z","repository":{"id":257789698,"uuid":"860186447","full_name":"GRV96/syspathmodif","owner":"GRV96","description":"This library offers concise manners to modify list sys.path. The user should not need to directly interact with that list.","archived":false,"fork":false,"pushed_at":"2025-09-25T00:59:14.000Z","size":81,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-25T02:46:49.497Z","etag":null,"topics":["import","path","pypi","pypi-package","pypi-packages","python","python-package","python-packages"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/syspathmodif/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GRV96.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-20T01:32:06.000Z","updated_at":"2025-09-25T00:59:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"7547020d-8802-4480-93ba-da12242fdc60","html_url":"https://github.com/GRV96/syspathmodif","commit_stats":null,"previous_names":["grv96/syspathmodif"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/GRV96/syspathmodif","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GRV96%2Fsyspathmodif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GRV96%2Fsyspathmodif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GRV96%2Fsyspathmodif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GRV96%2Fsyspathmodif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GRV96","download_url":"https://codeload.github.com/GRV96/syspathmodif/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GRV96%2Fsyspathmodif/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281533444,"owners_count":26517827,"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","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["import","path","pypi","pypi-package","pypi-packages","python","python-package","python-packages"],"created_at":"2025-10-28T23:54:11.739Z","updated_at":"2025-10-28T23:55:06.838Z","avatar_url":"https://github.com/GRV96.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# syspathmodif\n\n## FRANÇAIS\n\nCette bibliothèque offre des manières concises de modifier la liste `sys.path`.\nL'utilisateur ne devrait pas avoir besoin d'interagir directement avec cette\nliste.\n\n### Contenu\n\nLes fonctions suivantes prennent un chemin de type `str` ou `pathlib.Path`\ncomme argument. Elles convertissent les arguments de type `pathlib.Path` en\n`str` puisque `sys.path` n'est censée contenir que des chaînes de caractères.\n\n* `sp_append` ajoute le chemin donné à la fin de `sys.path`.\n* `sp_contains` indique si `sys.path` contient le chemin donné.\n* `sp_prepend` ajoute le chemin donné au début de `sys.path`.\n* `sp_remove` enlève le chemin donné de `sys.path`.\n\nAu moment de sa création, une instance de `SysPathBundle` contient plusieurs\nchemins et les ajoute au début de `sys.path`. Quand on vide (*clear*) une\ninstance, elle efface son contenu et l'enlève de `sys.path`. Ainsi, cette\nclasse facilite l'ajout et le retrait d'un groupe de chemins.\n\nIl est possible d'utiliser `SysPathBundle` comme un gestionnaire de contexte\n(*context manager*). Dans ce cas, l'instance est vidée à la fin du bloc `with`.\n\nLa fonction `sm_contains` prend comme argument un nom (`str`) de module. Elle\nindique si le dictionnaire `sys.modules` contient ce module.\n\nLes fonctions suivantes permettent d'ajouter au début de `sys.path` le chemin\nde dossiers parents du fichier qui les appelle. Des indices passés en argument\nidentifient les parents. Soit une instance `p` de `pathlib.Path` représentant\nle chemin du fichier appelant. Le dossier parent identifié par l'indice `i`\npassé à ces fonctions correspond au chemin renvoyé par `p.parents[i]`.\n\n* `sp_prepend_parent` ajoute un chemin parent à `sys.path`.\n* `sp_prepend_parent_bundle` passe un ou plusieurs chemins parents à une\ninstance de `SysPathBundle` puis renvoie cette dernière.\n\nPour plus d'informations, consultez la documentation et les démos dans le dépôt\nde code source.\n\n### Importations et `sys.path`\n\nIl est possible d'importer un module si la liste `sys.path` contient le chemin\nde son dossier parent. On peut donc rendre un module importable en ajoutant son\nchemin parent à `sys.path`.\n\n### Importations et `sys.modules`\n\nLe dictionnaire `sys.modules` associe des noms (`str`) de module au module\ncorrespondant. Le système d'importation l'utilise comme cache; tout module\nimporté pour la première fois y est conservé. Puisque le système d'importation\ncherche d'abord les modules demandés dans `sys.modules`, les modules qu'il\ncontient peuvent être importés partout sans qu'on modifie `sys.path`.\n\nSachant cela, on peut déterminer à l'aide de la fonction `sm_contains` si un\nmodule est déjà importable. Si `sm_contains` renvoie vrai (`True`), il n'est\npas nécessaire de modifier `sys.path` pour importer le module donné.\n\n### Dépendances\n\nInstallez les dépendances de `syspathmodif` avant de l'utiliser.\n```\npip install -r requirements.txt\n```\n\nCette commande installe les dépendances de développement en plus des\ndépendances ordinaires.\n```\npip install -r requirements-dev.txt\n```\n\n### Démos\n\nLes scripts dans le dossier `demos` montrent comment `syspathmodif` permet\nd'importer un module qui est indisponible tant qu'on n'a pas ajouté son chemin\nparent à `sys.path`. Toutes les démos dépendent du paquet `demo_package`.\n\n`demo1_individual_paths.py` ajoute la racine du dépôt à `sys.path` à l'aide de\nla fonction `sp_prepend`. Après les importations, la démo annule cette\nmodification à l'aide de la fonction `sp_remove`.\n```\npython demos/demo1_individual_paths.py\n```\n\n`demo2_bundle.py` ajoute la racine du dépôt et le dossier `demo_package` à\n`sys.path` à l'aide de la classe `SysPathBundle`. Après les importations, la\ndémo annule ces modifications en vidant l'instance de `SysPathBundle`.\n```\npython demos/demo2_bundle.py\n```\n\n`demo3_bundle_context.py` effectue la même tâche que `demo2_bundle.py` en\nutilisant `SysPathBundle` comme gestionnaire de contexte.\n```\npython demos/demo3_bundle_context.py\n```\n\n`demo4_sm_containsA.py` montre un cas où on peut importer un module sans ajouter\nson chemin parent à `sys.path`. La démo vérifie la présence du module dans\n`sys.modules` à l'aide de la fonction `sm_contains`.\n```\npython demos/demo4_sm_containsA.py\n```\n\n`demo5_sm_containsB.py` montre un autre usage de la fonction `sm_contains`.\n```\npython demos/demo5_sm_containsB.py\n```\n\n`demo6_parent.py` ajoute la racine du dépôt à `sys.path` à l'aide de la\nfonction `sp_prepend_parent`. Après les importations, la démo annule cette\nmodification à l'aide de la fonction `sp_remove`.\n```\npython demos/demo6_parent.py\n```\n\n`demo7_parent_bundle.py` met le chemin de la racine du dépôt dans une instance\nde `SysPathBundle` à l'aide de la fonction `sp_prepend_parent_bundle`.\nL'instance sert de gestionnaire de contexte.\n```\npython demos/demo7_parent_bundle.py\n```\n\n### Tests automatiques\n\nCette commande exécute les tests automatiques.\n```\npytest tests\n```\n\n## ENGLISH\n\nThis library offers concise manners to modify list `sys.path`.\nThe user should not need to directly interact with that list.\n\n### Content\n\nThe following functions take a path of type `str` or `pathlib.Path` as an\nargument. They convert arguments of type `pathlib.Path` to `str` since\n`sys.path` is supposed to contain only character strings.\n\n* `sp_append` adds the given path to the end of `sys.path`.\n* `sp_contains` indicates whether `sys.path` contains the given path.\n* `sp_prepend` adds the given path to the beginning of `sys.path`.\n* `sp_remove` removes the given path from `sys.path`.\n\nUpon creation, a `SysPathBundle` instance stores several paths and prepends\nthem to `sys.path`. When a bundle is cleared, it erases its content and removes\nit from `sys.path`. Thus, this class facilitates adding and removing a group of\npaths.\n\n`SysPathBundle` can be used as a context manager. In that case, the instance is\ncleared at the `with` block's end.\n\nFunction `sm_contains` takes a module's name (`str`) as an argument. It\nindicates whether dictionary `sys.modules` contains the module.\n\nThe following functions allow to prepend to `sys.path` the paths to parent\ndirectories of the file that calls them. Indices passed as arguments identify\nthe parents. Let be a `pathlib.Path` instance `p` representing the path to the\ncalling file. The parent directory identified by index `i` passed to these\nfunctions matches the path returned by `p.parents[i]`.\n\n* `sp_prepend_parent` prepends one parent path to `sys.path`.\n* `sp_prepend_parent_bundle` passes one or many parent paths to a\n`SysPathBundle` then returns the bundle.\n\nFor more information, consult the documentation and the demos in the source\ncode repository.\n\n### Imports and `sys.path`\n\nIt is possible to import a module if list `sys.path` contains the path to its\nparent directory. Therefore, you can make a module importable by adding its\nparent path to `sys.path`.\n\n### Imports and `sys.modules`\n\nDictionary `sys.modules` maps module names (`str`) to the corresponding module.\nThe import system uses it as a cache; any module imported for the first time is\nstored in it. Since the import system looks for the requested modules in\n`sys.modules` first, the modules that it contains can be imported everywhere\nwith no modifications to `sys.path`.\n\nKnowing this, you can use function `sm_contains` to determine if a module is\nalready importable. If `sm_contains` returns `True`, modifiying `sys.path` is\nnot required to import the given module.\n\n### Dependencies\n\nInstall the dependencies before using `syspathmodif`.\n```\npip install -r requirements.txt\n```\n\nThis command installs the development dependencies in addition to the ordinary\ndependencies.\n```\npip install -r requirements-dev.txt\n```\n\n### Demos\n\nThe scripts in directory `demos` show how `syspathmodif` allows to import a\nmodule unavailable unless its parent path is added to `sys.path`. All demos\ndepend on `demo_package`.\n\n`demo1_individual_paths.py` adds the repository's root to `sys.path` with\nfunction `sp_prepend`. After the imports, the demo undoes this modification\nwith function `sp_remove`.\n```\npython demos/demo1_individual_paths.py\n```\n\n`demo2_bundle.py` adds the repository's root and `demo_package` to `sys.path`\nwith class `SysPathBundle`. After the imports, the demo undoes these\nmodifications by clearing the `SysPathBundle` instance.\n```\npython demos/demo2_bundle.py\n```\n\n`demo3_bundle_context.py` performs the same task as `demo2_bundle.py` by using\n`SysPathBundle` as a context manager.\n```\npython demos/demo3_bundle_context.py\n```\n\n`demo4_sm_containsA.py` shows a case where a module can be imported without its\nparent path being added to `sys.path`. The demo verifies the module's presence\nin `sys.modules` with function `sm_contains`.\n```\npython demos/demo4_sm_containsA.py\n```\n\n`demo5_sm_containsB.py` shows another use of function `sm_contains`.\n```\npython demos/demo5_sm_containsB.py\n```\n\n`demo6_parent.py` adds the repository's root to `sys.path` with function\n`sp_prepend_parent`. After the imports, the demo undoes this modification with\nfunction `sp_remove`.\n```\npython demos/demo6_parent.py\n```\n\n`demo7_parent_bundle.py` puts the path to the repository's root in a\n`SysPathBundle` instance with function `sp_prepend_parent_bundle`. The bundle\nis used as a context manager.\n```\npython demos/demo7_parent_bundle.py\n```\n\n### Automated Tests\n\nThis command executes the automated tests.\n```\npytest tests\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrv96%2Fsyspathmodif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrv96%2Fsyspathmodif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrv96%2Fsyspathmodif/lists"}