|
8 | 8 | try: |
9 | 9 | from urllib.request import urlopen, Request |
10 | 10 | except ImportError: |
| 11 | + # For Python 2 compatibility |
11 | 12 | from urllib2 import urlopen, Request |
12 | 13 |
|
| 14 | +LABELS = { |
| 15 | + "chemdyg": "chemdyg_dev", |
| 16 | + "e3sm_diags": "e3sm_diags_dev", |
| 17 | + "e3sm_to_cmip": "e3sm_to_cmip_dev", |
| 18 | + "mache": "mache_dev", |
| 19 | + "moab": "moab_dev", |
| 20 | + "mpas-analysis": "mpas_analysis_dev", |
| 21 | + "mpas_tools": "mpas_tools_dev", |
| 22 | + "nco": "nco_dev", |
| 23 | + "xcdat": "xcdat_dev", |
| 24 | + "zppy": "zppy_dev", |
| 25 | + "zstash": "zstash_dev", |
| 26 | +} |
| 27 | + |
13 | 28 |
|
14 | 29 | def parse_args(bootstrap): |
15 | 30 | parser = argparse.ArgumentParser( |
16 | 31 | description='Deploy E3SM-Unified') |
17 | | - parser.add_argument("--version", dest="version", default="1.11.1", |
| 32 | + parser.add_argument("--version", dest="version", |
18 | 33 | help="The version of E3SM-Unified to deploy") |
19 | 34 | parser.add_argument("--conda", dest="conda_base", |
20 | 35 | help="Path for the conda base") |
@@ -56,6 +71,16 @@ def parse_args(bootstrap): |
56 | 71 | raise ValueError('You must supply both or neither of ' |
57 | 72 | '--mache_fork and --mache_branch') |
58 | 73 |
|
| 74 | + if args.version is None: |
| 75 | + meta_yaml_path = os.path.join( |
| 76 | + os.path.dirname(__file__), |
| 77 | + "..", |
| 78 | + "recipes", |
| 79 | + "e3sm-unified", |
| 80 | + "meta.yaml" |
| 81 | + ) |
| 82 | + args.version = get_version_from_meta(meta_yaml_path) |
| 83 | + |
59 | 84 | return args |
60 | 85 |
|
61 | 86 |
|
@@ -125,3 +150,64 @@ def get_conda_base(conda_base, config, shared): |
125 | 150 | # handle "~" in the path |
126 | 151 | conda_base = os.path.abspath(os.path.expanduser(conda_base)) |
127 | 152 | return conda_base |
| 153 | + |
| 154 | + |
| 155 | +def get_rc_dev_labels(meta_yaml_path): |
| 156 | + """Parse meta.yaml and return a list of dev labels for RC dependencies.""" |
| 157 | + |
| 158 | + # a rare case where module-level imports are not a good idea because |
| 159 | + # the deploy_e3sm_unified.py script may be called from an environment |
| 160 | + # where jinja2 and yaml are not installed. |
| 161 | + import yaml |
| 162 | + from jinja2 import Template |
| 163 | + |
| 164 | + labels_dict = LABELS |
| 165 | + |
| 166 | + # Render the jinja template with dummy/default values |
| 167 | + with open(meta_yaml_path) as f: |
| 168 | + template_text = f.read() |
| 169 | + # Provide dummy/default values for all jinja variables used in meta.yaml |
| 170 | + template = Template(template_text) |
| 171 | + rendered = template.render( |
| 172 | + mpi='mpich', # or any valid value |
| 173 | + py='310', # or any valid value |
| 174 | + CONDA_PY='310', # used in build string |
| 175 | + ) |
| 176 | + meta = yaml.safe_load(rendered) |
| 177 | + dev_labels = [] |
| 178 | + run_reqs = meta.get("requirements", {}).get("run", []) |
| 179 | + for req in run_reqs: |
| 180 | + # req can be a string like "pkgname version" or just "pkgname" |
| 181 | + if isinstance(req, str): |
| 182 | + parts = req.split() |
| 183 | + pkg = parts[0] |
| 184 | + version = " ".join(parts[1:]) if len(parts) > 1 else "" |
| 185 | + |
| 186 | + # NCO is special: it has a dev label for alpha/beta versions |
| 187 | + if pkg == "nco" and ('alpha' in version or 'beta' in version): |
| 188 | + label = labels_dict[pkg] |
| 189 | + if label not in dev_labels: |
| 190 | + dev_labels.append(label) |
| 191 | + |
| 192 | + # Only match 'rc' in version, not in pkg name |
| 193 | + if "rc" in version and pkg in labels_dict: |
| 194 | + label = labels_dict[pkg] |
| 195 | + if label not in dev_labels: |
| 196 | + dev_labels.append(label) |
| 197 | + return dev_labels |
| 198 | + |
| 199 | + |
| 200 | +def get_version_from_meta(meta_yaml_path): |
| 201 | + """Parse the version from the {% set version = ... %} line in meta.yaml.""" |
| 202 | + with open(meta_yaml_path) as f: |
| 203 | + for line in f: |
| 204 | + if line.strip().startswith("{% set version"): |
| 205 | + # e.g., {% set version = "1.11.1rc1" %} |
| 206 | + parts = line.split("=") |
| 207 | + if len(parts) >= 2: |
| 208 | + version = ( |
| 209 | + parts[1].strip().strip('%}').strip().strip( |
| 210 | + '"').strip("'") |
| 211 | + ) |
| 212 | + return version |
| 213 | + raise ValueError("Could not find version in meta.yaml") |
0 commit comments