Skip to main content

Hatch plugin for use in Modulefiles environments

Project description

hatch_modulefile

PyPI - Version PyPI - Python Version


This provides automatic modulefile generation for EnvironmentModules. 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

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 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hatch_modulefile-0.1.1.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

hatch_modulefile-0.1.1-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page