Skip to content

Commit b3b7f70

Browse files
committed
Merge branch 'add_snippets'
2 parents 49cb42d + 1c6dc41 commit b3b7f70

167 files changed

Lines changed: 6628 additions & 6339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
4747
"remoteUser": "vscode",
4848
"features": {
49-
"powershell": "latest"
49+
"powershell": "latest",
50+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
51+
"ghcr.io/itsmechlark/features/act:1": {}
5052
}
5153
}

.github/workflows/compare_score.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import json
2+
import os
3+
4+
import requests
5+
from dotenv import load_dotenv
6+
7+
try:
8+
9+
load_dotenv() # load variables
10+
load_dotenv(".secrets") # load variables from the ".secrets" file
11+
except:
12+
pass
13+
14+
# has been propagated from repo vars to env vars
15+
try:
16+
current_scores = json.loads(os.getenv("SNIPPET_SCORE", '{"snippet_score": 0}'))
17+
except json.decoder.JSONDecodeError:
18+
current_scores = {"snippet_score": 0}
19+
20+
# set by pytest in custom conftest reporting
21+
new_scores = {}
22+
with open("results/snippet_score.json", "r") as f:
23+
new_scores = json.load(f)
24+
25+
26+
# Compare the scores and update the repository variable if necessary
27+
def add_summary(msg, current_scores: dict, new_scores: dict):
28+
if os.getenv("GITHUB_STEP_SUMMARY") is None:
29+
print(f"The environment variable GITHUB_STEP_SUMMARY does not exist.")
30+
return
31+
with open(os.getenv("GITHUB_STEP_SUMMARY", 0), "a") as f:
32+
f.write("# Snippets\n")
33+
f.write(msg)
34+
f.write("\n```json\n")
35+
json.dump({"current": new_scores}, f)
36+
f.write("\n")
37+
json.dump({"previous": current_scores}, f)
38+
f.write("\n```\n")
39+
40+
41+
42+
def update_var(var_name: str, value: str):
43+
repo = os.getenv("GITHUB_REPOSITORY", "Josverl/micropython-stubs")
44+
gh_token_vars = os.getenv("GH_TOKEN_VARS", os.getenv("GH_TOKEN", "-"))
45+
if gh_token_vars == "-":
46+
print("No token available to update the repository variable")
47+
return
48+
# update the repository variable
49+
url = f"https://api.github.com/repos/{repo}/actions/variables/{var_name}"
50+
headers = {
51+
"Authorization": f"token {gh_token_vars}",
52+
"Content-Type": "application/json",
53+
"User-Agent": "josverl",
54+
}
55+
data = {"name": str(var_name), "value": str(value)}
56+
response = requests.patch(url, headers=headers, json=data)
57+
response.raise_for_status()
58+
59+
60+
if new_scores["snippet_score"] < current_scores["snippet_score"]:
61+
msg = f"The snippet_score has decreased from {current_scores['snippet_score']} to {new_scores['snippet_score']}"
62+
print(msg)
63+
add_summary(msg, current_scores, new_scores)
64+
exit(1) # Fail the test
65+
elif new_scores["snippet_score"] == current_scores["snippet_score"]:
66+
msg = f"The snippet_score has not changed from {current_scores['snippet_score']}"
67+
print(msg)
68+
add_summary(msg, current_scores, new_scores)
69+
elif new_scores["snippet_score"] > current_scores["snippet_score"]:
70+
msg = f"The snippet_score has improved to {new_scores['snippet_score']}"
71+
print(msg)
72+
add_summary(msg, current_scores, new_scores)
73+
if os.getenv("GITHUB_REF_NAME", "main") == "main":
74+
update_var(var_name="SNIPPET_SCORE", value=json.dumps(new_scores, skipkeys=True, indent=4))
75+
76+
print("Done")
77+
exit(0)

.github/workflows/list_versions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
This module retrieves the versions of Micropython from the Micropython repository on GitHub.
3+
It is used to generate a matrix of versions to create stubs for using Github Actions.
4+
5+
It provides a function `micropython_versions` that returns a list of versions starting from a specified version.
6+
The module also includes a main block that generates a matrix of versions based on command-line arguments and environment variables.
7+
The matrix is printed as JSON and can be optionally written to a file if running in a GitHub Actions workflow.
8+
"""
9+
import json
10+
import os
11+
import sys
12+
13+
from github import Github
14+
from packaging.version import parse
15+
16+
...
117
import json
218
import os
319
import sys
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: test_stub_quality
2+
on: [push, pull_request, workflow_dispatch]
3+
4+
env:
5+
# Setting an environment variable with the value of a configuration variable
6+
SNIPPET_SCORE: ${{ vars.SNIPPET_SCORE }}
7+
GH_TOKEN_VARS: ${{ secrets.GH_TOKEN_VARS }}
8+
9+
jobs:
10+
test_snippets:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
#----------------------------------------------
15+
16+
- name: Install poetry # poetry is not in the default image
17+
run: pipx install poetry
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.11" # Replace with the Python version you're using
23+
24+
- name: Testspace client install & config
25+
uses: testspace-com/setup-testspace@v1
26+
with:
27+
domain: josverl
28+
#----------------------------------------------
29+
# install project
30+
#----------------------------------------------
31+
- name: Install dependencies for group test
32+
run: |
33+
pip install -r requirements-test.txt
34+
35+
#----------------------------------------------
36+
# stubber clone
37+
# repos needed for tests
38+
#----------------------------------------------
39+
- name: stubber clone
40+
run: stubber clone
41+
42+
43+
- name: update the stubs and test the snippets (not pushed)
44+
continue-on-error: true
45+
run: |
46+
pwsh -file ./update-stubs.ps1
47+
pytest -m 'snippets' --cache-clear --junitxml=./results/results.xml
48+
env:
49+
JUPYTER_PLATFORM_DIRS: "1"
50+
# fix: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
51+
52+
- name: Testspace push test content
53+
run: |
54+
testspace ./results/results.xml
55+
56+
- name: compare and update
57+
run: |
58+
python .github/workflows/compare_score.py

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ typings
5050
# no node modules
5151
node_modules
5252
package*.json
53+
54+
coverage/snippet_score.json

.vscode/settings.json

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
{
22
"workbench.colorCustomizations": {
3-
"titleBar.activeBackground": "#215732",
4-
"titleBar.activeForeground": "#e7e7e7",
5-
"titleBar.inactiveBackground": "#21573299",
6-
"titleBar.inactiveForeground": "#e7e7e799",
7-
"activityBar.activeBackground": "#2f7c47",
8-
"activityBar.activeBorder": "#422c74",
9-
"activityBar.background": "#2f7c47",
10-
"activityBar.foreground": "#e7e7e7",
11-
"activityBar.inactiveForeground": "#e7e7e799",
12-
"panel.border": "#2f7c47",
13-
"editorGroup.border": "#2f7c47",
14-
"tab.activeBorder": "#2f7c47",
15-
"activityBarBadge.background": "#422c74",
16-
"activityBarBadge.foreground": "#e7e7e7",
17-
"statusBar.background": "#215732",
18-
"statusBar.foreground": "#e7e7e7",
19-
"statusBarItem.hoverBackground": "#2f7c47",
20-
"statusBarItem.remoteBackground": "#215732",
21-
"statusBarItem.remoteForeground": "#e7e7e7",
22-
"sash.hoverBorder": "#2f7c47",
23-
"commandCenter.border": "#e7e7e799"
3+
"activityBar.activeBorder": "#422c74"
244
},
255
"peacock.color": "#215732",
266
"cSpell.words": [
@@ -29,9 +9,6 @@
299
"peacock.affectEditorGroupBorder": true,
3010
"peacock.affectPanelBorder": true,
3111
"peacock.affectTabActiveBorder": true,
32-
"python.testing.pytestArgs": [
33-
"tests"
34-
],
3512
"python.testing.unittestEnabled": false,
3613
"python.testing.pytestEnabled": true,
3714
"python.analysis.useLibraryCodeForTypes": false,

lgtm.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)