|
13 | 13 | # All configuration values have a default; values that are commented out |
14 | 14 | # serve to show the default. |
15 | 15 |
|
16 | | -import re |
17 | 16 | import sys |
18 | 17 | import time |
19 | 18 | from importlib.metadata import version |
20 | 19 | from pathlib import Path |
21 | 20 |
|
22 | | -import yaml |
23 | | - |
24 | 21 | # Attempt to import the version dynamically from GitHub tag. |
25 | 22 | try: |
26 | 23 | fullversion = version("diffpy.cmi") |
|
325 | 322 |
|
326 | 323 | # Example configuration for intersphinx: refer to the Python standard library. |
327 | 324 | # intersphinx_mapping = {'http://docs.python.org/': None} |
328 | | - |
329 | | - |
330 | | -def generate_available_packs_rst(): |
331 | | - """Generate or update docs/source/available-packs.rst with pack |
332 | | - dependencies.""" |
333 | | - root = Path(__file__).parent.parent.parent |
334 | | - packs_dir = root / "requirements" / "packs" |
335 | | - source_dir = root / "docs" / "source" |
336 | | - cmi_rst = source_dir / "available-packs.rst" |
337 | | - |
338 | | - header = """Packs |
339 | | ------ |
340 | | -
|
341 | | -This page lists the dependencies required by each ``diffpy.cmi`` pack. |
342 | | -
|
343 | | -""" |
344 | | - pack_files = sorted(packs_dir.glob("*.txt")) |
345 | | - if cmi_rst.exists(): |
346 | | - content = cmi_rst.read_text() |
347 | | - existing_packs = set( |
348 | | - re.findall( |
349 | | - r"^=+\n([A-Za-z0-9_\-]+)\n=+", content, flags=re.MULTILINE |
350 | | - ) |
351 | | - ) |
352 | | - else: |
353 | | - cmi_rst.write_text(header) |
354 | | - content = header |
355 | | - existing_packs = set() |
356 | | - new_sections = [] |
357 | | - for pack_file in pack_files: |
358 | | - pack_name = pack_file.stem |
359 | | - if pack_name in existing_packs: |
360 | | - continue |
361 | | - dependencies = [ |
362 | | - line.strip() |
363 | | - for line in pack_file.read_text().splitlines() |
364 | | - if line.strip() |
365 | | - ] |
366 | | - if dependencies: |
367 | | - deps_list = "\n".join(f"- ``{dep}``" for dep in dependencies) |
368 | | - else: |
369 | | - deps_list = "_No dependencies listed._" |
370 | | - underline = "=" * len(pack_name) |
371 | | - section = f"""\n{underline} |
372 | | -{pack_name} |
373 | | -{underline} |
374 | | -{deps_list} |
375 | | -
|
376 | | -""" |
377 | | - new_sections.append(section) |
378 | | - if new_sections: |
379 | | - with open(cmi_rst, "a") as f: |
380 | | - f.writelines(new_sections) |
381 | | - print(f"Appended {len(new_sections)} new pack(s) to {cmi_rst}") |
382 | | - else: |
383 | | - print("No new packs found. available-packs.rst is up to date.") |
384 | | - |
385 | | - |
386 | | -generate_available_packs_rst() |
387 | | - |
388 | | - |
389 | | -def generate_available_profiles_rst(): |
390 | | - """Generate or update docs/source/available-profiles.rst listing all |
391 | | - profiles. |
392 | | -
|
393 | | - - If available-profiles.rst doesn't exist: create it with all profiles |
394 | | - listed. |
395 | | - - If it exists: append only new profiles (those not already present). |
396 | | - """ |
397 | | - root = Path(__file__).parent.parent.parent |
398 | | - profiles_dir = root / "requirements" / "profiles" |
399 | | - source_dir = root / "docs" / "source" |
400 | | - rst_file = source_dir / "available-profiles.rst" |
401 | | - |
402 | | - header = """Profiles |
403 | | --------- |
404 | | -
|
405 | | -This page lists the packs and extra dependencies |
406 | | -required by each ``diffpy.cmi`` profile. |
407 | | -
|
408 | | -""" |
409 | | - source_dir.mkdir(parents=True, exist_ok=True) |
410 | | - if rst_file.exists(): |
411 | | - content = rst_file.read_text() |
412 | | - existing_profiles = set( |
413 | | - re.findall( |
414 | | - r"^=+\n([A-Za-z0-9_\-]+)\n=+", content, flags=re.MULTILINE |
415 | | - ) |
416 | | - ) |
417 | | - else: |
418 | | - rst_file.write_text(header) |
419 | | - content = header |
420 | | - existing_profiles = set() |
421 | | - profile_files = sorted(profiles_dir.glob("*.yml")) |
422 | | - new_sections = [] |
423 | | - for profile_file in profile_files: |
424 | | - profile_name = profile_file.stem |
425 | | - if profile_name in existing_profiles: |
426 | | - continue # skip existing profiles |
427 | | - data = yaml.safe_load(profile_file.read_text()) |
428 | | - packs = data.get("packs", []) |
429 | | - extras = data.get("extras", []) |
430 | | - packs_str = ( |
431 | | - ", ".join(f"``{pack}``" for pack in packs) |
432 | | - if packs |
433 | | - else "_No packs listed_" |
434 | | - ) |
435 | | - extras_str = ( |
436 | | - ", ".join(f"``{extra}``" for extra in extras) |
437 | | - if extras |
438 | | - else "_No extras listed_" |
439 | | - ) |
440 | | - underline = "=" * len(profile_name) |
441 | | - section = f"""\n{underline} |
442 | | -{profile_name} |
443 | | -{underline} |
444 | | -
|
445 | | -packs: {packs_str} |
446 | | -
|
447 | | -extras: {extras_str} |
448 | | -
|
449 | | -""" |
450 | | - new_sections.append(section) |
451 | | - if new_sections: |
452 | | - with open(rst_file, "a") as f: |
453 | | - f.writelines(new_sections) |
454 | | - print(f"Appended {len(new_sections)} new profile(s) to {rst_file}") |
455 | | - else: |
456 | | - print("No new profiles found. available-profiles.rst is up to date.") |
457 | | - |
458 | | - |
459 | | -generate_available_profiles_rst() |
0 commit comments