From dc35262440df66c0d402925d1ac0a125ffe97a19 Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Tue, 14 May 2024 18:12:44 -0400 Subject: [PATCH 1/6] Adds setup.py configuration for installation via pip etc This enables including the modules in this repository to be easily included in conda environment specifications or to be installed in a virtual environment via `pip install .`, or by installing from the Git repository. In this version it enumerates as modules to be installed all .py files starting with a capital letter. Scripts etc in all-lowercase files are therefore not installed, but this could be added where useful. Also, it is probably better then to create a proper package structure. --- setup.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..104ef3e --- /dev/null +++ b/setup.py @@ -0,0 +1,18 @@ +from setuptools import setup, find_packages + +# modules are all .py files starting with a capital letter +import os +import re + +py_modules = [f[:-3] for f in os.listdir('.') + if f.endswith('.py') and re.match(r'^[A-Z]', f)] + +setup( + name='majoros-utils', + version='0.1', + py_modules=py_modules, + description="Majoros lab utility classes", + author="Bill Majoros", + author_email='"Bill Majoros" ', + license="GPL version 3" +) From bfe3a0fc41f23d9df2435ab2155a75395ea149f9 Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Fri, 24 May 2024 18:11:56 -0400 Subject: [PATCH 2/6] Adds lookupListOrDie() as a variant of lookupList() This is being called by NeuralConfig.py in BlueSTARR, --- ConfigFile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ConfigFile.py b/ConfigFile.py index 3111db8..f002b69 100755 --- a/ConfigFile.py +++ b/ConfigFile.py @@ -33,7 +33,12 @@ def lookupList(self,key,sep=", "): value=self.lookup(key) if(value is None): return value return value.split(sep) - + + def lookupListOrDie(self,key,sep=", "): + if(self.hash[key] is None): + raise Exception("$key not defined in config file\n") + return self.lookupList(key, sep) + def lookup(self,key): return self.hash[key] From 51b45eb7f73669a837a59225c5705e83befa903c Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Fri, 24 May 2024 18:37:30 -0400 Subject: [PATCH 3/6] Uses re.split() to allow optional whitespace Apparently NeuralConfig in BlueSTARR relies on this. --- ConfigFile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ConfigFile.py b/ConfigFile.py index f002b69..c713ce6 100755 --- a/ConfigFile.py +++ b/ConfigFile.py @@ -29,12 +29,12 @@ def __init__(self,filename): self.hash={} self.load(filename) - def lookupList(self,key,sep=", "): + def lookupList(self,key,sep=",\s*"): value=self.lookup(key) if(value is None): return value - return value.split(sep) + return re.split(sep, value) - def lookupListOrDie(self,key,sep=", "): + def lookupListOrDie(self,key,sep=",\s*"): if(self.hash[key] is None): raise Exception("$key not defined in config file\n") return self.lookupList(key, sep) From 5e57d61ba5566d3747ef8c041436f0869298a992 Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Fri, 24 May 2024 18:39:32 -0400 Subject: [PATCH 4/6] Increments version so pip install --upgrade works --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 104ef3e..01a4c46 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='majoros-utils', - version='0.1', + version='0.1.2', py_modules=py_modules, description="Majoros lab utility classes", author="Bill Majoros", From 5e0378a7a3c7c7a3c871aafdfd1dcc69923eefbe Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Fri, 24 May 2024 19:06:28 -0400 Subject: [PATCH 5/6] Fixes KeyError if key not in dictionary Brings the code in line with what the method names suggest. (Otherwise dict[key] will already die with a KeyError if the key is not in the dictionary.) Also makes the formatted error strings work. --- ConfigFile.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ConfigFile.py b/ConfigFile.py index c713ce6..f55b486 100755 --- a/ConfigFile.py +++ b/ConfigFile.py @@ -35,16 +35,16 @@ def lookupList(self,key,sep=",\s*"): return re.split(sep, value) def lookupListOrDie(self,key,sep=",\s*"): - if(self.hash[key] is None): - raise Exception("$key not defined in config file\n") + if(key not in self.hash): + raise Exception(f"{key} not defined in config file\n") return self.lookupList(key, sep) def lookup(self,key): - return self.hash[key] + return self.hash.get(key) def lookupOrDie(self,key): - if(self.hash[key] is None): - raise Exception("$key not defined in config file\n") + if(key not in self.hash): + raise Exception(f"{key} not defined in config file\n") return self.hash[key] def load(self,filename): From 26424a1c02edc8ab068340ce90e8fabbace6444f Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Fri, 24 May 2024 19:11:02 -0400 Subject: [PATCH 6/6] Increments version so pip --upgrade will pick it up --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 01a4c46..8050138 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='majoros-utils', - version='0.1.2', + version='0.1.3', py_modules=py_modules, description="Majoros lab utility classes", author="Bill Majoros",