44"""
55
66import sys
7- from enum import Enum
8- from platform import system
7+ from platform import processor , system
98from typing import Tuple
109
1110_system = system ()
11+ _processor = processor ()
12+
13+ SUPPORTED_OSTAGS = ["linux" , "mac" , "macarm" , "win32" , "win64" ]
1214
1315
1416def get_modflow_ostag () -> str :
@@ -17,7 +19,7 @@ def get_modflow_ostag() -> str:
1719 elif _system == "Linux" :
1820 return "linux"
1921 elif _system == "Darwin" :
20- return "mac"
22+ return "macarm" if _processor == "arm" else " mac"
2123 else :
2224 raise NotImplementedError (f"Unsupported system: { _system } " )
2325
@@ -31,6 +33,15 @@ def get_github_ostag() -> str:
3133 raise NotImplementedError (f"Unsupported system: { _system } " )
3234
3335
36+ def get_ostag (kind : str = "modflow" ) -> str :
37+ if kind == "modflow" :
38+ return get_modflow_ostag ()
39+ elif kind == "github" :
40+ return get_github_ostag ()
41+ else :
42+ raise ValueError (f"Invalid kind: { kind } " )
43+
44+
3445def get_binary_suffixes (ostag : str = None ) -> Tuple [str , str ]:
3546 """
3647 Returns executable and library suffixes for the given OS tag, if provided,
@@ -55,10 +66,10 @@ def _suffixes(tag):
5566 return ".exe" , ".dll"
5667 elif tag == "linux" :
5768 return "" , ".so"
58- elif tag == "mac " or tag == "darwin" :
69+ elif tag == "darwin " or "mac" in tag :
5970 return "" , ".dylib"
6071 else :
61- raise KeyError (f"unrecognized OS tag: { tag !r} " )
72+ raise KeyError (f"Invalid OS tag: { tag !r} " )
6273
6374 try :
6475 return _suffixes (ostag .lower ())
@@ -89,9 +100,9 @@ def python_to_modflow_ostag(tag: str) -> str:
89100 elif tag == "Linux" :
90101 return "linux"
91102 elif tag == "Darwin" :
92- return "mac"
103+ return "macarm" if _processor == "arm" else " mac"
93104 else :
94- raise ValueError (f"Invalid or unsupported tag: { tag } " )
105+ raise ValueError (f"Invalid tag: { tag } " )
95106
96107
97108def modflow_to_python_ostag (tag : str ) -> str :
@@ -112,18 +123,18 @@ def modflow_to_python_ostag(tag: str) -> str:
112123 return "Windows"
113124 elif tag == "linux" :
114125 return "Linux"
115- elif tag == "mac" :
126+ elif "mac" in tag :
116127 return "Darwin"
117128 else :
118- raise ValueError (f"Invalid or unsupported tag: { tag } " )
129+ raise ValueError (f"Invalid tag: { tag } " )
119130
120131
121132def modflow_to_github_ostag (tag : str ) -> str :
122133 if tag == "win64" :
123134 return "Windows"
124135 elif tag == "linux" :
125136 return "Linux"
126- elif tag == "mac" :
137+ elif "mac" in tag :
127138 return "macOS"
128139 else :
129140 raise ValueError (f"Invalid modflow os tag: { tag } " )
@@ -135,7 +146,7 @@ def github_to_modflow_ostag(tag: str) -> str:
135146 elif tag == "Linux" :
136147 return "linux"
137148 elif tag == "macOS" :
138- return "mac"
149+ return "macarm" if _processor == "arm" else " mac"
139150 else :
140151 raise ValueError (f"Invalid github os tag: { tag } " )
141152
@@ -148,39 +159,18 @@ def github_to_python_ostag(tag: str) -> str:
148159 return modflow_to_python_ostag (github_to_modflow_ostag (tag ))
149160
150161
151- def get_ostag (kind : str = "modflow" ) -> str :
152- if kind == "modflow" :
153- return get_modflow_ostag ()
154- elif kind == "github" :
155- return get_github_ostag ()
162+ def convert_ostag (tag : str , mapping : str ) -> str :
163+ if mapping == "py2mf" :
164+ return python_to_modflow_ostag (tag )
165+ elif mapping == "mf2py" :
166+ return modflow_to_python_ostag (tag )
167+ elif mapping == "gh2mf" :
168+ return github_to_modflow_ostag (tag )
169+ elif mapping == "mf2gh" :
170+ return modflow_to_github_ostag (tag )
171+ elif mapping == "py2gh" :
172+ return python_to_github_ostag (tag )
173+ elif mapping == "gh2py" :
174+ return github_to_python_ostag (tag )
156175 else :
157- raise ValueError (f"Invalid kind: { kind } " )
158-
159-
160- class OSTagCvt (Enum ):
161- py2mf = "py2mf"
162- mf2py = "mf2py"
163- gh2mf = "gh2mf"
164- mf2gh = "mf2gh"
165- py2gh = "py2gh"
166- gh2py = "gh2py"
167-
168-
169- class OSTag :
170- @staticmethod
171- def convert (tag : str , cvt : str ) -> str :
172- cvt = OSTagCvt (cvt )
173- if cvt == OSTagCvt .py2mf :
174- return python_to_modflow_ostag (tag )
175- elif cvt == OSTagCvt .mf2py :
176- return modflow_to_python_ostag (tag )
177- elif cvt == OSTagCvt .gh2mf :
178- return github_to_modflow_ostag (tag )
179- elif cvt == OSTagCvt .mf2gh :
180- return modflow_to_github_ostag (tag )
181- elif cvt == OSTagCvt .py2gh :
182- return python_to_github_ostag (tag )
183- elif cvt == OSTagCvt .gh2py :
184- return github_to_python_ostag (tag )
185- else :
186- raise ValueError (f"Unsupported mapping: { cvt } " )
176+ raise ValueError (f"Invalid mapping: { mapping } " )
0 commit comments