MCPcopy Index your code
hub / github.com/praw-dev/praw / main

Function main

tools/set_active_docs.py:33–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31
32
33def main():
34 content = pathlib.Path(f"{PROJECT}/const.py").read_text()
35 current_version = packaging.version.parse(re.search(r'__version__ = "([^"]+)"', content).group(1))
36 if current_version.is_devrelease:
37 current_version = packaging.version.parse(
38 f"{current_version.major}.{current_version.minor}.{current_version.micro - 1}"
39 )
40 max_retry_count = 5
41 retry_count = 0
42 while True:
43 # Versions are not active by default; activate the version once Read
44 # the Docs has synced the tag.
45 response = requests.patch(
46 f"https://readthedocs.org/api/v3/projects/{PROJECT}/versions/v{current_version}/",
47 headers=HEADERS,
48 json={"active": True, "hidden": False},
49 )
50 if response.status_code == 204:
51 sys.stdout.write(f"Version {current_version!s} is active\n")
52 versions = fetch_versions()
53 if versions is None:
54 return 1
55 if current_version in versions:
56 break
57 if retry_count >= max_retry_count:
58 sys.stderr.write(f"Current version {current_version!s} failed to activate\n")
59 return 1
60 sys.stdout.write("Waiting 30 seconds for version to activate\n")
61 retry_count += 1
62 time.sleep(30)
63 aggregated_versions = {}
64 for version in versions:
65 aggregated_versions.setdefault(version.major, [])
66 aggregated_versions[version.major].append(version)
67
68 latest_major_versions = [max(aggregated_versions[major]) for major in aggregated_versions]
69 major_versions = [version.major for version in versions]
70 is_new_major = major_versions.count(current_version.major) == 1
71
72 for version in versions:
73 if (is_new_major and version not in latest_major_versions) or (
74 (version.major, version.minor)
75 == (
76 current_version.major,
77 current_version.minor,
78 )
79 and version.micro != current_version.micro
80 ):
81 response = requests.patch(
82 f"https://readthedocs.org/api/v3/projects/{PROJECT}/versions/v{version}/",
83 headers=HEADERS,
84 json={"active": True, "hidden": True},
85 )
86 if response.status_code == 204:
87 sys.stderr.write(f"Version {version!s} was hidden successfully\n")
88 else:
89 sys.stderr.write(f"Failed to hide version {version!s}\n")
90 return 1

Callers 1

set_active_docs.pyFile · 0.70

Calls 4

fetch_versionsFunction · 0.85
patchMethod · 0.80
parseMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…