# hatch_modulefile
[![PyPI - Version](https://img.shields.io/pypi/v/hatch-modulefile.svg)](https://pypi.org/project/hatch-modulefile)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/hatch-modulefile.svg)](https://pypi.org/project/hatch-modulefile)
-----
This provides automatic modulefile generation for [EnvironmentModules](https://modules.readthedocs.io/en/latest/). Modulefiles are created with a basic template which:
1. Loads any modules listed in `requires`
2. Sources the activate script of the installed packages (assumes venv installation)
3. Sets extra environment variables defined in extra-paths
**Table of Contents**
- [Installation](#installation)
- [Example](#example)
- [License](#license)
## Installation
```console
pip install hatch-modulefile
```
## Example
Example use case. Note that requires is a list of modulefiles available on your system
through environment modules. Extra paths defines modulefile environment manipulations.
[build.hooks.modulefile]
requires = [
"module1/1.0.0",
"module2/3.1.2",
"module3/2.0.0",
]
extra-paths = [
{ type="setenv", variable="NUMEXPR_MAX_THREADS", value="8" },
{ type="prepend-path", variable="PATH", value="/custom/path" },
]
This would generate a modulefile which looks like this:
```
#%Module
# Gets the folder two folders up from this file
set venv [file dirname [file dirname [file dirname [file normalize $ModulesCurrentModulefile/___]]]]
set site_packages [glob $venv/lib/python*/site-packages]
set necessary {
module1/1.0.0
module2/3.1.2
module3/2.0.0
}
foreach mod $necessary {
set splitList [split $mod "/"]
set mod_name [lindex $splitList 0]
if { [ is-loaded $mod_name ] } {
module switch $mod
} else {
module load $mod
}
}
if { [module-info mode load] || [module-info mode switch2] } {
puts stdout "source $venv/bin/activate;"
} elseif { [module-info mode remove] && ![module-info mode switch3] } {
puts stdout "deactivate;"
}
# Extra module path requirements
setenv NUMEXPR_MAX_THREADS 8
prepend-path PATH /custom/path
```
## License
`hatch-modulefile` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "hatch-modulefile",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "build,hatch,modulefiles,plugin,pth",
"author": null,
"author_email": "Reuben Vandezande <reuben.vandezande@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/b3/12/693f56dbce18bc8bc4cc48aa70b15d7ac782160f562f8d6c6971e1bb8a21/hatch_modulefile-0.1.1.tar.gz",
"platform": null,
"description": "# hatch_modulefile\n\n[![PyPI - Version](https://img.shields.io/pypi/v/hatch-modulefile.svg)](https://pypi.org/project/hatch-modulefile)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/hatch-modulefile.svg)](https://pypi.org/project/hatch-modulefile)\n\n-----\n\nThis provides automatic modulefile generation for [EnvironmentModules](https://modules.readthedocs.io/en/latest/). Modulefiles are created with a basic template which:\n\n1. Loads any modules listed in `requires`\n2. Sources the activate script of the installed packages (assumes venv installation)\n3. Sets extra environment variables defined in extra-paths\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Example](#example)\n- [License](#license)\n\n## Installation\n\n```console\npip install hatch-modulefile\n```\n\n## Example\n\nExample use case. Note that requires is a list of modulefiles available on your system \nthrough environment modules. Extra paths defines modulefile environment manipulations.\n\n[build.hooks.modulefile]\nrequires = [\n \"module1/1.0.0\",\n \"module2/3.1.2\",\n \"module3/2.0.0\",\n]\nextra-paths = [\n { type=\"setenv\", variable=\"NUMEXPR_MAX_THREADS\", value=\"8\" },\n { type=\"prepend-path\", variable=\"PATH\", value=\"/custom/path\" },\n]\n\nThis would generate a modulefile which looks like this:\n\n```\n#%Module\n\n# Gets the folder two folders up from this file\nset venv [file dirname [file dirname [file dirname [file normalize $ModulesCurrentModulefile/___]]]]\nset site_packages [glob $venv/lib/python*/site-packages]\n\nset necessary {\n module1/1.0.0\n module2/3.1.2\n module3/2.0.0\n}\n\nforeach mod $necessary {\n set splitList [split $mod \"/\"]\n set mod_name [lindex $splitList 0]\n if { [ is-loaded $mod_name ] } {\n module switch $mod\n } else {\n module load $mod\n }\n}\n\nif { [module-info mode load] || [module-info mode switch2] } {\n puts stdout \"source $venv/bin/activate;\"\n} elseif { [module-info mode remove] && ![module-info mode switch3] } {\n puts stdout \"deactivate;\"\n}\n\n# Extra module path requirements\nsetenv NUMEXPR_MAX_THREADS 8\nprepend-path PATH /custom/path\n```\n\n## License\n\n`hatch-modulefile` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
"bugtrack_url": null,
"license": null,
"summary": "Hatch plugin for use in Modulefiles environments",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/rvandezande/hatch-modulefile#readme",
"Issues": "https://github.com/rvandezande/hatch-modulefile/issues",
"Source": "https://github.com/rvandezande/hatch-modulefile"
},
"split_keywords": [
"build",
"hatch",
"modulefiles",
"plugin",
"pth"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "353992f6455937c5cde62a6554f6e2eec2c3a4f3359e899983122b70dba6ce1d",
"md5": "fb7447fb1fab82f6a106f0f5fdaf321c",
"sha256": "fda066ff9731a45842ebb90a5695c4db8fd2d90420f2b106450360b9ef01b5ee"
},
"downloads": -1,
"filename": "hatch_modulefile-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fb7447fb1fab82f6a106f0f5fdaf321c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 6416,
"upload_time": "2024-01-05T18:37:44",
"upload_time_iso_8601": "2024-01-05T18:37:44.220936Z",
"url": "https://files.pythonhosted.org/packages/35/39/92f6455937c5cde62a6554f6e2eec2c3a4f3359e899983122b70dba6ce1d/hatch_modulefile-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "b312693f56dbce18bc8bc4cc48aa70b15d7ac782160f562f8d6c6971e1bb8a21",
"md5": "cc34712f6cd281bd56bc972657d53667",
"sha256": "731db25f1e650eafbf297473d7299732c334b2735a45906d01e5c85ff5dedc6f"
},
"downloads": -1,
"filename": "hatch_modulefile-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "cc34712f6cd281bd56bc972657d53667",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8152,
"upload_time": "2024-01-05T18:37:45",
"upload_time_iso_8601": "2024-01-05T18:37:45.787651Z",
"url": "https://files.pythonhosted.org/packages/b3/12/693f56dbce18bc8bc4cc48aa70b15d7ac782160f562f8d6c6971e1bb8a21/hatch_modulefile-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-05 18:37:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rvandezande",
"github_project": "hatch-modulefile#readme",
"github_not_found": true,
"lcname": "hatch-modulefile"
}