diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 718d157..eee1f54 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -9,11 +9,42 @@ on: - ".github/workflows/lint.yaml" - "test/aidbox_sdk/snapshots/**" - "resources/sdk/**" + pull_request: + branches-ignore: + - "**" jobs: - lint: + detect-changes: runs-on: ubuntu-latest + outputs: + typescript-changed: ${{ steps.detect-changes.outputs.typescript-changed }} + python-changed: ${{ steps.detect-changes.outputs.python-changed }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Detect file changes + id: detect-changes + run: | + # Fetch all changes between commits + git fetch --prune --unshallow || true + CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) + echo "Changed files: $CHANGED_FILES" + + # Check if TypeScript or Python files have changed + if echo "$CHANGED_FILES" | grep -qE '^test/aidbox_sdk/snapshots/typescript/|^resources/sdk/typescript/'; then + echo "typescript-changed=true" >> $GITHUB_OUTPUT + fi + if echo "$CHANGED_FILES" | grep -qE '^test/aidbox_sdk/snapshots/python/|^resources/sdk/python/'; then + echo "python-changed=true" >> $GITHUB_OUTPUT + fi + + lint-typescript: + needs: detect-changes + if: ${{ needs.detect-changes.outputs.typescript-changed }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -28,16 +59,6 @@ jobs: cache: "npm" cache-dependency-path: test/aidbox_sdk/snapshots/typescript/package-lock.json - # - name: Cache Node modules - # uses: actions/cache@v3 - # with: - # path: | - # ~/.npm - # **/node_modules - # key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - # restore-keys: | - # ${{ runner.os }}-node- - - name: Install system and client dependencies run: | sudo apt -y update @@ -45,3 +66,34 @@ jobs: - name: Run ESLint run: cd test/aidbox_sdk/snapshots/typescript && npm run lint + + lint-python: + needs: detect-changes + if: ${{ needs.detect-changes.outputs.python-changed }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Merge Python SDK files + run: | + cp -r -u resources/sdk/python/* test/aidbox_sdk/snapshots/python/ + + - name: Clear pip cache + run: rm -rf $HOME/.cache/pip + + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: 3.x + + - name: Install system + run: | + sudo apt -y update + python -m pip install --upgrade pip + + - name: Install python dependencies + run: | + cd test/aidbox_sdk/snapshots/python && pip install --prefer-binary './[dev]' + + - name: Run python lint + run: cd test/aidbox_sdk/snapshots/python && pylint **/*.py diff --git a/.gitignore b/.gitignore index d656038..62dc550 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ META/* !META/.gitkeep resources/sdk/typescript/node_modules/ +resources/sdk/python/aidbox.egg-info/ diff --git a/resources/sdk/python/pylintrc.toml b/resources/sdk/python/pylintrc.toml new file mode 100644 index 0000000..23a4e96 --- /dev/null +++ b/resources/sdk/python/pylintrc.toml @@ -0,0 +1,29 @@ +[tool.pylint."messages control"] +# Only show warnings with the listed confidence levels. Leave empty to show all. +# Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, UNDEFINED. +confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"] + +# Disable the message, report, category or checker with the given id(s). You can +# either give multiple identifiers separated by comma (,) or put this option +# multiple times (only on the command line, not in the configuration file where +# it should appear only once). You can also use "--disable=all" to disable +# everything first and then re-enable specific checks. For example, if you want +# to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable = [ + "raw-checker-failed", "bad-inline-option", + "locally-disabled", "file-ignored", "suppressed-message", + "useless-suppression", "deprecated-pragma", + "use-implicit-booleaness-not-comparison-to-string", + "use-implicit-booleaness-not-comparison-to-zero", + "use-symbolic-message-instead", + + + "missing-class-docstring", "wildcard-import", + "too-few-public-methods", "unused-wildcard-import", + "missing-final-newline", "invalid-name", + "relative-beyond-top-level", "missing-module-docstring", + "duplicate-code", "line-too-long" +] diff --git a/resources/sdk/python/setup.py b/resources/sdk/python/setup.py index 2a2de92..32634d5 100644 --- a/resources/sdk/python/setup.py +++ b/resources/sdk/python/setup.py @@ -1,18 +1,27 @@ +""" +setup.py +""" + from setuptools import setup setup( name="aidbox", version="0.0.1", description="", - python_requires=">=3.7", + python_requires=">=3.8", package_data={"": ["py.typed"]}, include_package_data=True, install_requires=[ "requests>=2.31.0", "types-requests==2.31.0.8", - "pydantic[email]==2.0.0", - "pydantic_core==2.0.1", + "pydantic[email]==2.9.2", + # "pydantic_core==2.24.0", ], + extras_require={ + 'dev': [ + 'pylint' + ], + }, classifiers=[ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", diff --git a/src/aidbox_sdk/generator/python.clj b/src/aidbox_sdk/generator/python.clj index de0ab6c..0397816 100644 --- a/src/aidbox_sdk/generator/python.clj +++ b/src/aidbox_sdk/generator/python.clj @@ -176,8 +176,8 @@ (generate-datatypes [_ ir-schemas] [{:path (datatypes-file-path) :content (generate-module - :deps [{:module "pydantic" :members ["*"]} - {:module "typing" :members ["Optional" "List"]}] + :deps [{:module "typing" :members ["Optional" "List"]} + {:module "pydantic" :members ["*"]}] :classes (map (fn [ir-schema] (generate-class ir-schema (map generate-class (:backbone-elements ir-schema)) @@ -187,8 +187,8 @@ (generate-resource-module [_ ir-schema] {:path (resource-file-path ir-schema) :content (generate-module - :deps [{:module "pydantic" :members ["*"]} - {:module "typing" :members ["Optional" "List"]} + :deps [{:module "typing" :members ["Optional" "List"]} + {:module "pydantic" :members ["*"]} {:module "..base" :members ["*"]}] :classes [(generate-class ir-schema (map generate-class (:backbone-elements ir-schema)))])})