forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate api data on each push (qmk#10609)
* add new qmk generate-api command, to generate a complete set of API data. * Generate api data and push it to the keyboard repo * fix typo * Apply suggestions from code review Co-authored-by: Joel Challis <git@zvecr.com> * fixup api workflow * remove file-changes-action * use a more mainstream github action * fix yaml error * Apply suggestions from code review Co-authored-by: Erovia <Erovia@users.noreply.github.com> * more uniform date handling * make flake8 happy * Update lib/python/qmk/decorators.py Co-authored-by: Erovia <Erovia@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Erovia <Erovia@users.noreply.github.com>
- Loading branch information
1 parent
8ef82c4
commit 0c42f91
Showing
18 changed files
with
397 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Update API Data | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- 'keyboards/**' | ||
- 'layouts/community/**' | ||
|
||
jobs: | ||
api_data: | ||
runs-on: ubuntu-latest | ||
container: qmkfm/base_container | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 1 | ||
persist-credentials: false | ||
|
||
- name: Generate API Data | ||
run: qmk generate-api | ||
|
||
- name: Upload API Data | ||
uses: JamesIves/github-pages-deploy-action@3.7.1 | ||
with: | ||
ACCESS_TOKEN: ${{ secrets.API_TOKEN_GITHUB }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: main | ||
FOLDER: api_data/v1 | ||
CLEAN: true | ||
GIT_CONFIG_EMAIL: hello@qmk.fm | ||
REPOSITORY_NAME: qmk/qmk_keyboards | ||
TARGET_FOLDER: v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
*.swp | ||
tags | ||
*~ | ||
api_data/v1 | ||
build/ | ||
.build/ | ||
*.bak | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-cayman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# QMK Keyboard Metadata | ||
|
||
This directory contains machine parsable data about keyboards supported by QMK. The latest version is always available online at <https://keyboards.qmk.fm>. | ||
|
||
Do not edit anything here by hand. It is generated with the `qmk generate-api` command. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""This script automates the generation of the QMK API data. | ||
""" | ||
from pathlib import Path | ||
from shutil import copyfile | ||
import json | ||
|
||
from milc import cli | ||
|
||
from qmk.datetime import current_datetime | ||
from qmk.info import info_json | ||
from qmk.keyboard import list_keyboards | ||
|
||
|
||
@cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) | ||
def generate_api(cli): | ||
"""Generates the QMK API data. | ||
""" | ||
api_data_dir = Path('api_data') | ||
v1_dir = api_data_dir / 'v1' | ||
keyboard_list = v1_dir / 'keyboard_list.json' | ||
keyboard_all = v1_dir / 'keyboards.json' | ||
usb_file = v1_dir / 'usb.json' | ||
|
||
if not api_data_dir.exists(): | ||
api_data_dir.mkdir() | ||
|
||
kb_all = {'last_updated': current_datetime(), 'keyboards': {}} | ||
usb_list = {'last_updated': current_datetime(), 'devices': {}} | ||
|
||
# Generate and write keyboard specific JSON files | ||
for keyboard_name in list_keyboards(): | ||
kb_all['keyboards'][keyboard_name] = info_json(keyboard_name) | ||
keyboard_dir = v1_dir / 'keyboards' / keyboard_name | ||
keyboard_info = keyboard_dir / 'info.json' | ||
keyboard_readme = keyboard_dir / 'readme.md' | ||
keyboard_readme_src = Path('keyboards') / keyboard_name / 'readme.md' | ||
|
||
keyboard_dir.mkdir(parents=True, exist_ok=True) | ||
keyboard_info.write_text(json.dumps(kb_all['keyboards'][keyboard_name])) | ||
|
||
if keyboard_readme_src.exists(): | ||
copyfile(keyboard_readme_src, keyboard_readme) | ||
|
||
if 'usb' in kb_all['keyboards'][keyboard_name]: | ||
usb = kb_all['keyboards'][keyboard_name]['usb'] | ||
|
||
if usb['vid'] not in usb_list['devices']: | ||
usb_list['devices'][usb['vid']] = {} | ||
|
||
if usb['pid'] not in usb_list['devices'][usb['vid']]: | ||
usb_list['devices'][usb['vid']][usb['pid']] = {} | ||
|
||
usb_list['devices'][usb['vid']][usb['pid']][keyboard_name] = usb | ||
|
||
# Write the global JSON files | ||
keyboard_list.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': sorted(kb_all['keyboards'])})) | ||
keyboard_all.write_text(json.dumps(kb_all)) | ||
usb_file.write_text(json.dumps(usb_list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,13 @@ | ||
"""List the keyboards currently defined within QMK | ||
""" | ||
# We avoid pathlib here because this is performance critical code. | ||
import os | ||
import glob | ||
|
||
from milc import cli | ||
|
||
BASE_PATH = os.path.join(os.getcwd(), "keyboards") + os.path.sep | ||
KB_WILDCARD = os.path.join(BASE_PATH, "**", "rules.mk") | ||
|
||
|
||
def find_name(path): | ||
"""Determine the keyboard name by stripping off the base_path and rules.mk. | ||
""" | ||
return path.replace(BASE_PATH, "").replace(os.path.sep + "rules.mk", "") | ||
import qmk.keyboard | ||
|
||
|
||
@cli.subcommand("List the keyboards currently defined within QMK") | ||
def list_keyboards(cli): | ||
"""List the keyboards currently defined within QMK | ||
""" | ||
# find everywhere we have rules.mk where keymaps isn't in the path | ||
paths = [path for path in glob.iglob(KB_WILDCARD, recursive=True) if 'keymaps' not in path] | ||
|
||
# Extract the keyboard name from the path and print it | ||
for keyboard_name in sorted(map(find_name, paths)): | ||
for keyboard_name in qmk.keyboard.list_keyboards(): | ||
print(keyboard_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Functions to work with dates and times in a uniform way. | ||
The results of these functions are cached for 5 seconds to provide uniform time strings across short running processes. Long running processes that need more precise timekeeping should not use these functions. | ||
""" | ||
from time import gmtime, strftime | ||
|
||
from qmk.constants import DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT | ||
from qmk.decorators import lru_cache | ||
|
||
|
||
@lru_cache(timeout=5) | ||
def current_date(): | ||
"""Returns the current time in UTZ as a formatted string. | ||
""" | ||
return strftime(DATE_FORMAT, gmtime()) | ||
|
||
|
||
@lru_cache(timeout=5) | ||
def current_datetime(): | ||
"""Returns the current time in UTZ as a formatted string. | ||
""" | ||
return strftime(DATETIME_FORMAT, gmtime()) | ||
|
||
|
||
@lru_cache(timeout=5) | ||
def current_time(): | ||
"""Returns the current time in UTZ as a formatted string. | ||
""" | ||
return strftime(TIME_FORMAT, gmtime()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.