bring up to pre-commit standards and add workflows

This commit is contained in:
Jeff Epler 2023-12-17 19:21:43 -06:00
parent c77b0f31ef
commit a173e10173
No known key found for this signature in database
GPG key ID: D5BF15AB975AB4DE
25 changed files with 242 additions and 28 deletions

View file

@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2021 Adafruit Industries
#
# SPDX-License-Identifier: MIT
Thank you for contributing! Before you submit a pull request, please read the following.
Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html
If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs
Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code
Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues.

50
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
name: Build CI
on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo "repo-name=$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)" >> $GITHUB_OUTPUT
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Versions
run: |
python3 --version
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Install deps
run: |
sudo apt update
sudo apt-get install gettext otf2bdf xfonts-utils
pip install -r requirements.txt
pip install pre-commit
- name: Library version
run: git describe --dirty --always --tags
- name: Pre-commit hooks
run: |
pre-commit run --all-files
- name: Build assets
run: python build.py
- uses: actions/upload-artifact@v3
with:
path: dist
name: bundle
- name: Setup problem matchers
uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1

19
.github/workflows/failure-help-text.yml vendored Normal file
View file

@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries
#
# SPDX-License-Identifier: MIT
name: Failure help text
on:
workflow_run:
workflows: ["Build CI"]
types:
- completed
jobs:
post-help:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }}
steps:
- name: Post comment to help
uses: adafruit/circuitpython-action-library-ci-failed@v1

50
.github/workflows/images.yml vendored Normal file
View file

@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
name: Generate folder images
on:
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
concurrency:
group: bundle-folder-images
cancel-in-progress: true
jobs:
update-images:
if: github.repository_owner == 'adafruit'
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: checkout submodules
run: git submodule update --init --jobs 16 --depth 1
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Checkout screenshot maker
run: git clone --depth=1 https://github.com/circuitpython/CircuitPython_Library_Screenshot_Maker
- name: Install dependencies
run: pip install -r CircuitPython_Library_Screenshot_Maker/requirements.txt
- name: Generate images
run: |
find libraries -path "libraries/*/examples/*.py" -exec python3 CircuitPython_Library_Screenshot_Maker/create_requirement_images.py bundle {} +
- name: Commit updates
run: |
cd generated_images
git config --global user.name "${GITHUB_ACTOR} (github actions cron)"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global init.defaultBranch main
git init
for i in *.png; do echo "<a href=\"$i\">$i</a><br>"; done > index.html
git add *.png index.html
git remote add origin https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
if git commit -m"update images"; then git push -f origin HEAD:folder-images; fi

47
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
name: Release Actions
on:
workflow_dispatch:
release:
types: [published]
jobs:
upload-release-assets:
runs-on: ubuntu-latest
steps:
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo "repo-name=$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)" >> $GITHUB_OUTPUT
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Versions
run: |
python3 --version
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Install deps
run: |
sudo apt update
sudo apt-get install gettext otf2bdf xfonts-utils
pip install -r requirements.txt
- name: Build assets
run: python build.py
- name: Upload Release Assets
uses: shogo82148/actions-upload-release-asset@v1
with:
asset_path: "dist/*"
github_token: ${{ secrets.GITHUB_TOKEN }}
upload_url: ${{ github.event.release.upload_url }}

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries
# SPDX-License-Identifier: MIT
/build-*
/build_deps
/dist

View file

@ -35,7 +35,7 @@ the GNU FreeFont software before embedding it. This is true even though
portions of the software become part of the document.
Therefore users of fonts released with this exception need not concern
themselves with the license terms to:
themselves with the license terms to:
Create a printable file using the fonts.
- Publish such a file.

9
LICENSES/MIT.txt Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1 +1,4 @@
I'm a little README
Build a suite of importable bitmap fonts for CircuitPython
# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries
# SPDX-License-Identifier: MIT

View file

@ -13,11 +13,14 @@ from convert import convert
with open("config.toml", "rb") as f:
config = tomllib.load(f)
def build(src, dest, size, variant):
src = Path("fonts") / src
font_license = src.with_suffix(src.suffix + ".license")
uvariant= variant.replace('-', '_')
destdir = Path(f"libraries/circuitpython-font-{dest.replace('_', '-')}-{size}{variant}")
uvariant = variant.replace("-", "_")
destdir = Path(
f"libraries/circuitpython-font-{dest.replace('_', '-')}-{size}{variant}"
)
print(destdir)
package = f"circuitpython_font_{dest}_{size}{uvariant}"
@ -43,8 +46,10 @@ def build(src, dest, size, variant):
# SPDX-License-Identifier: Unlicense
CircuitPython font generated from {src} @{size}{variant}
"""))
convert(src, packagedir / "font.pcf", size, '32_126' if variant else None)
"""
)
)
convert(src, packagedir / "font.pcf", size, "32_126" if variant else None)
dest_font_license = packagedir / "font.pcf.license"
dest_font_license.write_text(font_license.read_text())
@ -73,16 +78,24 @@ def build(src, dest, size, variant):
from {package} import FONT
print(FONT.get_bounding_box())
"""))
"""
)
)
if __name__ == '__main__':
targets = [(src, dest, size, variant)
if __name__ == "__main__":
targets = [
(src, dest, size, variant)
for dest, src in config["FONTS"].items()
for size in config["SIZES"]
for variant in ("", "-ascii")]
for size in config["SIZES"]
for variant in ("", "-ascii")
]
with Pool() as pool:
# This construct causes all the individual calls to finish, discarding the results
deque(pool.starmap(build, targets), 0)
check_call("circuitpython-build-bundles --output_directory dist --filename_prefix circuitpython-font --library_location libraries/ --library_depth 1", shell=True)
check_call(
"circuitpython-build-bundles --output_directory dist --filename_prefix circuitpython-font --library_location libraries/ --library_depth 1",
shell=True,
)

View file

@ -1,4 +1,5 @@
# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries
# SPDX-License-Identifier: MIT
SIZES = [6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 48, 60, 72]

View file

@ -1,4 +1,7 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries
# SPDX-License-Identifier: MIT
from pathlib import Path
from subprocess import run, check_call, DEVNULL, PIPE
@ -8,10 +11,9 @@ import click
def convert(src: Path, dest: Path, size: int, subset=None) -> None:
otf_command = ["otf2bdf", "-p", f"{size}", "-r", "72", f"{src}"]
if subset:
otf_command.extend(['-l', subset])
otf_command.extend(["-l", subset])
otf_process = run(otf_command, stdin=DEVNULL, stdout=PIPE
)
otf_process = run(otf_command, stdin=DEVNULL, stdout=PIPE)
bdf_content = otf_process.stdout
if otf_process.returncode != 8:
print(f"Note: End of bdf_content: {bdf_content[-32:]!r}")

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2002-2012 GNU Freefont contributors
SPDX-License-Identifier: GPL-3.0-or-later WITH Special-Font-Exception
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Special-Font-Exception

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries
# SPDX-License-Identifier: MIT
circuitpython-build-tools