Skip to content

Commit 9c9cf05

Browse files
committed
Special check overlays for Py2
Will be automatically filled with <id>: enabled: false compatible: false for Python 2 incompatible plugins on page build, unless `id` is already present in the data (in case of more specific overlays). That way plugins will no longer prompt to update to Python 3 only versions if running on Python 2 (starting with OctoPrint 1.6.0). Alternatively, plugin authors could rewrite the update URL in such cases, e.g. to still be notified of security updates from a legacy fork.
1 parent 403481c commit 9c9cf05

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import concurrent.futures
2+
import os
3+
import sys
4+
5+
import frontmatter
6+
import pkg_resources
7+
import yaml
8+
9+
10+
def process_plugin_file(path):
11+
output = []
12+
13+
def out(line, prefix="", *args, **kwargs):
14+
output.append("{}{}".format(prefix, line))
15+
16+
overlay = {}
17+
18+
data = frontmatter.load(path)
19+
plugin_id = data["id"]
20+
21+
out("Processing plugin {} at path {}".format(plugin_id, path))
22+
23+
if data.get("compatibility", {}).get("python"):
24+
pycompat = data["compatibility"]["python"]
25+
s = pkg_resources.Requirement.parse("Python" + pycompat)
26+
if "2.7" not in s:
27+
out(
28+
"Plugin {} is not Python 2 compatible, disable update checks in the field".format(
29+
plugin_id
30+
)
31+
)
32+
overlay = {plugin_id: {"enabled": False, "compatible": False}}
33+
34+
return "\n".join(output), overlay
35+
36+
37+
if __name__ == "__main__":
38+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
39+
40+
filtered = None
41+
if len(sys.argv) > 1:
42+
filtered = sys.argv[1:]
43+
44+
futures_to_name = dict()
45+
46+
overlays_path = os.path.join(
47+
os.path.dirname(os.path.abspath(__file__)),
48+
"..",
49+
"..",
50+
"_data",
51+
"update_check_overlays_py2.yaml",
52+
)
53+
with open(overlays_path, "r") as f:
54+
data = yaml.safe_load(f)
55+
assert isinstance(data, dict)
56+
57+
plugin_dir = os.path.join(
58+
os.path.dirname(os.path.abspath(__file__)), "..", "..", "_plugins"
59+
)
60+
with os.scandir(plugin_dir) as it:
61+
for entry in it:
62+
if not entry.is_file() or not entry.name.endswith(".md"):
63+
continue
64+
if filtered and entry.name[:-3] not in filtered:
65+
continue
66+
if entry.name[:-3] in data:
67+
continue
68+
future = executor.submit(process_plugin_file, entry.path)
69+
futures_to_name[future] = entry.name
70+
71+
overlays = {}
72+
for future in concurrent.futures.as_completed(futures_to_name):
73+
name = futures_to_name[future]
74+
try:
75+
output, result = future.result()
76+
overlays.update(result)
77+
78+
print(output)
79+
print("")
80+
except Exception as exc:
81+
print("{} generated an exception: {}".format(name, exc))
82+
83+
if overlays:
84+
# there were overlays added, write them to the data file now
85+
print("Adding {} new overlays to {}...".format(len(overlays), overlays_path))
86+
87+
data.update(overlays)
88+
with open(overlays_path, "w") as f:
89+
yaml.safe_dump(data, f)
90+
91+
print("Overlays added.")

.github/workflows/publish-to-github-pages.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ jobs:
5959
env:
6060
GITHUB_TOKEN: ${{ secrets.metadata_token }}
6161

62+
- name: 🏗 Enrich py2 check overlays
63+
if: github.repository == 'OctoPrint/plugins.octoprint.org' && github.event_name != 'pull_request'
64+
run: |
65+
python ./src/.github/scripts/populate_py2_overlays.py
66+
6267
- name: 📦 Cache jekyll build bundle
6368
uses: actions/cache@v2
6469
with:

_data/update_check_overlays_py2.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Update check overlays for Python 2 instances specifically. Format:
2+
#
3+
# pluginID:
4+
# user: new github user
5+
# repo: new github repo
6+
# pip: new pip URL
7+
# ...
8+
#
9+
# Any keys from the software update config can be overwritten, changing the default values. config.yaml on the
10+
# instances out there still wins though, in case the user has a personal override configured.
11+
{}

update_check_overlay_py2.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: null
3+
---
4+
{{ site.data.update_check_overlays_py2 | jsonify }}

0 commit comments

Comments
 (0)