diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e65557..2ed4c4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,7 @@ foreach(suffix rate_constants conditions) "${ENUM_SRC_REGEX}" --src-regex --dst-type=c --dst=${ENUM_DST} --dst-maps=${ENUM_MAP} --dst-maps-header=${ENUM_MAP_H} --dst-global=${ENUM_GLOBAL} + --enum-name-global=MODULE --root-include-dir=${CMAKE_CURRENT_SOURCE_DIR}/include --include-file-maps=${ENUM_UTILS} --prefix-by-split=${suffix} --overwrite # --verbose diff --git a/cmake/FindSUNDIALS.cmake b/cmake/FindSUNDIALS.cmake index 628d167..0575720 100644 --- a/cmake/FindSUNDIALS.cmake +++ b/cmake/FindSUNDIALS.cmake @@ -153,7 +153,7 @@ if (SUNDIALS_INCLUDE_DIR) CVODE_DIRECT_INCLUDE_DIR NVECTOR_INCLUDE_DIR KINSOL_INCLUDE_DIR) - if(NOT ${${x}} STREQUAL "NOTFOUND") + if(NOT ${${x}} STREQUAL "${x}-NOTFOUND") list(APPEND SUNDIALS_INCLUDE_DIRS ${${x}}) endif() endforeach() diff --git a/include/enums/enums.hpp b/include/enums/enums.hpp index 732548c..38777eb 100644 --- a/include/enums/enums.hpp +++ b/include/enums/enums.hpp @@ -1,4 +1,19 @@ #pragma once + #include "enums/enums_conditions.hpp" #include "enums/enums_rate_constants.hpp" +enum EMPTY_ENUM {}; +enum MODULE { + MODULE_NONE , + MODULE_PR , + MODULE_PS , + MODULE_RedoxReg , + MODULE_FI , + MODULE_RuACT , + MODULE_XanCycle , + MODULE_SUCS , + MODULE_BF , + MODULE_RROEA , + MODULE_MAX , +}; diff --git a/include/enums/enums_conditions.hpp b/include/enums/enums_conditions.hpp index 67c3300..cc87c09 100644 --- a/include/enums/enums_conditions.hpp +++ b/include/enums/enums_conditions.hpp @@ -1,6 +1,7 @@ #pragma once enum PR_conditions { + PR_conditions_NONE , PR_GCEA , //!< Glycerate in chloroplast; derived based on V113 PR_GCA , //!< Derived from radioactive labelling experiment; assume equal concenatration inside and outshide chloroplast PR_PGCA , //!< Phosphoglycolate in chloroplast derived based on the Km112; orignal value is : 0.0029; @@ -11,9 +12,11 @@ enum PR_conditions { PR_HPRc , //!< HydroxylPyruvate; derived from equation 123; PR_GCEAc , //!< Glycerate in cytosol; assume at equilibrium with GCEA initially. PR_RuBP , //!< RuBP concentration + PR_conditions_MAX , }; enum PS_conditions { + PS_conditions_NONE , PS_RuBP , PS_PGA , PS_DPGA , @@ -26,17 +29,21 @@ enum PS_conditions { PS_ATP , PS_HexP , PS_PenP , + PS_conditions_MAX , }; enum RedoxReg_conditions { + RedoxReg_conditions_NONE , RedoxReg_ThioRatio , RedoxReg_FBPase , RedoxReg_SBPase , RedoxReg_PRK , RedoxReg_ATPase , + RedoxReg_conditions_MAX , }; enum FI_conditions { + FI_conditions_NONE , FI_A , //!< The concentration of excitons in the peripheral antenna FI_U , //!< The concentration fo excitons in the core antenna FI_P680ePheo , //!< The concentration of the P680Pheo @@ -59,23 +66,29 @@ enum FI_conditions { FI_QAQB2n , //!< The concentration of [QAQB2-] FI_QAnQB2n , //!< The concentration of [QA-QB2-] FI_PQn , //!< The concentration of reduced PQ, i.e. PQH2; + FI_conditions_MAX , }; enum RuACT_conditions { + RuACT_conditions_NONE , RuACT_ER , //!< The concentration of inactive ER RuACT_Eaf , //!< The total concentration of E, EC, AND ECM RuACT_ECMR , //!< The concentration of ECMR RuACT_RuBP , //!< The concentration of ECMR + RuACT_conditions_MAX , }; enum XanCycle_conditions { + XanCycle_conditions_NONE , XanCycle_Vx , //!< * 0.37 XanCycle_Ax , //!< * 0.37 XanCycle_Zx , //!< * 0.37 XanCycle_ABA , + XanCycle_conditions_MAX , }; enum SUCS_conditions { + SUCS_conditions_NONE , SUCS_T3Pc , SUCS_FBPc , SUCS_HexPc , @@ -84,9 +97,11 @@ enum SUCS_conditions { SUCS_SUCP , SUCS_SUC , SUCS_PGAc , + SUCS_conditions_MAX , }; enum BF_conditions { + BF_conditions_NONE , BF_ISPHr , //!< The reduced ion sulfer protein (ISPH) BF_cytc1 , //!< The oxidized state of cytc1 BF_ISPo , //!< The oxidized ion sulfer protein (ISP) @@ -116,12 +131,15 @@ enum BF_conditions { BF_PHs , //!< The PH value of the stroma BF_PHl , //!< The PH value of the lumen BF_NADPH , //!< The NADPH concentration in stroma, Unit: mmol l-1; + BF_conditions_MAX , }; enum RROEA_conditions { + RROEA_conditions_NONE , RROEA_MDH , //!< The initial concentration of actove MDH RROEA_Thio , //!< The initial concentration of reduced thioredoxin RROEA_Fd , //!< The initial concentration of reduced ferrodoxin RROEA_RuACT , //!< The initial concentration of active Rubisco activase + RROEA_conditions_MAX , }; diff --git a/include/enums/enums_rate_constants.hpp b/include/enums/enums_rate_constants.hpp index 7e90997..c3d85b0 100644 --- a/include/enums/enums_rate_constants.hpp +++ b/include/enums/enums_rate_constants.hpp @@ -1,6 +1,7 @@ #pragma once enum RuACT_rate_constants { + RuACT_rate_constants_NONE , RuACT_k1 , //!< The rate constant of the activation of the Rubisco bound with RuBP. This step is associated with the ARubisco theVars->activase content or activity; RuACT_kn1 , //!< The rate constant of E inactivation by binding of RuBP; RuACT_km1 , //!< The michaelis menton constant for RuBP with E. @@ -15,16 +16,20 @@ enum RuACT_rate_constants { RuACT_C , //!< mM RuACT_O , //!< mM RuACT_M , + RuACT_rate_constants_MAX , }; enum RedoxReg_rate_constants { + RedoxReg_rate_constants_NONE , RedoxReg_Fd_Thio_ET , RedoxReg_ThioT , RedoxReg_Thio_Oxidation , RedoxReg_Thion0 , //!< This is a wild guess + RedoxReg_rate_constants_MAX , }; enum PR_rate_constants { + PR_rate_constants_NONE , PR_V111 , //!< Reaction 111: RUBP+O2<-->PGlycolate + PGA PR_V112 , //!< Reaction 112: PGlycolate-->Pi+Glycolate; PR_V113 , //!< Reaction 113: Gcea+ATP<-->ADP + PGA @@ -82,9 +87,11 @@ enum PR_rate_constants { PR_Vf_T121 , //!< VfactorT used with GRNT & Tp > 25 PR_Vf_T122 , //!< VfactorT used with GRNT & Tp > 25 PR_Vf_T112 , //!< VfactorT used with GRNT & Tp > 25 + PR_rate_constants_MAX , }; enum BF_rate_constants { + BF_rate_constants_NONE , BF_K1 , //!< The rate constant for formation of ISP.QH2 complex; unit: per second BF_K2 , //!< The rate constant for ISP.QH2-->QH(semi) + ISPH(red) ; unit: per second BF_K3 , //!< The rate constant for QH. + cytbL --> Q + cytbL- + H+ Unit: s-1 @@ -132,9 +139,11 @@ enum BF_rate_constants { BF_k12 , //!< The total concentration of buffer in lumen; unit: mmol per liter BF_k23 , //!< The total number of P700; unit: micromole m-2 leaf area BF_k30 , //!< The total concentration of NADPH in stroma; 1 is an guessed value; + BF_rate_constants_MAX , }; enum RROEA_rate_constants { + RROEA_rate_constants_NONE , RROEA_ke2GAPDH , //!< The rate constant of electron transfer to GAPDH. From literature. RROEA_ke2MDH , //!< The rate constant of electront transfer to MDH, this rate is totally ASSUMED. RROEA_ke2FBPase , //!< The rate constant of electron transfer from thioredoxin to FBPase. @@ -171,9 +180,11 @@ enum RROEA_rate_constants { RROEA_FdT , //!< Not used with RROEA_EPS RROEA_ThioT , RROEA_RuACTT , + RROEA_rate_constants_MAX , }; enum SUCS_rate_constants { + SUCS_rate_constants_NONE , SUCS_V51 , //!< DHAP+GAP --FBP; default 0.5 SUCS_V52 , //!< FBP --F6P + Pi SUCS_V55 , //!< G1P+UTP --OPOP+UDPG @@ -225,16 +236,20 @@ enum SUCS_rate_constants { SUCS_KE59 , SUCS_KE61 , SUCS_Km621 , + SUCS_rate_constants_MAX , }; enum XanCycle_rate_constants { + XanCycle_rate_constants_NONE , XanCycle_kva , //!< Ruth Frommolt et a; 2001; Planta XanCycle_kaz , //!< Ruth Frommolt et a; 2001; Planta XanCycle_kza , //!< Ruth Frommolt et a; 2001; Planta XanCycle_kav , //!< Ruth Frommolt et a; 2001; Planta. This is not given in the paper. Therefore, teh value is really an educated guess. + XanCycle_rate_constants_MAX , }; enum FI_rate_constants { + FI_rate_constants_NONE , FI_kA_d , //!< The rate constant of heat dissipation from peripheral antenna Lazar (1999), 0.25~1 *10^(9) FI_kA_f , //!< The rate constant of fluorescence emission from peripheral antenna Lazar 1999, with a lifetime of 5 ns at closed reaction center FI_kA_U , //!< The rate constant of exciton transfer from periphral antenna to core antenna Reference needed, a guess @@ -258,9 +273,11 @@ enum FI_rate_constants { FI_k_pq_oxy , //!< The rate constant of the PQH2 oxidation Lazar (1999),50~500 FI_QBt , //!< The total concentration of Qb site; FI_PQT , //!< The total concentration of PQ; + FI_rate_constants_MAX , }; enum PS_rate_constants { + PS_rate_constants_NONE , PS_CP , //!< Global constant for the total phosphate PS_CA , //!< Global constant for the total adenylates PS_CN , //!< Global constant for the cytosolic Phosphate concentration; @@ -373,5 +390,6 @@ enum PS_rate_constants { PS_Vf_T9 , //!< VfactorT used with GRNT & Tp > 25 PS_Vf_T13 , //!< VfactorT used with GRNT & Tp > 25 PS_Vf_T23 , //!< VfactorT used with GRNT & Tp > 25 + PS_rate_constants_MAX , }; diff --git a/include/enums/enums_utils.hpp b/include/enums/enums_utils.hpp index 86aa19c..3375944 100644 --- a/include/enums/enums_utils.hpp +++ b/include/enums/enums_utils.hpp @@ -18,6 +18,11 @@ const std::map& get_enum_map() { return out; } +template +MODULE get_enum_module() { + return MODULE_NONE; +} + namespace ePhotosynthesis { namespace utils { @@ -44,8 +49,8 @@ namespace ePhotosynthesis { } template - void readEnumFile(const std::string &filename, - std::map &map) { + std::map readEnumFile(const std::string &filename) { + std::map map; std::vector tempVec; std::string comment = "#"; std::string input; @@ -67,7 +72,7 @@ namespace ePhotosynthesis { count++; map.insert(std::pair(key, val)); } - + return map; } template diff --git a/src/enums/enums_conditions_map.cpp b/src/enums/enums_conditions_map.cpp index 34e1a77..feefa4d 100644 --- a/src/enums/enums_conditions_map.cpp +++ b/src/enums/enums_conditions_map.cpp @@ -21,6 +21,9 @@ const std::map& PR_conditions_map() { template<> const std::map& get_enum_map() { return PR_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_PR; +} const std::map& PS_conditions_map() { static const std::map map { @@ -42,6 +45,9 @@ const std::map& PS_conditions_map() { template<> const std::map& get_enum_map() { return PS_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_PS; +} const std::map& RedoxReg_conditions_map() { static const std::map map { @@ -56,6 +62,9 @@ const std::map& RedoxReg_condition template<> const std::map& get_enum_map() { return RedoxReg_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_RedoxReg; +} const std::map& FI_conditions_map() { static const std::map map { @@ -87,6 +96,9 @@ const std::map& FI_conditions_map() { template<> const std::map& get_enum_map() { return FI_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_FI; +} const std::map& RuACT_conditions_map() { static const std::map map { @@ -100,6 +112,9 @@ const std::map& RuACT_conditions_map( template<> const std::map& get_enum_map() { return RuACT_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_RuACT; +} const std::map& XanCycle_conditions_map() { static const std::map map { @@ -113,6 +128,9 @@ const std::map& XanCycle_condition template<> const std::map& get_enum_map() { return XanCycle_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_XanCycle; +} const std::map& SUCS_conditions_map() { static const std::map map { @@ -130,6 +148,9 @@ const std::map& SUCS_conditions_map() template<> const std::map& get_enum_map() { return SUCS_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_SUCS; +} const std::map& BF_conditions_map() { static const std::map map { @@ -168,6 +189,9 @@ const std::map& BF_conditions_map() { template<> const std::map& get_enum_map() { return BF_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_BF; +} const std::map& RROEA_conditions_map() { static const std::map map { @@ -181,4 +205,7 @@ const std::map& RROEA_conditions_map( template<> const std::map& get_enum_map() { return RROEA_conditions_map(); }; +template<> MODULE get_enum_module() { + return MODULE_RROEA; +} diff --git a/src/enums/enums_rate_constants_map.cpp b/src/enums/enums_rate_constants_map.cpp index 9c00ccd..a4bcd79 100644 --- a/src/enums/enums_rate_constants_map.cpp +++ b/src/enums/enums_rate_constants_map.cpp @@ -25,6 +25,9 @@ const std::map& RuACT_rate_consta template<> const std::map& get_enum_map() { return RuACT_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_RuACT; +} const std::map& RedoxReg_rate_constants_map() { static const std::map map { @@ -38,6 +41,9 @@ const std::map& RedoxReg_rate_ template<> const std::map& get_enum_map() { return RedoxReg_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_RedoxReg; +} const std::map& PR_rate_constants_map() { static const std::map map { @@ -104,6 +110,9 @@ const std::map& PR_rate_constants_ma template<> const std::map& get_enum_map() { return PR_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_PR; +} const std::map& BF_rate_constants_map() { static const std::map map { @@ -160,6 +169,9 @@ const std::map& BF_rate_constants_ma template<> const std::map& get_enum_map() { return BF_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_BF; +} const std::map& RROEA_rate_constants_map() { static const std::map map { @@ -205,6 +217,9 @@ const std::map& RROEA_rate_consta template<> const std::map& get_enum_map() { return RROEA_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_RROEA; +} const std::map& SUCS_rate_constants_map() { static const std::map map { @@ -265,6 +280,9 @@ const std::map& SUCS_rate_constant template<> const std::map& get_enum_map() { return SUCS_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_SUCS; +} const std::map& XanCycle_rate_constants_map() { static const std::map map { @@ -278,6 +296,9 @@ const std::map& XanCycle_rate_ template<> const std::map& get_enum_map() { return XanCycle_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_XanCycle; +} const std::map& FI_rate_constants_map() { static const std::map map { @@ -310,6 +331,9 @@ const std::map& FI_rate_constants_ma template<> const std::map& get_enum_map() { return FI_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_FI; +} const std::map& PS_rate_constants_map() { static const std::map map { @@ -431,4 +455,7 @@ const std::map& PS_rate_constants_ma template<> const std::map& get_enum_map() { return PS_rate_constants_map(); }; +template<> MODULE get_enum_module() { + return MODULE_PS; +} diff --git a/src/enums/enums_utils.cpp b/src/enums/enums_utils.cpp index 3c5cade..d9e15bd 100644 --- a/src/enums/enums_utils.cpp +++ b/src/enums/enums_utils.cpp @@ -16,3 +16,8 @@ std::string ePhotosynthesis::utils::str_tolower(const std::string& inStr) { [](unsigned char c) { return std::tolower(c); }); return outStr; } + +template<> const std::map& get_enum_map() { + static const std::map map; + return map; +}; diff --git a/utils/generate_enum.py b/utils/generate_enum.py index 81044b9..17f3f69 100644 --- a/utils/generate_enum.py +++ b/utils/generate_enum.py @@ -116,10 +116,13 @@ def parse_lines(self, lines, **kwargs): raise NotImplementedError def prefix_by_split(self, split): + out = {} for k, v in self.param.items(): prefix = k.split(split, 1)[0] - for x in v: - x['name'] = prefix + x['name'] + out[k] = [prefix] + # for x in v: + # x['name'] = prefix + x['name'] + return out class EnumGeneratorBase(EnumBase): @@ -214,25 +217,35 @@ def perfile_options_keys(cls): v.get('dest', k) for k, v in cls.perfile_options.items()] @classmethod - def all_children(cls): - out = [v.name for v in cls.added_file_classes.values()] + def all_children(cls, return_classes=False): + if return_classes: + out = list(cls.added_file_classes.values()) + else: + out = [v.name for v in cls.added_file_classes.values()] for v in cls.added_file_classes.values(): - out += v.all_children() + out += v.all_children(return_classes=return_classes) return out @classmethod def extract_child_kws(cls, kwargs, child_kws, **kws_all): + kwargs_orig = dict(kwargs) out = child_kws kws_all.update(**child_kws.pop('all', {})) - for x in cls.all_children(): + for xcls in cls.all_children(return_classes=True): + x = xcls.name out.setdefault(x, {}) - for k in cls.perfile_options_keys(): + for k in xcls.perfile_options_keys(): key = f"{k}_{x}" if key in kwargs: if k == 'kwargs': out[x].update(**kwargs.pop(key)) else: out[x][k] = kwargs.pop(key) + elif key in kwargs_orig: + if k == 'kwargs': + out[x].update(**kwargs_orig[key]) + else: + out[x][k] = kwargs_orig[key] kws_all = dict(kwargs, **kws_all) for x in cls.all_children(): out[x] = dict(kws_all, **out[x]) @@ -266,17 +279,30 @@ def write(self, verbose=False, overwrite=False, dry_run=False, with open(self.dst, 'w') as fd: fd.write(contents) - def add_member(self, member): + def max_width(self, members): + width = len(self.add_member( + max(members, key=lambda x: + len(self.add_member(x, return_name=True))), + return_name=True)) + return width + + def add_member(self, member, return_name=False): assert self.current_key is not None - member.setdefault('abbr', member['name']) - member['name'] = self._current_keys['kreplacement'].get( - member['name'], member['name']) + name = member['name'] + abbr = member.get('abbr', name) + name = self._current_keys['kreplacement'].get( + name, name) if self._current_keys['klower']: - member['name'] = member['name'].lower() - for x in self._current_keys['ksuffix']: - member['name'] = member['name'] + x - for x in self._current_keys['kprefix']: - member['name'] = x + member['name'] + name = name.lower() + if not member.get('no_suffix', False): + for x in self._current_keys['ksuffix']: + name = name + x + if not member.get('no_prefix', False): + for x in self._current_keys['kprefix']: + name = x + name + if return_name: + return name + return dict(member, name=name, abbr=abbr) def generate_member(self, x, **kwargs): raise NotImplementedError @@ -286,7 +312,7 @@ def generate_item(self, name, members, **kwargs): for x in members: if x['name'] in self.skip_items.get(name, []): continue - self.add_member(x) + x = self.add_member(x) lines += self.generate_member(x, **kwargs) return lines @@ -501,7 +527,7 @@ def generate_item(self, name, members, tname=None, in_header=False): "", f" static const std::map map {{" ] - width = len(max(members, key=lambda x: len(x['name']))['name']) + width = self.max_width(members) width_abbr = len(max(members, key=lambda x: len(x['abbr']))['abbr']) lines += super(CEnumGeneratorMapSource, self).generate_item( name, members, width=width, width_abbr=width_abbr) @@ -511,6 +537,9 @@ def generate_item(self, name, members, tname=None, in_header=False): f"const std::string>& get_enum_map() {{", f" return {func_name}();", "};", + f"template<> MODULE get_enum_module() {{", + f" return MODULE_{name.split('_')[0]};", + "}", "" ] return lines @@ -527,24 +556,64 @@ class CEnumGeneratorGlobalHeader(CEnumGeneratorBase): name = 'global' file_suffix = '' explicit_dst = True + perfile_options = dict( + CEnumGeneratorBase.perfile_options, + enum_name={ + 'type': str, + 'help': "Name that should be used for the global enum", + }, + ) def __init__(self, *args, **kwargs): + self.enum_name = kwargs.pop('enum_name', None) + if self.enum_name is None: + self.enum_name = self.name.upper() kwargs.setdefault("append_unique", True) super(CEnumGeneratorGlobalHeader, self).__init__(*args, **kwargs) assert self.parent + def generate_item(self, name, members, width=None): + assert width + if self._current_keys['kprefix']: + name = ''.join(self._current_keys['kprefix'][::-1]).rstrip('_') + key = f"{self.enum_name}_{name}" + return [f"{key:{width}},"] + def generate(self, indent='', **kwargs): - return self.parent.include_self( + lines = [] + lines += self.parent.include_self( self.dst, rootdir=self.root_include_dir) + def key_len(x): + return len(''.join(self.prefixes.get(x, [x]))) + + width = ( + key_len(max(self.src.param.keys(), key=key_len)) + + len(self.enum_name) + 1) + first = f'{self.enum_name}_NONE' + last = f'{self.enum_name}_MAX' + lines += [ + f'enum {self.enum_name} {{', + f' {first:{width}},', + ] + indent += ' ' + lines += super(CEnumGeneratorGlobalHeader, self).generate( + indent=indent, width=width, **kwargs) + lines += [ + f' {last:{width}},', + "};", + "" + ] + return lines + class CEnumGeneratorHeader(CEnumGeneratorBase): name = 'c' file_suffix = '_enum' added_file_classes = { - 'maps': CEnumGeneratorMapSource, 'global': CEnumGeneratorGlobalHeader, + 'maps': CEnumGeneratorMapSource, } def __init__(self, *args, **kwargs): @@ -566,11 +635,19 @@ def generate_member(self, x, width=None, width_val=None): def generate_item(self, name, members): lines = [] lines += [ - f"enum {name} {{" + f"enum {name} {{", ] - width = len(max(members, key=lambda x: len(x['name']))['name']) + width = self.max_width(members) width_val = len(max(members, key=lambda x: len(x.get('val', ''))).get('val', '')) + 3 + first = f"{name}_NONE" + last = f"{name}_MAX" + if members[0]['name'] != first: + members.insert(0, {'name': first, 'abbr': first, + 'no_prefix': True}) + if members[-1]['name'] != last: + members.append({'name': last, 'abbr': last, + 'no_prefix': True}) lines += super(CEnumGeneratorHeader, self).generate_item( name, members, width=width, width_val=width_val) lines += [ @@ -779,7 +856,7 @@ def generate_item(self, name, members): def rename_source(directory, src_suffix, dst_suffix, ext): import shutil src_regex = os.path.join(directory, f"*_{src_suffix}{ext}") - files = glob.glob(src_regex) + files = sorted(glob.glob(src_regex)) if not files: raise Exception(f"No files found matching {src_regex}") for src in files: @@ -837,9 +914,9 @@ def rename_source(directory, src_suffix, dst_suffix, ext): else: src = get_registered_class('parser', args.src_type)( args.src, verbose=args.verbose, is_regex=args.src_regex) - if args.prefix_by_split: - src.prefix_by_split(args.prefix_by_split) kws = {} + if args.prefix_by_split: + kws['prefixes'] = src.prefix_by_split(args.prefix_by_split) for x in registered_classes('generator', return_classes=True): x.get_arguments(args, kws) dst = get_registered_class('generator', args.dst_type)(