lmod-toolkit 0.0.5__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {lmod_toolkit-0.0.5/src/lmod_toolkit.egg-info → lmod_toolkit-0.0.6}/PKG-INFO +3 -1
  2. lmod_toolkit-0.0.6/README.md +29 -0
  3. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/pyproject.toml +2 -0
  4. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/setup.sh +47 -16
  5. lmod_toolkit-0.0.6/src/lmod_toolkit/__init__.py +5 -0
  6. lmod_toolkit-0.0.6/src/lmod_toolkit/__main__.py +6 -0
  7. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit/_version.py +3 -3
  8. lmod_toolkit-0.0.6/src/lmod_toolkit/bin/lmtk.sh +13 -0
  9. lmod_toolkit-0.0.6/src/lmod_toolkit/cli.py +86 -0
  10. lmod_toolkit-0.0.6/src/lmod_toolkit/config.py +69 -0
  11. lmod_toolkit-0.0.6/src/lmod_toolkit/examples/common.toml.sample +28 -0
  12. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit/lmod_config.py +17 -1
  13. lmod_toolkit-0.0.6/src/lmod_toolkit/lmod_ext_attrs.py +95 -0
  14. lmod_toolkit-0.0.6/src/lmod_toolkit/lmod_spider.py +75 -0
  15. lmod_toolkit-0.0.6/src/lmod_toolkit/logging_config.py +47 -0
  16. lmod_toolkit-0.0.6/src/lmod_toolkit/metadata.py +61 -0
  17. lmod_toolkit-0.0.6/src/lmod_toolkit/publish.py +61 -0
  18. lmod_toolkit-0.0.6/src/lmod_toolkit/test.py +54 -0
  19. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6/src/lmod_toolkit.egg-info}/PKG-INFO +3 -1
  20. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit.egg-info/SOURCES.txt +9 -1
  21. lmod_toolkit-0.0.6/src/lmod_toolkit.egg-info/requires.txt +2 -0
  22. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit.egg-info/scm_file_list.json +8 -1
  23. lmod_toolkit-0.0.6/src/lmod_toolkit.egg-info/scm_version.json +8 -0
  24. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/utils/quickstart.sh +10 -9
  25. lmod_toolkit-0.0.5/README.md +0 -7
  26. lmod_toolkit-0.0.5/src/lmod_toolkit/__init__.py +0 -1
  27. lmod_toolkit-0.0.5/src/lmod_toolkit/bin/lmtk-test.sh +0 -10
  28. lmod_toolkit-0.0.5/src/lmod_toolkit/lmod_ext_attrs.py +0 -79
  29. lmod_toolkit-0.0.5/src/lmod_toolkit/lmod_spider.py +0 -54
  30. lmod_toolkit-0.0.5/src/lmod_toolkit/test.py +0 -14
  31. lmod_toolkit-0.0.5/src/lmod_toolkit.egg-info/scm_version.json +0 -8
  32. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/.github/workflows/publish-to-test-pypi.yml +0 -0
  33. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/.gitignore +0 -0
  34. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/README.pypi +0 -0
  35. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/setup.cfg +0 -0
  36. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit/build_helper.py +0 -0
  37. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit.egg-info/dependency_links.txt +0 -0
  38. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/src/lmod_toolkit.egg-info/top_level.txt +0 -0
  39. {lmod_toolkit-0.0.5 → lmod_toolkit-0.0.6}/utils/uv_installer.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lmod-toolkit
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: ACCESS Lmod Toolkit
5
5
  Author-email: Andy Loftus <aloftus@illinois.edu>, Eric Blau <blau@globus.org>
6
6
  Project-URL: Repository, https://github.com/access-ci-org/lmod-toolkit
@@ -10,6 +10,8 @@ Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Topic :: System :: Monitoring
11
11
  Requires-Python: >=3.14
12
12
  Description-Content-Type: text/markdown
13
+ Requires-Dist: platformdirs
14
+ Requires-Dist: requests
13
15
 
14
16
  # lmod toolkit (LMTK)
15
17
  Tools for working with lmod
@@ -0,0 +1,29 @@
1
+ # lmod toolkit
2
+ Tools for working with lmod
3
+
4
+ ## Install
5
+ * `curl -o lmtk-setup.sh
6
+ https://raw.githubusercontent.com/access-ci-org/lmod-toolkit/refs/heads/main/setup.sh
7
+ `
8
+ * `./lmtk-setup.sh`
9
+ * `~/lmod-toolkit/bin/mkcfg.sh`
10
+ * Edit config file (from previous step)
11
+ * `~/lmod-toolkit/bin/test.sh`
12
+ * `~/lmod-toolkit/bin/publish.sh`
13
+
14
+ # Design
15
+ Config holds a list of Resource Definitions to be reported on.
16
+
17
+ Publish loops over each Resource Definition and for each,
18
+ * gathers & publishes:
19
+ * lmod_spider (available software modules)
20
+ * lmod_extended_attributes
21
+
22
+ It does this via Config.iter_resources(), a Python generator function.
23
+
24
+ Each iteration of iter_resources moves to a new Resource Definition and saves
25
+ the current Resource Definition.
26
+
27
+ lmod_spider and lmod_ext_attrs will ask Config for
28
+ "current_resource_definition" and do their work relative to any settings given
29
+ therein.
@@ -8,6 +8,8 @@ build-backend = "setuptools.build_meta:__legacy__"
8
8
  name = "lmod-toolkit"
9
9
  requires-python = ">=3.14"
10
10
  dependencies = [
11
+ "platformdirs",
12
+ "requests",
11
13
  ]
12
14
  dynamic = [
13
15
  "version",
@@ -160,28 +160,57 @@ update_files() {
160
160
  local _replacement="$INSTALL_DIR"
161
161
  grep -r --files-with-matches -F "$_pattern" "$LMTK_PATH" \
162
162
  | while read; do
163
- sed -i -e "s?$_pattern?$_replacement?" "$REPLY"
163
+ # update only regular files while ignoring symlinks
164
+ if [[ -f "$REPLY" ]] && [[ ! -L "$REPLY" ]]; then
165
+ sed -i -e "s?$_pattern?$_replacement?" "$REPLY"
166
+ fi
164
167
  done
165
168
  }
166
169
 
167
170
 
168
- mk_symlinks() {
171
+ mk_support_dirs() {
169
172
  [[ $DEBUG -eq $YES ]] && set -x
170
- pushd "$INSTALL_DIR"
171
- local _symlink_dirs=( bin etc configure lib var )
172
- # for d in "${_symlink_dirs[@]}"; do
173
- # [[ -L $d ]] || ln -s "$LMTK_PATH"/$d
174
- # done
175
- popd
176
- pushd "$INSTALL_DIR"/bin
177
- ln -s "${V_PYTHON}"
178
- popd
173
+ local _dirs
174
+ _dirs=( bin data logs )
175
+ for d in "${_dirs[@]}"; do
176
+ mkdir -p "$INSTALL_DIR"/"${d}"
177
+ done
179
178
  }
180
179
 
181
180
 
182
- restore_config_links() {
181
+ mk_source_symlinks() {
182
+ # For each target dir, look for dir by same name in source,
183
+ # for each file in source dir,
184
+ # create a symlink in target dir to source file
183
185
  [[ $DEBUG -eq $YES ]] && set -x
184
- /bin/bash "$INSTALL_DIR"/bin/save_configs.sh
186
+ local -a _symlink_dirs
187
+ _symlink_dirs=( 'bin' )
188
+ for target_dir in "${_symlink_dirs[@]}"; do
189
+ pushd "${INSTALL_DIR}"/"${target_dir}"
190
+ find "${LMTK_PATH}"/"${target_dir}" -mindepth 1 -maxdepth 1 -type f -print \
191
+ | while read; do
192
+ tgt_fn=$( basename "${REPLY}" )
193
+ [[ -L "${tgt_fn}" ]] || ln -s "${REPLY}"
194
+ done
195
+ popd
196
+ done
197
+ }
198
+
199
+
200
+ mk_custom_symlinks() {
201
+ [[ $DEBUG -eq $YES ]] && set -x
202
+ pushd "$INSTALL_DIR"/bin
203
+ local -A _links_targets
204
+ _links_targets=(
205
+ ['mkcfg.sh']='lmtk.sh'
206
+ ['publish.sh']='lmtk.sh'
207
+ ['test.sh']='lmtk.sh'
208
+ )
209
+ for linkname in "${!_links_targets[@]}"; do
210
+ linktarget="${_links_targets[$linkname]}"
211
+ [[ -L "${linkname}" ]] || ln -s "${linktarget}" "${linkname}"
212
+ done
213
+ popd
185
214
  }
186
215
 
187
216
 
@@ -193,8 +222,10 @@ mk_venv
193
222
 
194
223
  install_lmod_toolkit
195
224
 
196
- # update_files
225
+ update_files
226
+
227
+ mk_support_dirs
197
228
 
198
- # mk_symlinks
229
+ mk_source_symlinks
199
230
 
200
- # restore_config_links
231
+ mk_custom_symlinks
@@ -0,0 +1,5 @@
1
+ from . import lmod_config, lmod_spider, lmod_ext_attrs, _version, metadata, test, config, publish
2
+
3
+ import logging
4
+
5
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
@@ -0,0 +1,6 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ if __name__ == "__main__":
6
+ sys.exit( main() )
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.0.5'
22
- __version_tuple__ = version_tuple = (0, 0, 5)
21
+ __version__ = version = '0.0.6'
22
+ __version_tuple__ = version_tuple = (0, 0, 6)
23
23
 
24
- __commit_id__ = commit_id = 'g772328371'
24
+ __commit_id__ = commit_id = 'g7ac28a58d'
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/bash
2
+
3
+ INSTALL_DIR=___INSTALL_DIR___
4
+
5
+ set -x
6
+
7
+ CMD=$( basename $0 '.sh' )
8
+
9
+ OPT="--$CMD"
10
+
11
+ PYTHON="${INSTALL_DIR}"/.venv/bin/python
12
+
13
+ $PYTHON -m lmod_toolkit "$OPT"
@@ -0,0 +1,86 @@
1
+ import argparse
2
+ import functools
3
+ import logging
4
+ from logging.handlers import RotatingFileHandler
5
+ from textwrap import dedent
6
+
7
+ from .logging_config import configure_logging
8
+ import lmod_toolkit as lmtk
9
+
10
+ logr = logging.getLogger( __name__ )
11
+
12
+
13
+ @functools.cache
14
+ def get_args( params=None ):
15
+ constructor_args = {
16
+ 'formatter_class': argparse.RawDescriptionHelpFormatter,
17
+ 'description': 'lmod_toolkit command line interface.',
18
+ 'epilog': '''NETRC:
19
+ ACCESS lmod_toolkit publishing credentials should be stored in ~/.netrc.
20
+ ''',
21
+ }
22
+ parser = argparse.ArgumentParser( **constructor_args )
23
+ parser.add_argument( '-d', '--debug', action='store_true' )
24
+ parser.add_argument( '-v', '--verbose', action='store_true' )
25
+ action = parser.add_mutually_exclusive_group( required=True )
26
+ action.add_argument( '--test',
27
+ const='test',
28
+ dest='action',
29
+ action='store_const',
30
+ help='Test run of gathering publishing data' )
31
+ action.add_argument( '--mkcfg',
32
+ const='mkcfg',
33
+ dest='action',
34
+ action='store_const',
35
+ help='Copy a sample config into the default location' )
36
+ action.add_argument( '--publish',
37
+ const='publish',
38
+ dest='action',
39
+ action='store_const',
40
+ help='Collect and publish data (default)' )
41
+ # parser.set_defaults(
42
+ # action = 'publish',
43
+ # )
44
+ args = parser.parse_args( params )
45
+ return args
46
+
47
+
48
+ def mkcfg():
49
+ try:
50
+ lmtk.config.mk_config()
51
+ except UserWarning as e:
52
+ msg = str( e )
53
+ else:
54
+ msg = dedent( f"""
55
+ New config file: '{lmtk.config.get_config()}'
56
+ You MUST add at least one valid resource to the config before publishing.
57
+ Next Steps:
58
+ 1. Edit the config file '{lmtk.config.get_config()}'
59
+ 2. Test with: '~/lmod-toolkit/bin/python -m lmod_toolkit --test'
60
+ """).strip( "\n" )
61
+ return( msg )
62
+
63
+
64
+ def setup_logging():
65
+ args = get_args()
66
+ loglvl = logging.WARNING
67
+ if args.debug:
68
+ loglvl = logging.DEBUG
69
+ elif args.verbose:
70
+ loglvl = logging.INFO
71
+ logfile = lmtk.metadata.log_dir / f'{__package__}.log'
72
+ configure_logging( log_level=loglvl, log_file=logfile )
73
+
74
+
75
+ def main():
76
+ setup_logging()
77
+ args = get_args()
78
+ if args.action == 'test':
79
+ lmtk.test.all_tests()
80
+ elif args.action == 'publish':
81
+ lmtk.publish.go()
82
+ elif args.action == 'mkcfg':
83
+ status = mkcfg()
84
+ print( status )
85
+ else:
86
+ raise SystemExit( f"Invalid action: '{args.action}'" )
@@ -0,0 +1,69 @@
1
+ import functools
2
+ import os
3
+ import tomllib
4
+
5
+ from pathlib import Path
6
+ from platformdirs import PlatformDirs
7
+
8
+ import lmod_toolkit as lmtk
9
+
10
+
11
+ __all__ = [
12
+ 'get_config_path',
13
+ 'get_config',
14
+ 'mk_config',
15
+ ]
16
+
17
+ module_resources = {
18
+ 'current_resource_definition': None,
19
+ }
20
+
21
+
22
+ @functools.cache
23
+ def get_config_path():
24
+ # allow LMTK_CONFIG_PATH override
25
+ from_env = os.getenv( 'LMTK_CONFIG_PATH', None ) #default to None
26
+ if from_env:
27
+ cfg_path = Path( from_env )
28
+ else:
29
+ dirs = PlatformDirs( appname=__package__, ensure_exists=True )
30
+ cfg_path = dirs.place_config_file( 'common.toml' )
31
+ return cfg_path
32
+
33
+
34
+ @functools.cache
35
+ def get_config():
36
+ cfg_path = get_config_path()
37
+ with cfg_path.open( mode='rb' ) as fh:
38
+ cfg_data = tomllib.load( fh )
39
+ return cfg_data
40
+
41
+
42
+ def mk_config():
43
+ cfg_path = get_config_path()
44
+ if cfg_path.exists():
45
+ raise UserWarning( f"ConfigFile '{cfg_path}' exists, refusing to overwrite" )
46
+ # get module install dir
47
+ pkg_dir = lmtk.metadata.install_path
48
+ cfg_sample = pkg_dir / 'examples' / 'common.toml.sample'
49
+ encoding='utf-8'
50
+ sample_text = cfg_sample.read_text( encoding=encoding )
51
+ cfg_path.write_text( sample_text, encoding=encoding )
52
+
53
+
54
+ def iter_resources():
55
+ ''' Loop through all the resource definitions in the config
56
+ Yield one at a time as a generator function.
57
+ Additionally, and more importantly, set "current_resource_definition"
58
+ so other functions can operate accordingly
59
+ for whatever is the current_resource_definition.
60
+ This function effectively controls all the activity in this package ...
61
+ ... it is the "main loop", if you will.
62
+ '''
63
+ for resource_definition in get_config()['resources']:
64
+ module_resources['current_resource_definition'] = resource_definition
65
+ yield resource_definition
66
+
67
+
68
+ def get_current_resource_definition():
69
+ return module_resources['current_resource_definition']
@@ -0,0 +1,28 @@
1
+ [[resources]]
2
+ # name is one of:
3
+ # + global_resource_id, defined in cider.access-ci.org
4
+ # + global_group_id, defined in
5
+ # https://operations-api.access-ci.org/wh2/cider/v1/access-active-groups/
6
+ # Required? YES
7
+ # Data type: string
8
+ name =
9
+
10
+ # type is one of: "global_resource_id", "global_group_id"
11
+ # it is essentially telling where the "name" (above) came from
12
+ # Required? YES
13
+ # Data type: string
14
+ type =
15
+
16
+ # Specify a custom module path to use instead of MODULEPATH environment variable
17
+ # [OPTIONAL] string: same format and purpose of MODULEPATH
18
+ # Required? No (defaults to MODULEPATH environment variable)
19
+ # Data type: string
20
+ modulepath =
21
+
22
+
23
+ # Can specify this multiple times
24
+ # data for each unique resource_id OR group_id will be published in turn
25
+ #[[resources]]
26
+ #name =
27
+ #type =
28
+ #modulepath =
@@ -2,10 +2,14 @@ import functools
2
2
  import json
3
3
  import pprint
4
4
  import subprocess
5
+ import sys
6
+
7
+ from pathlib import Path
5
8
 
6
9
  __all__ = [
7
10
  'as_json',
8
11
  'get_config',
12
+ 'get_spider_path',
9
13
  ]
10
14
 
11
15
  @functools.cache
@@ -19,8 +23,20 @@ def get_config():
19
23
  return json.loads( result.stderr )
20
24
 
21
25
 
26
+ @functools.cache
27
+ def get_spider_path():
28
+ this_py_module = sys.modules[ __name__ ]
29
+ prefix = this_py_module.prefix
30
+ libexec = Path( prefix , 'lmod' , 'lmod' , 'libexec' )
31
+ return libexec / 'spider'
32
+
33
+
34
+ def as_dict():
35
+ return get_config()
36
+
37
+
22
38
  def as_json():
23
- return json.dumps( get_config() )
39
+ return json.dumps( as_dict() )
24
40
 
25
41
 
26
42
  def __getattr__( name ):
@@ -0,0 +1,95 @@
1
+ import functools
2
+ import json
3
+ import logging
4
+ import pprint
5
+ import re
6
+
7
+ from pathlib import Path
8
+
9
+ import lmod_toolkit as lmtk
10
+
11
+ logr = logging.getLogger( __name__ )
12
+
13
+ __all__ = [
14
+ 'as_json',
15
+ 'get_ext_attrs',
16
+ ]
17
+
18
+ # Adapted from:
19
+ # https://github.com/access-ci-org/ipf/blob/3e419ebb2d0f404454ec7a8c3630f5cf24c2d756/ipf/glue2/modules.py#L444
20
+ EXTATTR_KEYS = [
21
+ 'Name',
22
+ 'Version',
23
+ '.*escription',
24
+ 'URL',
25
+ 'Category',
26
+ 'Keywords',
27
+ 'SupportStatus',
28
+ 'SupportContact',
29
+ 'Default',
30
+ 'IPF_FLAGS',
31
+ ]
32
+ LONGEST_FIRST = sorted(EXTATTR_KEYS, key=len, reverse=True)
33
+ WHATIS_RE = re.compile(r'whatis\(\[\[((?:{}))\s*:\s*(.*)\]\]\)'.format('|'.join(LONGEST_FIRST)))
34
+ COMMENT_RE = re.compile(r'\"((?:{})):([^\"]+)\"'.format('|'.join(LONGEST_FIRST)))
35
+
36
+
37
+ def get_ext_attrs():
38
+ ''' Search through all modules' lua files for any extended attributes.
39
+ Extended attributes are non-lmod supported data added to a
40
+ lua module definition.
41
+ '''
42
+ ext_attrs = {}
43
+ for module in lmtk.lmod_spider.get_module_data():
44
+ for version in module[ 'versions' ]:
45
+ # path = version[ 'path' ]
46
+ ## skip non-lua files
47
+ #if not path.endswith(".lua"):
48
+ # #logr.debug( f"skipping non-lua file {path}" )
49
+ # print( f"skipping non-lua file {path}" )
50
+ # continue
51
+ filepath = Path( version[ 'path' ] )
52
+ # try:
53
+ # file_contents = filepath.read_text()
54
+ # except ( FileNotFoundError, PermissionError, IOError ) as e:
55
+ # logr.warning( f"error opening file '{filepath}' {e}" )
56
+ # continue
57
+ # ext_data = get_ext_attrs_from_lua_file( file_contents )
58
+ ext_data = get_ext_attrs_from_lua_file( filepath )
59
+ if ext_data:
60
+ full_name = version[ 'full' ]
61
+ ext_attrs[ full_name ] = ext_data
62
+ return ext_attrs
63
+
64
+
65
+ # wrapping this with functools.cache ensures we open a file only once
66
+ # @functools.cache
67
+ def get_ext_attrs_from_lua_file( filepath: Path ) -> dict:
68
+ ''' text parsing taken from
69
+ https://github.com/access-ci-org/ipf/blob/3e419ebb/ipf/glue2/modules.py#L444
70
+ '''
71
+ try:
72
+ text = filepath.read_text()
73
+ except ( FileNotFoundError, PermissionError, IOError ) as e:
74
+ logr.warning( f"error opening file '{filepath}' {e}" )
75
+ return None
76
+ whatis_res = WHATIS_RE.findall(text)
77
+ comment_res = COMMENT_RE.findall(text)
78
+ # Return all tuples found, allow "comment" to override "whatis"
79
+ ext_attrs = {
80
+ k: v
81
+ for k, v in whatis_res+comment_res
82
+ }
83
+ return ext_attrs
84
+
85
+
86
+ def as_dict():
87
+ return get_ext_attrs()
88
+
89
+
90
+ def as_json():
91
+ return json.dumps( as_dict() )
92
+
93
+
94
+ if __name__ == '__main__':
95
+ pprint.pprint( get_ext_attrs() )
@@ -0,0 +1,75 @@
1
+ import functools
2
+ import json
3
+ import os
4
+ import pprint
5
+ import subprocess
6
+
7
+ from pathlib import Path
8
+
9
+ import lmod_toolkit as lmtk
10
+
11
+
12
+ __all__ = [
13
+ 'as_json',
14
+ 'get_modulepath',
15
+ 'get_module_data',
16
+ 'get_module_files',
17
+ 'get_module_names',
18
+ ]
19
+
20
+
21
+ def get_modulepath():
22
+ current_resource = lmtk.config.get_current_resource_definition()
23
+ current_modulepath = current_resource.get( 'modulepath', None )
24
+ # If current modulepath is None, try to get it from the environment
25
+ if current_modulepath is None:
26
+ try:
27
+ current_modulepath = os.environ[ 'MODULEPATH' ]
28
+ except KeyError as e:
29
+ raise SystemExit( f"Missing environment variable 'MODULEPATH'\n{e}" )
30
+ return current_modulepath
31
+
32
+
33
+ def get_module_data():
34
+ ''' Wrapper around get_lmod_spider_software_page
35
+ passing the current value of MODULEPATH
36
+ so that functools.cache works as expected,
37
+ caching the results for a given modulepath
38
+ '''
39
+ current_modulepath = get_modulepath()
40
+ return get_lmod_spider_software_page( modulepath=current_modulepath )
41
+
42
+
43
+ def get_module_names():
44
+ return get_module_data().keys()
45
+
46
+
47
+ def get_module_files():
48
+ return [
49
+ v.keys()
50
+ for v in get_module_data().values()
51
+ ]
52
+
53
+
54
+ def as_dict():
55
+ return get_module_data()
56
+
57
+
58
+ def as_json():
59
+ return json.dumps( as_dict() )
60
+
61
+
62
+ @functools.cache
63
+ def get_lmod_spider_software_page( modulepath ):
64
+ spider = lmtk.lmod_config.get_spider_path()
65
+ cmds = [ 'bash', '-l', '-c', f"{spider} -o jsonSoftwarePage \"{modulepath}\"" ]
66
+ result = subprocess.run(
67
+ cmds,
68
+ capture_output=True, # Captures both stdout and stderr
69
+ text=True # Returns strings instead of bytes
70
+ )
71
+ return json.loads( result.stdout )
72
+
73
+
74
+ if __name__ == '__main__':
75
+ pprint.pprint( get_module_data() )
@@ -0,0 +1,47 @@
1
+ import logging.config
2
+
3
+ PKG = __name__.split(".")[0] # "mypkg"
4
+
5
+ def configure_logging( log_level=logging.WARNING, log_file=None ):
6
+ handlers = {
7
+ 'console': {
8
+ 'class': 'logging.StreamHandler',
9
+ 'formatter': 'std',
10
+ 'level': log_level,
11
+ }
12
+ }
13
+ if log_file:
14
+ # ensure file log level is at least INFO
15
+ file_log_level = logging.INFO
16
+ if log_level == logging.DEBUG:
17
+ file_log_level = logging.DEBUG
18
+ handlers['file'] = {
19
+ 'class': 'logging.handlers.RotatingFileHandler',
20
+ 'formatter': 'std',
21
+ 'filename': log_file,
22
+ 'level': file_log_level,
23
+ 'mode': 'a',
24
+ 'encoding': 'utf-8',
25
+ 'maxBytes': 10485760, #10MB
26
+ 'backupCount': 5,
27
+ }
28
+
29
+ logging.config.dictConfig( {
30
+ 'version': 1,
31
+ 'disable_existing_loggers': False,
32
+ 'formatters': {
33
+ 'std': {
34
+ 'format': '{asctime} {levelname} {name}.{funcName}[{lineno}] {message}',
35
+ 'style': '{',
36
+ },
37
+ },
38
+ 'handlers': handlers,
39
+ 'loggers': {
40
+ PKG: {
41
+ 'level': 'DEBUG', # let handlers decide what to show
42
+ 'handlers': list(handlers),
43
+ 'propogate': False,
44
+ },
45
+ },
46
+ }
47
+ )
@@ -0,0 +1,61 @@
1
+ import functools
2
+ import importlib.metadata
3
+ import json
4
+ import pprint
5
+
6
+ from pathlib import Path
7
+
8
+ import lmod_toolkit as lmtk
9
+
10
+ __all__ = [
11
+ 'as_dict',
12
+ 'as_json',
13
+ ]
14
+
15
+
16
+ @functools.cache
17
+ def get_metadata():
18
+ pkg_install_dir = Path(__file__).resolve().parent
19
+ user_install_dir = get_user_install_dir()
20
+ data_dir = user_install_dir / 'data'
21
+ log_dir = user_install_dir / 'logs'
22
+ return {
23
+ 'data_dir': data_dir,
24
+ 'log_dir': log_dir,
25
+ 'pkg_install_dir': pkg_install_dir,
26
+ 'pkg_name': __package__,
27
+ 'user_install_dir': user_install_dir,
28
+ 'version': lmtk._version.version,
29
+ }
30
+
31
+
32
+ def get_user_install_dir():
33
+ module_path = Path(__file__).resolve()
34
+ parts = []
35
+ for part in module_path.parts:
36
+ if part != '.venv':
37
+ parts.append( part )
38
+ else:
39
+ break
40
+ return Path( *parts )
41
+
42
+
43
+ def as_dict():
44
+ ''' Implement the common interface method as_dict()
45
+ to get this module's relevant data as type dict
46
+ '''
47
+ return get_metadata()
48
+
49
+
50
+ def as_json():
51
+ ''' Implement the common interface method as_json()
52
+ to get this module's relevant data as a json string
53
+ '''
54
+ return json.dumps( get_metadata() )
55
+
56
+
57
+ def __getattr__( name ):
58
+ return( get_metadata()[name] )
59
+
60
+ if __name__ == '__main__':
61
+ pprint.pprint( as_json() )
@@ -0,0 +1,61 @@
1
+ import datetime
2
+ import importlib
3
+ import json
4
+ # import requests
5
+ import time
6
+
7
+ from pathlib import Path
8
+ from textwrap import dedent
9
+
10
+ import lmod_toolkit as lmtk
11
+
12
+
13
+ __all__ = [
14
+ 'get_resource_data',
15
+ ]
16
+
17
+ data_functions = [
18
+ 'lmod_spider',
19
+ 'lmod_ext_attrs',
20
+ ]
21
+
22
+
23
+ def go():
24
+ lmtk_metadata = lmtk.metadata.as_dict()
25
+ lmod_config_data = lmtk.lmod_config.as_dict()
26
+ for resource_definition in lmtk.config.iter_resources():
27
+ for pymod_name in data_functions:
28
+ pymod = importlib.import_module( f"lmod_toolkit.{pymod_name}" )
29
+ data_to_publish = {
30
+ 'resource': resource_definition,
31
+ 'lmod_toolkit': lmtk.metadata.as_dict(),
32
+ 'manifest': { 'data_type': pymod_name },
33
+ 'payload': pymod.as_dict(),
34
+ }
35
+ publish_data( data=data_to_publish, datatype=pymod_name )
36
+
37
+
38
+ def publish_data( data: dict, datatype: string ) -> None:
39
+ filepath = write_to_local_file( data=data, datatype=datatype )
40
+ # upload_http( data )
41
+
42
+
43
+ def write_to_local_file( data: dict, datatype: string ) -> Path:
44
+ # make output filename
45
+ ts = int( time.time() )
46
+ timestamp = datetime.datetime.fromtimestamp( ts, tz=datetime.timezone.utc )
47
+ fn_suffix = timestamp.strftime( '%F_%T%z' )
48
+ outfile = lmtk.metadata.data_dir / f"{datatype}.{fn_suffix}"
49
+
50
+ # write data
51
+ with outfile.open( mode='w', encoding='utf-8' ) as fh:
52
+ json.dump( data, fh, default=str )
53
+
54
+ return outfile
55
+
56
+
57
+ def upload_http( filename: Path ) -> None:
58
+ ''' Upload file data to a web API via HTTP.
59
+ See also: https://github.com/andylytical/jira-tools/blob/main/web_api.py
60
+ '''
61
+ pass
@@ -0,0 +1,54 @@
1
+ import pprint
2
+ from textwrap import dedent
3
+ from tomllib import TOMLDecodeError
4
+
5
+ import lmod_toolkit as lmtk
6
+
7
+
8
+ def lmtk_config_test():
9
+ print( '\nLmod-toolkit Config' )
10
+ print( '===================' )
11
+ try:
12
+ cfg = lmtk.config.get_config()
13
+ except TOMLDecodeError as e:
14
+ msg = dedent( f"""
15
+ Error parsing config file '{lmtk.config.get_config_path()}'
16
+ tomllib.TOMLDecodeError ({e})
17
+ """).strip( "\n" )
18
+ raise SystemExit( msg )
19
+ else:
20
+ pprint.pprint( cfg )
21
+
22
+
23
+ def lmod_config_test():
24
+ print( '\nLMOD CONFIG' )
25
+ print( '===========' )
26
+ print( lmtk.lmod_config.as_json() )
27
+
28
+
29
+ def lmod_spider_test():
30
+ print( '\nLMOD SPIDER' )
31
+ print( '===========' )
32
+ print( lmtk.lmod_spider.as_json() )
33
+
34
+
35
+ def lmod_extended_attrs_test():
36
+ print( '\nLMOD EXT ATTRS' )
37
+ print( '==============' )
38
+ print( lmtk.lmod_ext_attrs.as_json() )
39
+
40
+
41
+
42
+ def all_tests():
43
+ lmtk_config_test() #test loading the config
44
+
45
+ # initialize config by loading the first resource
46
+ resources = lmtk.config.iter_resources() #iter_resources is a generator function
47
+ next( resources ) #tell the generator to "set up" the first resource
48
+
49
+ lmod_config_test()
50
+ lmod_spider_test()
51
+ lmod_extended_attrs_test()
52
+
53
+ if __name__ == '__main__':
54
+ all_tests()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lmod-toolkit
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: ACCESS Lmod Toolkit
5
5
  Author-email: Andy Loftus <aloftus@illinois.edu>, Eric Blau <blau@globus.org>
6
6
  Project-URL: Repository, https://github.com/access-ci-org/lmod-toolkit
@@ -10,6 +10,8 @@ Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Topic :: System :: Monitoring
11
11
  Requires-Python: >=3.14
12
12
  Description-Content-Type: text/markdown
13
+ Requires-Dist: platformdirs
14
+ Requires-Dist: requests
13
15
 
14
16
  # lmod toolkit (LMTK)
15
17
  Tools for working with lmod
@@ -5,18 +5,26 @@ pyproject.toml
5
5
  setup.sh
6
6
  .github/workflows/publish-to-test-pypi.yml
7
7
  src/lmod_toolkit/__init__.py
8
+ src/lmod_toolkit/__main__.py
8
9
  src/lmod_toolkit/_version.py
9
10
  src/lmod_toolkit/build_helper.py
11
+ src/lmod_toolkit/cli.py
12
+ src/lmod_toolkit/config.py
10
13
  src/lmod_toolkit/lmod_config.py
11
14
  src/lmod_toolkit/lmod_ext_attrs.py
12
15
  src/lmod_toolkit/lmod_spider.py
16
+ src/lmod_toolkit/logging_config.py
17
+ src/lmod_toolkit/metadata.py
18
+ src/lmod_toolkit/publish.py
13
19
  src/lmod_toolkit/test.py
14
20
  src/lmod_toolkit.egg-info/PKG-INFO
15
21
  src/lmod_toolkit.egg-info/SOURCES.txt
16
22
  src/lmod_toolkit.egg-info/dependency_links.txt
23
+ src/lmod_toolkit.egg-info/requires.txt
17
24
  src/lmod_toolkit.egg-info/scm_file_list.json
18
25
  src/lmod_toolkit.egg-info/scm_version.json
19
26
  src/lmod_toolkit.egg-info/top_level.txt
20
- src/lmod_toolkit/bin/lmtk-test.sh
27
+ src/lmod_toolkit/bin/lmtk.sh
28
+ src/lmod_toolkit/examples/common.toml.sample
21
29
  utils/quickstart.sh
22
30
  utils/uv_installer.sh
@@ -0,0 +1,2 @@
1
+ platformdirs
2
+ requests
@@ -7,11 +7,18 @@
7
7
  "pyproject.toml",
8
8
  "setup.sh",
9
9
  "src/lmod_toolkit/__init__.py",
10
- "src/lmod_toolkit/bin/lmtk-test.sh",
10
+ "src/lmod_toolkit/__main__.py",
11
+ "src/lmod_toolkit/bin/lmtk.sh",
11
12
  "src/lmod_toolkit/build_helper.py",
13
+ "src/lmod_toolkit/cli.py",
14
+ "src/lmod_toolkit/config.py",
15
+ "src/lmod_toolkit/examples/common.toml.sample",
12
16
  "src/lmod_toolkit/lmod_config.py",
13
17
  "src/lmod_toolkit/lmod_ext_attrs.py",
14
18
  "src/lmod_toolkit/lmod_spider.py",
19
+ "src/lmod_toolkit/logging_config.py",
20
+ "src/lmod_toolkit/metadata.py",
21
+ "src/lmod_toolkit/publish.py",
15
22
  "src/lmod_toolkit/test.py",
16
23
  "utils/quickstart.sh",
17
24
  "utils/uv_installer.sh"
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.0.6",
3
+ "distance": 0,
4
+ "node": "g7ac28a58d17519a7ea972318cbcc951116645178",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-12-02"
8
+ }
@@ -67,17 +67,18 @@ if [[ -n "${MANUAL}" ]] ; then
67
67
  echo '---------------------------------'
68
68
  fi
69
69
 
70
- # stop anything running
71
- # [[ -x "${IPF_BIN}"/wfm ]] && ${ACTION} bash "${IPF_BIN}"/wfm stop
70
+ # Unless upgrade is specified, do a full clean & reinstall
71
+ if [[ -z "${LMTK_ALLOW_UPGRADE}" ]] ; then
72
+ # cleanup any existing installs
73
+ ${ACTION} rm -rf "${LMTK_INSTALL_DIR}"
72
74
 
73
- # cleanup any existing installs
74
- ${ACTION} rm -rf "${LMTK_INSTALL_DIR}"
75
- # ${ACTION} rm -rf "${HOME}"/.cache/pip #shouldn't need this anymore since switched to UV
75
+ # rm local setup script
76
+ ${ACTION} rm -f "${LMTK_SETUP}"
77
+ fi
76
78
 
77
- # get new setup script
78
- ${ACTION} rm -f "${LMTK_SETUP}"
79
- ${ACTION} curl -o "${LMTK_SETUP}" "${LMTK_SETUP_URL}"
80
- # and run it
79
+ # get new setup script (if needed)
80
+ [[ -f "${LMTK_SETUP}" ]] || ${ACTION} curl -o "${LMTK_SETUP}" "${LMTK_SETUP_URL}"
81
+ # run setup script
81
82
  ${ACTION} bash "${LMTK_SETUP}"
82
83
 
83
84
  # validate install
@@ -1,7 +0,0 @@
1
- # lmod toolkit
2
- Tools for working with lmod
3
-
4
- ## Install
5
- ` curl -o lmtk-setup.sh
6
- https://raw.githubusercontent.com/access-ci-org/lmod-toolkit/refs/heads/main/setup.sh
7
- `
@@ -1 +0,0 @@
1
- from . import lmod_config, lmod_spider, lmod_ext_attrs
@@ -1,10 +0,0 @@
1
- #!/usr/bin/bash
2
-
3
- INSTALL_DIR=___INSTALL_DIR___
4
- V_PYTHON="${INSTALLL_DIR}"/.venv/bin/python
5
- SITE_PACKAGES=$(
6
- "${V_PYTHON}" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'
7
- )
8
- LMTK_PATH="${SITE_PACKAGES}"/lmod_toolkit
9
-
10
- "${V_PYTHON}" "${LMTK_PATH}"/test.py
@@ -1,79 +0,0 @@
1
- import functools
2
- import json
3
- import pprint
4
- import re
5
-
6
- from pathlib import Path
7
-
8
- from lmod_toolkit import lmod_spider
9
-
10
- __all__ = [
11
- 'as_json',
12
- 'get_ext_attrs',
13
- ]
14
-
15
- EXTATTR_KEYS = [
16
- 'Name',
17
- 'Version',
18
- '.*escription',
19
- 'URL',
20
- 'Category',
21
- 'Keywords',
22
- 'SupportStatus',
23
- 'SupportContact',
24
- 'Default',
25
- 'IPF_FLAGS',
26
- ]
27
- LONGEST_FIRST = sorted(EXTATTR_KEYS, key=len, reverse=True)
28
- WHATIS_RE = re.compile(r'whatis\(\[\[((?:{}))\s*:\s*(.*)\]\]\)'.format('|'.join(LONGEST_FIRST)))
29
- COMMENT_RE = re.compile(r'\"((?:{})):([^\"]+)\"'.format('|'.join(LONGEST_FIRST)))
30
-
31
-
32
- @functools.cache
33
- def get_ext_attrs():
34
- ''' Search through all modules' lua files for any extended attributes.
35
- Extended attributes are non-lmod supported data added to a lua file.
36
- '''
37
- ext_attrs = {}
38
- for module in lmod_spider.get_module_data():
39
- for version in module[ 'versions' ]:
40
- path = version[ 'path' ]
41
- # skip non-lua files
42
- if not path.endswith(".lua"):
43
- #logr.debug( f"skipping non-lua file {path}" )
44
- print( f"skipping non-lua file {path}" )
45
- continue
46
- filepath = Path( path )
47
- try:
48
- file_contents = filepath.read_text()
49
- except ( FileNotFoundError, PermissionError, IOError ) as e:
50
- #logr.debug( f"error opening file '{filepath}' {e}" )
51
- print( f"error opening file '{filepath}' {e}" )
52
- continue
53
- ext_data = get_ext_attrs_from_lua_file( file_contents )
54
- if ext_data:
55
- full_name = version[ 'full' ]
56
- ext_attrs[ full_name ] = ext_data
57
- return ext_attrs
58
-
59
-
60
- def get_ext_attrs_from_lua_file( text: str ) -> dict:
61
- ''' text parsing taken from
62
- https://github.com/access-ci-org/ipf/blob/3e419ebb/ipf/glue2/modules.py#L444
63
- '''
64
- whatis_res = WHATIS_RE.findall(text)
65
- comment_res = COMMENT_RE.findall(text)
66
- # Return all tuples found, allow "comment" to override "whatis"
67
- ext_attrs = {
68
- k: v
69
- for k, v in whatis_res+comment_res
70
- }
71
- return ext_attrs
72
-
73
-
74
- def as_json():
75
- return json.dumps( get_ext_attrs() )
76
-
77
-
78
- if __name__ == '__main__':
79
- pprint.pprint( get_ext_attrs() )
@@ -1,54 +0,0 @@
1
- import functools
2
- import json
3
- import os
4
- import pprint
5
- import subprocess
6
-
7
- from pathlib import Path
8
-
9
- from lmod_toolkit import lmod_config
10
-
11
-
12
- __all__ = [
13
- 'as_json',
14
- 'get_module_data',
15
- 'get_module_files',
16
- 'get_module_names',
17
- ]
18
-
19
-
20
- @functools.cache
21
- def get_module_data():
22
- prefix = lmod_config.prefix
23
- libexec = Path( prefix , 'lmod' , 'lmod' , 'libexec' )
24
- spider = libexec / 'spider'
25
- try:
26
- MODULEPATH = os.environ[ 'MODULEPATH' ] #will fail with KeyError if not found
27
- except KeyError as e:
28
- raise SystemExit( f"Missing environment variable 'MODULEPATH'\n{e}" )
29
- cmds = [ 'bash', '-l', '-c', f"{spider} -o jsonSoftwarePage \"{MODULEPATH}\"" ]
30
- result = subprocess.run(
31
- cmds,
32
- capture_output=True, # Captures both stdout and stderr
33
- text=True # Returns strings instead of bytes
34
- )
35
- return json.loads( result.stdout )
36
-
37
-
38
- def get_module_names():
39
- return get_module_data().keys()
40
-
41
-
42
- def get_module_files():
43
- return [
44
- v.keys()
45
- for v in get_module_data().values()
46
- ]
47
-
48
-
49
- def as_json():
50
- return json.dumps( get_module_data() )
51
-
52
-
53
- if __name__ == '__main__':
54
- pprint.pprint( get_module_data() )
@@ -1,14 +0,0 @@
1
-
2
- import lmod_toolkit as lmtk
3
-
4
- print( '\nLMOD CONFIG' )
5
- print( '===========' )
6
- print( lmtk.lmod_config.as_json() )
7
-
8
- print( '\nLMOD SPIDER' )
9
- print( '===========' )
10
- print( lmtk.lmod_spider.as_json() )
11
-
12
- print( '\nLMOD EXT ATTRS' )
13
- print( '==============' )
14
- print( lmtk.lmod_ext_attrs.as_json() )
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "0.0.5",
3
- "distance": 0,
4
- "node": "g772328371eff4a673f8284183d36aa2ccc19c951",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-11-18"
8
- }
File without changes
File without changes
File without changes