Skip to content

Commit a752e84

Browse files
authored
Feat: QR code generator (#137)
2 parents d9078c3 + ffaed3c commit a752e84

File tree

11 files changed

+227
-6
lines changed

11 files changed

+227
-6
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN apt-get install -y ruby-full && gem install bundler
99
RUN python -m pip install --upgrade pip
1010

1111
RUN useradd --create-home --shell /bin/bash $USER && \
12+
mkdir /home/$USER/site && \
1213
chown -R $USER /home/$USER
1314

1415
WORKDIR /home/$USER/site
@@ -20,5 +21,5 @@ RUN bundle install
2021
USER $USER
2122
ENV PATH "$PATH:/home/$USER/.local/bin"
2223

23-
COPY .devcontainer/requirements.txt .devcontainer/requirements.txt
24-
RUN pip install --no-cache-dir -r .devcontainer/requirements.txt
24+
COPY LICENSE pyproject.toml README.md ./
25+
RUN pip install -e .[dev,qr_codes]

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "compiler/datadonuts.la",
3-
"dockerComposeFile": "compose.yml",
3+
"dockerComposeFile": "../compose.yml",
44
"service": "site",
55
"workspaceFolder": "/home/compiler/site",
66
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"],
@@ -18,6 +18,9 @@
1818
"eamodio.gitlens",
1919
"esbenp.prettier-vscode",
2020
"mhutchie.git-graph",
21+
"ms-python.python",
22+
"ms-python.black-formatter",
23+
"ms-python.flake8",
2124
"redhat.vscode-xml",
2225
"sissel.shopify-liquid",
2326
"tamasfe.even-better-toml"

.devcontainer/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 127
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Generate QR code
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
data:
6+
description: "The data for the QR code, e.g. a URL"
7+
required: true
8+
type: string
9+
color:
10+
description: "The color of the QR code (hex or name), defaults to black"
11+
default: "#000000"
12+
required: false
13+
type: string
14+
background:
15+
description: "The background color of the QR code in hex format, defaults to transparent"
16+
default: "transparent"
17+
required: false
18+
type: string
19+
size:
20+
description: "The size of the QR code from 1 (smallest) to 10 (largest), defaults to 4"
21+
default: 4
22+
required: false
23+
type: choice
24+
options:
25+
- 1
26+
- 2
27+
- 3
28+
- 4
29+
- 5
30+
- 6
31+
- 7
32+
- 8
33+
- 9
34+
- 10
35+
36+
jobs:
37+
generate-qr-code:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Python
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.11"
47+
cache: pip
48+
cache-dependency-path: "pyproject.toml"
49+
50+
- name: Install dependencies
51+
run: pip install -e .[qr_codes]
52+
53+
- name: Generate QR code
54+
run: |
55+
python qr_codes/main.py \
56+
--color="${{ inputs.color }}" \
57+
--background="${{ inputs.background }}" \
58+
--size="${{ inputs.size }}" \
59+
${{ inputs.data }} \
60+
qr-code.png
61+
62+
- name: Upload QR code as artifact
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: qr-code.png
66+
path: qr-code.png

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.idea/
44
_site/
55
.DS_Store
6+
qr_codes/*.png
7+
!qr_codes/datadonuts.la.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
22
site:
33
build:
4-
context: ..
4+
context: .
55
dockerfile: .devcontainer/Dockerfile
66
command: sleep infinity
77
volumes:
8-
- ..:/home/compiler/site
8+
- .:/home/compiler/site

pyproject.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[project]
2+
name = "data-donuts"
3+
description = "Administrative tasks for the Data + Donuts team"
4+
version = "1.0.0"
5+
readme = "README.md"
6+
license = { file = "LICENSE" }
7+
classifiers = ["Programming Language :: Python :: 3 :: Only"]
8+
requires-python = ">=3.11"
9+
dependencies = []
10+
11+
[project.urls]
12+
code = "https://github.com/compilerla/data-donuts"
13+
tracker = "https://github.com/compilerla/data-donuts/issues"
14+
15+
[project.optional-dependencies]
16+
dev = [
17+
"black",
18+
"build",
19+
"flake8",
20+
"ipykernel",
21+
"pre-commit"
22+
]
23+
qr_codes = [
24+
"pypng==0.20220715.0",
25+
"qrcode[pil]==7.4.2",
26+
"typing_extensions==4.12.2"
27+
]
28+
29+
[build-system]
30+
requires = ["setuptools>=65"]
31+
build-backend = "setuptools.build_meta"
32+
33+
[tool.black]
34+
line-length = 127
35+
target-version = ['py311']
36+
include = '\.pyi?$'
37+
38+
[tool.setuptools]
39+
packages = []

qr_codes/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Generate QR codes
2+
3+
> Generate a QR code as an PNG file
4+
5+
## Run in GitHub
6+
7+
1. Go to the `Actions` tab at the top of this repository
8+
1. In the left bar, select the `Generate QR code` workflow
9+
1. Click the gray `Run workflow` button on the right side, providing inputs as-needed:
10+
11+
- `branch` should be left as `main`
12+
- `data` is required, this is the URL the QR code should point to
13+
- `color`, `background`, and `size` are optional
14+
15+
1. Click the green `Run workflow` button
16+
1. Refresh the page to see the in-progress workflow run
17+
1. When the workflow has completed (look for the green check mark), click the run
18+
1. In the bottom pane under `Artifacts`, find a link to download the QR code image (downloads a ZIP file with the image inside)
19+
20+
## Run locally
21+
22+
1. Open this repository's devcontainer in VS Code
23+
2. Change into the `qr_codes` directory
24+
3. Run the helper script
25+
26+
```bash
27+
$ python main.py -h
28+
usage: main.py [-h] [--color COLOR] [--background BACKGROUND] [--size SIZE] data output
29+
30+
Generate a QR code as an PNG file
31+
32+
positional arguments:
33+
data The data to encode as a QR code
34+
output Path to an PNG file where the QR code is written
35+
36+
options:
37+
-h, --help show this help message and exit
38+
--color COLOR The color of the QR code in hex format, by default black
39+
--background BACKGROUND
40+
The background color of the QR code in hex format, by default transparent
41+
--size SIZE The QR code size from 1-10, by default 4
42+
```

qr_codes/datadonuts.la.png

2.18 KB
Loading

0 commit comments

Comments
 (0)