Skip to content

Commit a09d53c

Browse files
committed
chore: use Flask inspired GHA workflow
1 parent b0a58f9 commit a09d53c

File tree

8 files changed

+131
-62
lines changed

8 files changed

+131
-62
lines changed

.github/workflows/pre-commit.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: pre-commit
2+
on:
3+
pull_request:
4+
push:
5+
branches: [main, '*.x']
6+
jobs:
7+
main:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
11+
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
12+
with:
13+
python-version: 3.x
14+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
15+
- uses: pre-commit-ci/lite-action@9d882e7a565f7008d4faf128f27d1cb6503d4ebf # v1.0.2
16+
if: ${{ !cancelled() }}

.github/workflows/publish.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
hash: ${{ steps.hash.outputs.hash }}
11+
steps:
12+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
13+
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
14+
with:
15+
python-version: '3.x'
16+
cache: pip
17+
- run: pip install -e .
18+
# Use the commit date instead of the current date during the build.
19+
- run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
20+
- run: python -m build
21+
# Generate hashes used for provenance.
22+
- name: generate hash
23+
id: hash
24+
run: cd dist && echo "hash=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT
25+
- uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
26+
with:
27+
path: ./dist
28+
provenance:
29+
needs: [build]
30+
permissions:
31+
actions: read
32+
id-token: write
33+
contents: write
34+
# Can't pin with hash due to how this workflow works.
35+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
36+
with:
37+
base64-subjects: ${{ needs.build.outputs.hash }}
38+
create-release:
39+
# Upload the sdist, wheels, and provenance to a GitHub release. They remain
40+
# available as build artifacts for a while as well.
41+
needs: [provenance]
42+
runs-on: ubuntu-latest
43+
permissions:
44+
contents: write
45+
steps:
46+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
47+
- name: create release
48+
run: >
49+
gh release create --draft --repo ${{ github.repository }}
50+
${{ github.ref_name }}
51+
*.intoto.jsonl/* artifact/*
52+
env:
53+
GH_TOKEN: ${{ github.token }}
54+
publish-pypi:
55+
needs: [provenance]
56+
# Wait for approval before attempting to upload to PyPI. This allows reviewing the
57+
# files in the draft release.
58+
environment:
59+
name: publish
60+
url: https://pypi.org/project/wtforms/${{ github.ref_name }}
61+
runs-on: ubuntu-latest
62+
permissions:
63+
id-token: write
64+
steps:
65+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
66+
- uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0
67+
with:
68+
repository-url: https://test.pypi.org/legacy/
69+
packages-dir: artifact/
70+
- uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0
71+
with:
72+
packages-dir: artifact/

.github/workflows/tests.yaml

+22-51
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,37 @@
1-
---
2-
name: tests
1+
name: Tests
32
on:
43
push:
54
branches:
65
- main
76
- '*.x'
7+
paths-ignore:
8+
- 'docs/**'
9+
- '*.md'
10+
- '*.rst'
811
pull_request:
9-
branches:
10-
- main
11-
- '*.x'
12+
paths-ignore:
13+
- 'docs/**'
14+
- '*.md'
15+
- '*.rst'
1216
jobs:
1317
tests:
14-
name: ${{ matrix.python }}
15-
runs-on: ubuntu-latest
18+
name: ${{ matrix.name || matrix.python }}
19+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
1620
strategy:
1721
fail-fast: false
1822
matrix:
19-
python:
20-
- '3.13'
21-
- '3.12'
22-
- '3.11'
23-
- '3.10'
24-
- '3.9'
25-
- 'pypy-3.10'
23+
include:
24+
- {python: '3.13'}
25+
- {python: '3.12'}
26+
- {python: '3.11'}
27+
- {python: '3.10'}
28+
- {python: '3.9'}
2629
steps:
27-
- uses: actions/checkout@v2
28-
- uses: actions/setup-python@v2
30+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
31+
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
2932
with:
3033
python-version: ${{ matrix.python }}
31-
- uses: actions/cache@v1
32-
with:
33-
path: ~/.cache/pip
34-
key: pip|${{ hashFiles('setup.py') }}|${{ hashFiles('tox.ini') }}
35-
- run: pip install tox
36-
- run: tox -e py
37-
style:
38-
runs-on: ubuntu-latest
39-
steps:
40-
- uses: actions/checkout@v2
41-
- uses: actions/setup-python@v2
42-
with:
43-
python-version: '3.13'
44-
- uses: actions/cache@v1
45-
with:
46-
path: ~/.cache/pip
47-
key: pip|${{ hashFiles('setup.py') }}|${{ hashFiles('tox.ini') }}
48-
- uses: actions/cache@v1
49-
with:
50-
path: ~/.cache/pre-commit
51-
key: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }}
52-
- run: pip install tox
53-
- run: tox -e style
54-
docs:
55-
runs-on: ubuntu-latest
56-
steps:
57-
- uses: actions/checkout@v2
58-
- uses: actions/setup-python@v2
59-
with:
60-
python-version: '3.13'
61-
- uses: actions/cache@v1
62-
with:
63-
path: ~/.cache/pip
64-
key: pip|${{ hashFiles('setup.py') }}|${{ hashFiles('tox.ini') }}
34+
allow-prereleases: true
35+
cache: pip
6536
- run: pip install tox
66-
- run: tox -e docs
37+
- run: tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }}

src/wtforms/fields/datetime.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def __init__(
3434
def _value(self):
3535
if self.raw_data:
3636
return " ".join(self.raw_data)
37-
return self.data and self.data.strftime(self.format[0]) or ""
37+
format = self.format[0]
38+
return self.data and self.data.strftime(format) or ""
3839

3940
def process_formdata(self, valuelist):
4041
if not valuelist:

src/wtforms/utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import os
12
import re
23

4+
_LEADING_SYMBOL = "#" if os.name == "nt" else "-"
5+
36
# https://docs.python.org/3/library/datetime.html#technical-detail (see NOTE #9)
47
_DATETIME_STRIP_ZERO_PADDING_FORMATS_RE = re.compile(
5-
"%-["
8+
f"%{_LEADING_SYMBOL}["
69
"d" # day of month
710
"m" # month
811
"H" # hour (24-hour)
@@ -25,7 +28,7 @@ def clean_datetime_format_for_strptime(formats):
2528
return [
2629
re.sub(
2730
_DATETIME_STRIP_ZERO_PADDING_FORMATS_RE,
28-
lambda m: m[0].replace("-", ""),
31+
lambda m: m[0].replace(_LEADING_SYMBOL, ""),
2932
format,
3033
)
3134
for format in formats

tests/fields/test_datetime.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import datetime
23

34
from tests.common import DummyPostData
@@ -12,27 +13,29 @@ def make_form(name="F", **fields):
1213
class F(Form):
1314
a = DateTimeField()
1415
b = DateTimeField(format="%Y-%m-%d %H:%M")
15-
c = DateTimeField(format="%-m/%-d/%Y %-I:%M")
16+
c = DateTimeField(
17+
format="%#m/%#d/%Y %#I:%M" if os.name == "nt" else "%-m/%-d/%Y %-I:%M"
18+
)
1619

1720

1821
def test_basic():
1922
d = datetime(2008, 5, 5, 4, 30, 0, 0)
2023
# Basic test with both inputs
21-
form = F(
22-
DummyPostData(
23-
a=["2008-05-05", "04:30:00"], b=["2008-05-05 04:30"], c=["5/5/2008 4:30"]
24-
)
25-
)
24+
form = F(DummyPostData(a=["2008-05-05", "04:30:00"]))
2625
assert form.a.data == d
2726
assert (
2827
form.a()
2928
== """<input id="a" name="a" type="datetime" value="2008-05-05 04:30:00">"""
3029
)
30+
31+
form = F(DummyPostData(b=["2008-05-05 04:30"]))
3132
assert form.b.data == d
3233
assert (
3334
form.b()
3435
== """<input id="b" name="b" type="datetime" value="2008-05-05 04:30">"""
3536
)
37+
38+
form = F(DummyPostData(c=["5/5/2008 4:30"]))
3639
assert form.c.data == d
3740
assert (
3841
form.c() == """<input id="c" name="c" type="datetime" value="5/5/2008 4:30">"""

tests/fields/test_datetimelocal.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import datetime
23

34
from tests.common import DummyPostData
@@ -12,7 +13,9 @@ def make_form(name="F", **fields):
1213
class F(Form):
1314
a = DateTimeLocalField()
1415
b = DateTimeLocalField(format="%Y-%m-%d %H:%M")
15-
c = DateTimeLocalField(format="%-m/%-d/%Y %-I:%M")
16+
c = DateTimeLocalField(
17+
format="%#m/%#d/%Y %#I:%M" if os.name == "nt" else "%-m/%-d/%Y %-I:%M"
18+
)
1619

1720

1821
def test_basic():

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ deps =
1111
babel
1212
email_validator
1313
commands =
14-
pytest --tb=short --basetemp={envtmpdir} {posargs}
14+
pytest --tb=short -l --basetemp={envtmpdir} {posargs}
1515

1616
[testenv:coverage]
1717
deps =

0 commit comments

Comments
 (0)