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

Python lint #27

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
74 changes: 63 additions & 11 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,20 +59,41 @@ 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
cd test/aidbox_sdk/snapshots/typescript && npm ci

- 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ META/*
!META/.gitkeep

resources/sdk/typescript/node_modules/
resources/sdk/python/aidbox.egg-info/
29 changes: 29 additions & 0 deletions resources/sdk/python/pylintrc.toml
Original file line number Diff line number Diff line change
@@ -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"
]
15 changes: 12 additions & 3 deletions resources/sdk/python/setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/aidbox_sdk/generator/python.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)))])})
Expand Down
Loading