Source sets & dependencies소스셋과 의존성

Tell the plugin where your Python lives and what it depends on.

Python 코드가 어디 있고 무엇에 의존하는지 플러그인에 알려줍니다.

Where the package is패키지 위치

python {
    sourceSets {
        val commonMain by getting {
            srcDirs("src/commonMain/python")          // the pypackpack package
            metaDirs("src/commonMain/generated/meta") // .pyi stubs, merged into the bundle
            libDirs("src/commonMain/build/site-packages")
        }
    }
}
Rule규칙Detail내용
Package directory패키지 디렉터리localLibraryPath if set, otherwise the first commonMain.srcDirs entry, otherwise none (install and bundle skip).localLibraryPath 가 있으면 그것, 없으면 commonMain.srcDirs 의 첫 항목, 그것도 없으면 없음 (설치와 번들 건너뜀).
metaDirs, libDirsmetaDirs, libDirsEvery entry is forwarded to pypackpack's BundleRequest. metaDirs are left out when buildFeatures { metaclass = false } (default true), and from the bundles of a build type that sets excludeMetaclass = true.모든 항목이 pypackpack 의 BundleRequest 로 전달됩니다. metaDirs 는 buildFeatures { metaclass = false }(기본값 true)이면 빠지고, excludeMetaclass = true 인 빌드 타입의 번들에서도 빠집니다.
Only on commonMaincommonMain 에서만The three directory functions throw in any other source set.세 디렉터리 함수는 다른 소스셋에서 호출하면 예외가 납니다.

Dependencies의존성

python {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("pyzmq")
                implementation("rpds-py==0.20.0")
            }
        }
        val androidMain by getting {
            dependencies {
                integration("pycomposeui")   // a Python package that depends on Kotlin
            }
        }
    }
}

Each variant gets the dependencies of commonMain, of its own family's source set (androidMain, iosMain or desktopMain) and of its flavor's <flavor>Main, and nothing else. They are installed for that variant's target triple, as wheels, and land in its bundle's python/ beside your modules.

각 변형은 commonMain, 자기 계열의 소스셋(androidMain, iosMain, desktopMain), 자기 플레이버의 <flavor>Main 의 의존성만 받습니다. 그 변형의 타깃 트리플용 wheel 로 설치되어, 번들의 python/ 에 모듈과 나란히 들어갑니다.

Task태스크What it does하는 일
installPythonDependencies<Platform><Flavor>Installs that set's dependencies with pypackpack's uv pip install --target build/pythonDeps/<platform>-<flavor> --python-platform <triple>, for compileSdk's Python version and from wheels only. Debug and release share it. Every buildPython… task of the set bundles that directory.그 집합의 의존성을 pypackpack 의 uv pip install --target build/pythonDeps/<platform>-<flavor> --python-platform <triple> 로, compileSdk 의 Python 버전에 맞춰 wheel 로만 설치합니다. debug 와 release 가 함께 씁니다. 그 집합의 모든 buildPython… 태스크가 이 디렉터리를 번들에 넣습니다.
installPythonDependenciesHostWithout a platform variant: commonMain and desktopMain for the build machine's triple, into build/pythonDeps/host.플랫폼 변형이 없을 때: commonMain 과 desktopMain 을 빌드 머신의 트리플용으로 build/pythonDeps/host 에 설치합니다.
installPythonDependenciesA real uv add of every source set's dependencies in the package directory: they are recorded in your pyproject.toml, and the .venv it leaves is what compileLevel = "bytecode" compiles with. It does not feed the bundle.모든 소스셋의 의존성을 패키지 디렉터리에서 실제 uv add 합니다. pyproject.toml 에 기록되고, 남는 .venv 로 compileLevel = "bytecode" 가 컴파일합니다. 번들에는 쓰이지 않습니다.

A package with no wheel for a variant's triple fails that variant's install task, naming the package. Dependencies in a source set no variant reads (androidArm64Main, or freeMain without a free flavor) fail the install tasks instead of being silently dropped. integration() still installs exactly like implementation(): the KLIBDEPENS wheel check the DSL describes is not implemented yet.

변형의 트리플용 wheel 이 없는 패키지는 그 변형의 설치 태스크를 패키지 이름과 함께 실패시킵니다. 어떤 변형도 읽지 않는 소스셋(androidArm64Main, 또는 free 플레이버 없는 freeMain)의 의존성은 조용히 버려지지 않고 설치 태스크를 실패시킵니다. integration() 은 여전히 implementation() 과 똑같이 설치됩니다. DSL 이 설명하는 KLIBDEPENS 휠 검사는 아직 없습니다.

integration() installs like implementation(); afterwards each integration's installed *.dist-info/ is checked for a KLIBDEPENS file, and if it is missing a warning suggests implementation() (never a failure).

integration() 은 implementation() 처럼 설치된 뒤, 설치된 *.dist-info/ 에 KLIBDEPENS 파일이 있는지 검사하며 없으면 implementation() 을 쓰라는 경고를 냅니다 (실패는 아님).

Package repositories패키지 저장소

python {
    defaultConfig {
        pip {
            autoUpdate = true                                  // uv add --upgrade
            repositories {
                central { setUrl("https://mirror.example/simple") }  // --default-index
                local { url = Paths.get("wheels").toUri().toString() } // --find-links
            }
        }
    }
}

central's first URL replaces PyPI; any further URLs are added as extra indexes. local is a directory of wheels. jit { } (building packages from recipes) is not supported yet: declaring it fails installPythonDependencies and the per-target install tasks with the reason, and only when there is something to install.

central 의 첫 URL 이 PyPI 를 대신하고, 나머지 URL 은 추가 인덱스가 됩니다. local 은 wheel 이 든 디렉터리입니다. jit { }(레시피로 패키지 빌드)는 아직 지원하지 않습니다. 선언하면 설치할 것이 있을 때만 installPythonDependencies 와 타깃별 설치 태스크가 이유와 함께 실패합니다.

ComposeCompose

python {
    buildFeatures {
        compose = true
    }
}
# gradle.properties (or -P on the command line)
python.compose.pythonxCompose=pythonx-compose==0.1.0      # or a directory of wheels
python.compose.kotlinModule=group:python-multiplatform-compose:version

compose = true installs pythonx-compose with the other dependencies and adds python-multiplatform-compose to Kotlin Multiplatform commonMain's implementation. Neither is published yet, so both locations come from these two Gradle properties and have no default. pythonxCompose is a pip requirement, or a directory of wheels, which is added to --find-links after any local repository. A missing pythonxCompose fails installPythonDependencies only; a missing kotlinModule fails configuration, because the dependency belongs to every Kotlin compilation. Without the Kotlin Multiplatform plugin only pythonx-compose is installed, with a warning.

compose = true 는 다른 의존성과 함께 pythonx-compose 를 설치하고, Kotlin Multiplatform commonMain 의 implementation 에 python-multiplatform-compose 를 추가합니다. 둘 다 아직 배포되지 않았으므로 위치는 이 두 Gradle 속성으로 정하며 기본값이 없습니다. pythonxCompose 는 pip 요구사항이거나 wheel 디렉터리이고, 디렉터리는 local 저장소 뒤에 --find-links 로 추가됩니다. pythonxCompose 가 없으면 installPythonDependencies 만 실패하고, kotlinModule 이 없으면 구성 단계가 실패합니다. 그 의존성은 모든 Kotlin 컴파일에 속하기 때문입니다. Kotlin Multiplatform 플러그인이 없으면 경고와 함께 pythonx-compose 만 설치됩니다.