Debian Codegraph @

ansible_collections/community/dns/noxfile.py

raw
1 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 # SPDX-FileCopyrightText: 2025 Felix Fontein <[email protected]>
4
5 # /// script
6 # dependencies = ["nox>=2025.02.09", "antsibull-nox"]
7 # ///
8
9 from __future__ import annotations
10
11 import os
12 import sys
13 import urllib.request
14 from pathlib import Path
15
16 import nox
17
18 try:
19 import antsibull_nox
20 import antsibull_nox.sessions
21 except ImportError:
22 print("You need to install antsibull-nox in the same Python environment as nox.")
23 sys.exit(1)
24
25
26 IN_CI = os.environ.get("CI") == "true"
27
28
29 antsibull_nox.load_antsibull_nox_toml()
30
31
32 @nox.session(name="update-docs-fragments", default=True)
33 def update_docs_fragments(session: nox.Session) -> None:
34 """
35 Update/check auto-generated parts of docs fragments.
36 """
37 session.install("ansible-core")
38 prepare = antsibull_nox.sessions.prepare_collections(
39 session, install_in_site_packages=True
40 )
41 if not prepare:
42 return
43 data = ["python", "tests/update-docs-fragments.py"]
44 if IN_CI:
45 data.append("--lint")
46 session.run(*data)
47
48
49 @nox.session(name="update-psl", default=False, python=False)
50 def update_psl(session: nox.Session) -> None:
51 # Sometimes the version on publicsuffix.org differs depending on from where you request it over many hours,
52 # so for now let's directly fetch it from GitHub.
53 # url = 'https://publicsuffix.org/list/public_suffix_list.dat'
54 url = "https://raw.githubusercontent.com/publicsuffix/list/main/public_suffix_list.dat"
55 filename = "plugins/public_suffix_list.dat"
56
57 # Download file
58 urllib.request.urlretrieve(url, filename)
59
60 output = session.run("git", "status", "--porcelain=v1", filename, silent=True)
61 if output is None:
62 # The run was skipped
63 return
64 if output == "":
65 print("PSL is up-to-date!")
66 return
67
68 if IN_CI:
69 session.error("PSL is not up-to-date! Run 'nox -e update-psl'!")
70 return
71
72 fragment = Path("changelogs", "fragments", "update-psl.yml")
73 if not fragment.exists():
74 fragment.write_text(r"""bugfixes:
75 - "Update Public Suffix List."
76 """)
77
78 session.run("git", "status", filename, fragment)
79
80
81 # Allow to run the noxfile with `python noxfile.py`, `pipx run noxfile.py`, or similar.
82 # Requires nox >= 2025.02.09
83 if __name__ == "__main__":
84 nox.main()