mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-18 00:21:31 +00:00
feat(backend): add typechecking with ty (#9664)
* Add ty for type checking * fix various typing issues * fix req * more fixes * and more types * and more typing * fix imports * more fixes * fix types and optional statements * ensure patch only runs if it is installed * add type check to qc * more fixes * install all reqs * fix more types * more fixes * disable container stuff for now * move typecheck to seperate job * try to use putput for path * use env instead * fix typo * add missing install * remove unclear imports - not sure why this was done * add kwarg names * fix introduced issue in url call * ignore import * fix broken typing changes * fix filter import * reduce change set * remove api-change * fix dict * ignore typing errors * fix more type issues * ignore errors * style fix * fix type * bump ty * fix more * type fixes * update ignores * fix import * fix defaults * fix ignore * fix some issues * fix type
This commit is contained in:
22
.github/scripts/version_check.py
vendored
22
.github/scripts/version_check.py
vendored
@@ -17,6 +17,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
|
||||
@@ -183,7 +184,8 @@ def check_version_number(version_string, allow_duplicate=False):
|
||||
return highest_release
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main() -> bool:
|
||||
"""Run the version check."""
|
||||
parser = argparse.ArgumentParser(description='InvenTree Version Check')
|
||||
parser.add_argument(
|
||||
'--show-version',
|
||||
@@ -220,7 +222,7 @@ if __name__ == '__main__':
|
||||
# Ensure that we are running in GH Actions
|
||||
if os.environ.get('GITHUB_ACTIONS', '') != 'true':
|
||||
print('This script is intended to be run within a GitHub Action!')
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
||||
print('Running InvenTree version check...')
|
||||
|
||||
@@ -261,11 +263,11 @@ if __name__ == '__main__':
|
||||
)
|
||||
|
||||
# Determine which docker tag we are going to use
|
||||
docker_tags = None
|
||||
docker_tags: Optional[list[str]] = None
|
||||
|
||||
if GITHUB_REF_TYPE == 'tag':
|
||||
# GITHUB_REF should be of the form /refs/heads/<tag>
|
||||
version_tag = GITHUB_REF.split('/')[-1]
|
||||
version_tag: str = GITHUB_REF.split('/')[-1]
|
||||
print(f"Checking requirements for tagged release - '{version_tag}':")
|
||||
|
||||
if version_tag != inventree_version:
|
||||
@@ -287,11 +289,11 @@ if __name__ == '__main__':
|
||||
print('GITHUB_REF_TYPE:', GITHUB_REF_TYPE)
|
||||
print('GITHUB_BASE_REF:', GITHUB_BASE_REF)
|
||||
print('GITHUB_REF:', GITHUB_REF)
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
||||
if docker_tags is None:
|
||||
print('Docker tags could not be determined')
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
||||
print(f"Version check passed for '{inventree_version}'!")
|
||||
print(f"Docker tags: '{docker_tags}'")
|
||||
@@ -308,3 +310,11 @@ if __name__ == '__main__':
|
||||
|
||||
if GITHUB_REF_TYPE == 'tag' and highest_release:
|
||||
env_file.write('stable_release=true\n')
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
rslt = main()
|
||||
if rslt is not True:
|
||||
print('Version check failed!')
|
||||
sys.exit(1)
|
||||
|
21
.github/workflows/qc_checks.yaml
vendored
21
.github/workflows/qc_checks.yaml
vendored
@@ -97,6 +97,27 @@ jobs:
|
||||
pip install --require-hashes -r contrib/dev_reqs/requirements.txt
|
||||
python3 .github/scripts/version_check.py
|
||||
|
||||
typecheck:
|
||||
name: Style [Typecheck]
|
||||
runs-on: ubuntu-24.04
|
||||
needs: [paths-filter, pre-commit]
|
||||
if: needs.paths-filter.outputs.server == 'true' || needs.paths-filter.outputs.requirements == 'true' || needs.paths-filter.outputs.force == 'true'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Environment Setup
|
||||
id: setup
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
apt-dependency: gettext poppler-utils
|
||||
dev-install: true
|
||||
update: true
|
||||
- name: Check types
|
||||
run: |
|
||||
ty check --python ${Python_ROOT_DIR}/bin/python3
|
||||
|
||||
mkdocs:
|
||||
name: Style [Documentation]
|
||||
runs-on: ubuntu-24.04
|
||||
|
Reference in New Issue
Block a user