FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-black/scripts/check_pre_commit_rev_in_example.py at main · pullfrog/python-black · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pullfrog
/
python-black
Public
forked from
psf/black
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-black
/
scripts
/
check_pre_commit_rev_in_example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (45 loc) · 1.83 KB
Breadcrumbs
python-black
/
scripts
/
check_pre_commit_rev_in_example.py
Copy path
File metadata and controls
54 lines (45 loc) · 1.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Check that the rev value in the example pre-commit configuration matches
the latest version of Black. This saves us from forgetting to update that
during the release process.
Why can't we just use `rev: stable` and call it a day? Well pre-commit
won't auto update the hook as you may expect (and for good reasons, some
technical and some pragmatic). Encouraging bad practice is also just
not ideal. xref: https://github.com/psf/black/issues/420
"""
import
os
import
sys
import
commonmark
import
yaml
from
bs4
import
BeautifulSoup
def
main
(
changes
:
str
,
source_version_control
:
str
)
->
None
:
changes_html
=
commonmark
.
commonmark
(
changes
)
changes_soup
=
BeautifulSoup
(
changes_html
,
"html.parser"
)
headers
=
changes_soup
.
find_all
(
"h2"
)
latest_tag
,
*
_
=
(
header
.
string
for
header
in
headers
if
header
.
string
!=
"Unreleased"
)
source_version_control_html
=
commonmark
.
commonmark
(
source_version_control
)
source_version_control_soup
=
BeautifulSoup
(
source_version_control_html
,
"html.parser"
)
pre_commit_repos
=
yaml
.
safe_load
(
source_version_control_soup
.
find
(
class_
=
"language-yaml"
).
string
# type: ignore[union-attr, arg-type]
)[
"repos"
]
for
repo
in
pre_commit_repos
:
pre_commit_rev
=
repo
[
"rev"
]
if
not
pre_commit_rev
==
latest_tag
:
print
(
"Please set the rev in ``source_version_control.md`` to be the latest "
f"one.
\n
Expected
{
latest_tag
}
, got
{
pre_commit_rev
}
.
\n
"
)
sys
.
exit
(
1
)
if
__name__
==
"__main__"
:
with
open
(
"CHANGES.md"
,
encoding
=
"utf-8"
)
as
fd
:
changes
=
fd
.
read
()
with
open
(
os
.
path
.
join
(
"docs"
,
"integrations"
,
"source_version_control.md"
),
encoding
=
"utf-8"
,
)
as
fd
:
source_version_control
=
fd
.
read
()
main
(
changes
,
source_version_control
)
Back
|
FazBrowse Home
|
New Git URL