Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flake8 python version check script and CI check #431

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/flake8_py_version_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: flake8_py_version_check
on:
workflow_dispatch: {}
schedule:
# every Sunday at midnight
- cron: "0 0 * * 0"
jobs:
r-downing marked this conversation as resolved.
Show resolved Hide resolved
check-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: run script
run: python scripts/flake8_py_version_check.py
36 changes: 36 additions & 0 deletions scripts/flake8_py_version_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
import re
import subprocess


def main():
# find a line in pyproject.toml that looks like `python-requires = "..."`
# with forgiving spacing and single or double quotes
with open("pyproject.toml") as fp:
pyproject_txt = fp.read()
match = re.search(r"""\n\s*requires-python\s*=\s*['"](.*)['"]""", pyproject_txt)
r-downing marked this conversation as resolved.
Show resolved Hide resolved
assert match is not None, "'requires-python' line not found in pyproject.toml"

flake8_bugbear_requires = match.group(1).strip()

# get pypi data for flake8 as json
curl_output = subprocess.getoutput(
"curl -L -s --header 'Accept: application/vnd.pypi.simple.v1+json'"
r-downing marked this conversation as resolved.
Show resolved Hide resolved
" https://pypi.org/simple/flake8"
)
flake8_pypi_data = json.loads(curl_output)

# find latest non-yanked flake8 file data
latest_file_data = next(
file for file in reversed(flake8_pypi_data["files"]) if not file["yanked"]
)
flake8_requires = latest_file_data["requires-python"]

assert flake8_requires == flake8_bugbear_requires, (
f"python version requirements don't match: ({flake8_requires=} !="
f" {flake8_bugbear_requires=})"
)
Comment on lines +24 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankyou for the verbose assert failing message :)



if __name__ == "__main__":
main()