Skip to content

Commit b6baf35

Browse files
authored
Merge pull request #410 from thisisthepy/feat/design-systems-408
Compose: bump fork libraries to 1.11.1-ext.4 and bind design systems (#408)
2 parents d6132fe + d83d11e commit b6baf35

11 files changed

Lines changed: 301 additions & 17 deletions

File tree

‎.github/scripts/stubs/consumer.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from androidx.compose.material3 import Checkbox, Icon, Text
2929
from androidx.compose.ui import Modifier
3030
from androidx.compose.ui.graphics.vector import ImageVector
31+
from org.thisisthepy.compose.material3 import Material3DesignSystem, material_design_system
3132

3233
# A chain started from the class, the way Kotlin writes `Modifier.padding(16.dp)`.
3334
chain: Modifier = Modifier.fillMaxWidth().padding(16.0).size(24.0)
@@ -43,6 +44,10 @@
4344
assert_type(fill_max_width(chain), Modifier)
4445
pythonic_chain: Modifier = Modifier.fill_max_width().padding(16.0).fill_max_width(0.5)
4546

47+
# Issue #408: the fork's design systems are walked too, under their own Kotlin packages.
48+
dark: Material3DesignSystem = material_design_system(True)
49+
assert_type(material_design_system(is_dark=False), Material3DesignSystem)
50+
4651
checked = True
4752

4853

‎docs/SPEC.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,19 @@ All in `PM/commonTest`, so they run wherever the interpreter loads.
658658
in `AGENTS.md`): everything else that is public stays bound; it is not a list of what to expose. A segment
659659
must equal `internal` exactly (`internals` and `internal_api` are ordinary packages).
660660
`Status: implemented`, `GP/artifact/InternalPackageExclusionTest.kt`.
661+
- **B-12** (#408) The Compose fixtures (`python-multiplatform-compose/fixtures/compose`, whose stubs are the
662+
`kotlin-stubs` artefact of B-8, and `fixtures/notebook-e2e`) depend on the fork's design systems,
663+
`org.thisisthepy.compose.designsystem:designsystem` and `designsystem-{material3, breeze, cupertino, deepin,
664+
fluent, gnome, liquid-glass}` at `compose-libraries` (`gradle/libs.versions.toml`, `1.11.1-ext.4`), and walk
665+
their Kotlin packages `org.thisisthepy.compose.{designsystem, material3, breeze, cupertino, deepin, fluent,
666+
gnome, liquidglass}` under those names (decision 12.1). pythonx-compose puts `org.thisisthepy.compose.material3`
667+
in front of `androidx.compose.material3` and exposes each design system as `pythonx.compose.<name>`
668+
(pythonx-compose #152; leader decision 2026-11-13 on pythonx-compose #54 that they become a dependency here once
669+
published). The design systems build against the fork's Compose at their own version, so these two fixtures
670+
resolve the fork's Compose at 1.11.1-ext.4.
671+
`Status: implemented`:
672+
`fixtures/compose/.../DesignSystemBindingTest.kt` and the `org.thisisthepy.compose.material3` lines of
673+
`.github/scripts/stubs/consumer.py`.
661674

662675
## 7. Threading and builds
663676

‎gradle.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ org.gradle.java.installations.paths=/Volumes/macMini/toolchains/bellsoft-liberic
4646
# compose-multiplatform-core-extended (#191, #249): the Compose modules a native-image build takes from
4747
# the fork instead of upstream, and where from. Read in one place, by the notebook E2E's native image;
4848
# the fork's coordinates and version line are 1.11.1-ext.N, and only these lines follow.
49-
composeExtended.version=1.11.1-ext.2
49+
composeExtended.version=1.11.1-ext.4
5050
# The group the fork publishes under, as a prefix of upstream's (org.thisisthepy.compose).
5151
composeExtended.groupPrefix=org.thisisthepy.compose
5252
composeExtended.modules=org.thisisthepy.compose.ui:ui,org.thisisthepy.compose.ui:ui-desktop,org.thisisthepy.compose.ui:ui-text,org.thisisthepy.compose.ui:ui-text-desktop,org.thisisthepy.compose.foundation:foundation,org.thisisthepy.compose.foundation:foundation-desktop

‎gradle/libs.versions.toml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ androidx-espresso-core = "3.6.1"
1111
androidx-material = "1.12.0"
1212
androidx-test-junit = "1.2.1"
1313
compose-plugin = "1.11.1-ext.3"
14-
compose-libraries = "1.11.1-ext.2"
14+
compose-libraries = "1.11.1-ext.4"
1515
# JetBrains stopped publishing material-icons with Compose after 1.7.3 (Maven Central: newest is 1.7.3);
1616
# it is the version Compose Multiplatform 1.11.x points to, resolved against 1.11.1's ui/ui-graphics.
1717
compose-material-icons = "1.7.3"
@@ -38,6 +38,15 @@ androidx-lifecycle-viewmodel = { group = "org.thisisthepy.compose.androidx.lifec
3838
androidx-lifecycle-runtime-compose = { group = "org.thisisthepy.compose.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "compose-libraries" }
3939
kotlinx-coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
4040
kotlinx-browser = { group = "org.jetbrains.kotlinx", name = "kotlinx-browser", version.ref = "kotlinx-browser" }
41+
# The fork's design systems (compose-multiplatform-core-extended `extended/design-systems`, issue #408).
42+
designsystem = { group = "org.thisisthepy.compose.designsystem", name = "designsystem", version.ref = "compose-libraries" }
43+
designsystem-material3 = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-material3", version.ref = "compose-libraries" }
44+
designsystem-breeze = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-breeze", version.ref = "compose-libraries" }
45+
designsystem-cupertino = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-cupertino", version.ref = "compose-libraries" }
46+
designsystem-deepin = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-deepin", version.ref = "compose-libraries" }
47+
designsystem-fluent = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-fluent", version.ref = "compose-libraries" }
48+
designsystem-gnome = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-gnome", version.ref = "compose-libraries" }
49+
designsystem-liquid-glass = { group = "org.thisisthepy.compose.designsystem", name = "designsystem-liquid-glass", version.ref = "compose-libraries" }
4150

4251
[plugins]
4352
android-application = { id = "com.android.application", version.ref = "agp" }

‎python-multiplatform-compose/fixtures/compose/build.gradle.kts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ kotlin {
5858
exclude(group = "org.jetbrains.compose.runtime")
5959
exclude(group = "org.jetbrains.compose.ui")
6060
}
61+
// The fork's design systems (issue #408): `pythonx.compose.material3` puts
62+
// `org.thisisthepy.compose.material3` in front of `androidx.compose.material3`, and
63+
// `pythonx.compose.<name>` is each of these (pythonx-compose `pythonx-map.toml`).
64+
implementation(libs.designsystem)
65+
implementation(libs.designsystem.material3)
66+
implementation(libs.designsystem.breeze)
67+
implementation(libs.designsystem.cupertino)
68+
implementation(libs.designsystem.deepin)
69+
implementation(libs.designsystem.fluent)
70+
implementation(libs.designsystem.gnome)
71+
implementation(libs.designsystem.liquid.glass)
6172
implementation(compose.desktop.currentOs)
6273
}
6374
}
@@ -123,6 +134,15 @@ pythonBindings {
123134
// Python calls inside a composition. Its file facade, not the package, so that the host
124135
// composables (`PythonAppView` and friends) stay out of the table.
125136
"python.multiplatform.compose.RememberSaveableKt",
137+
// 8. The fork's design systems (issue #408), one package each.
138+
"org.thisisthepy.compose.designsystem",
139+
"org.thisisthepy.compose.material3",
140+
"org.thisisthepy.compose.breeze",
141+
"org.thisisthepy.compose.cupertino",
142+
"org.thisisthepy.compose.deepin",
143+
"org.thisisthepy.compose.fluent",
144+
"org.thisisthepy.compose.gnome",
145+
"org.thisisthepy.compose.liquidglass",
126146
),
127147
)
128148
// Stubs on: `generatePythonStubs` over the real Compose jars is what `.github/scripts/stubs/check-stubs.sh` (the mypy
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package fixture.compose
2+
3+
import python.multiplatform.ffi.Python3
4+
import python.multiplatform.ffi.pythonx.PythonxAdapter
5+
import python.multiplatform.ffi.upcall.UpcallBootstrap
6+
import python.multiplatform.generated.artifacts.ArtifactTable
7+
import python.multiplatform.reflection.UpcallTable
8+
import kotlin.test.AfterTest
9+
import kotlin.test.BeforeTest
10+
import kotlin.test.Test
11+
12+
/**
13+
* SPEC B-12 (issue #408): the fork's design systems (`org.thisisthepy.compose.designsystem:*`) are
14+
* walked, each under its own Kotlin package, so pythonx-compose's `pythonx.compose.material3` (the
15+
* design system in front of `androidx.compose.material3`) and `pythonx.compose.<name>` resolve.
16+
*
17+
* Each package must answer with the declaration that names the system; `materialDesignSystem` and
18+
* `MaterialButton` are checked parameter by parameter, by their Kotlin names, because pythonx-compose
19+
* calls them. Without the dependency or the walked package, the import fails.
20+
*/
21+
class DesignSystemBindingTest {
22+
23+
@BeforeTest
24+
fun installProducers() {
25+
Python3.initialize(silent = true)
26+
UpcallTable.clear()
27+
UpcallTable.install(ArtifactTable.fragments)
28+
check(UpcallBootstrap.publishToGlobals()) { "UpcallBootstrap.publishToGlobals() failed" }
29+
PythonxAdapter.install(PYTHONX_RAW_VALUE_CLASSES)
30+
}
31+
32+
@AfterTest
33+
fun cleanup() {
34+
UpcallTable.clear()
35+
}
36+
37+
@Test
38+
fun everyDesignSystemPackageIsBoundUnderItsKotlinName() {
39+
Python3.exec(
40+
"""
41+
import importlib as _ds_il
42+
_ds_expected = {
43+
'org.thisisthepy.compose.designsystem': 'LocalDesignSystem',
44+
'org.thisisthepy.compose.material3': 'Material3DesignSystem',
45+
'org.thisisthepy.compose.breeze': 'BreezeDesignSystem',
46+
'org.thisisthepy.compose.cupertino': 'CupertinoDesignSystem',
47+
'org.thisisthepy.compose.deepin': 'DeepinDesignSystem',
48+
'org.thisisthepy.compose.fluent': 'FluentDesignSystem',
49+
'org.thisisthepy.compose.gnome': 'GnomeDesignSystem',
50+
'org.thisisthepy.compose.liquidglass': 'LiquidGlass',
51+
}
52+
_ds_missing = {}
53+
for _ds_package, _ds_name in _ds_expected.items():
54+
_ds_module = _ds_il.import_module(_ds_package)
55+
if _ds_name not in dir(_ds_module):
56+
_ds_missing[_ds_package] = sorted(n for n in dir(_ds_module) if not n.startswith('_'))[:20]
57+
assert not _ds_missing, _ds_missing
58+
""".trimIndent(),
59+
)
60+
}
61+
62+
@Test
63+
fun theMaterialDesignSystemFunctionsCarryTheirKotlinParameters() {
64+
Python3.exec(
65+
"""
66+
import python_multiplatform as _ds_pm
67+
import org.thisisthepy.compose.material3 as _ds_m3
68+
69+
_ds_d = _ds_pm.describe(_ds_m3, 'materialDesignSystem')
70+
assert [(_p['name'], _p['type']) for _p in _ds_d['parameters']] == \
71+
[('isDark', 'kotlin.Boolean')], _ds_d
72+
73+
_ds_b = _ds_pm.describe(_ds_m3, 'MaterialButton')
74+
assert [_p['name'] for _p in _ds_b['parameters']] == \
75+
['variant', 'onClick', 'modifier', 'enabled', 'content'], _ds_b
76+
assert _ds_b['parameters'][0]['type'] == 'org.thisisthepy.compose.designsystem.ButtonVariant', _ds_b
77+
""".trimIndent(),
78+
)
79+
}
80+
}

‎python-multiplatform-compose/fixtures/notebook-e2e/build.gradle.kts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ kotlin {
6161
exclude(group = "org.jetbrains.compose.runtime")
6262
exclude(group = "org.jetbrains.compose.ui")
6363
}
64+
// The fork's design systems (issue #408): `pythonx.compose.material3` puts
65+
// `org.thisisthepy.compose.material3` in front of `androidx.compose.material3`, and
66+
// `pythonx.compose.<name>` is each of these (pythonx-compose `pythonx-map.toml`).
67+
implementation(libs.designsystem)
68+
implementation(libs.designsystem.material3)
69+
implementation(libs.designsystem.breeze)
70+
implementation(libs.designsystem.cupertino)
71+
implementation(libs.designsystem.deepin)
72+
implementation(libs.designsystem.fluent)
73+
implementation(libs.designsystem.gnome)
74+
implementation(libs.designsystem.liquid.glass)
6475
implementation(compose.desktop.currentOs)
6576
}
6677
}
@@ -98,6 +109,15 @@ pythonBindings {
98109
"androidx.compose.foundation.text.input.TextFieldState",
99110
"androidx.compose.foundation.text.input.TextFieldStateKt",
100111
"python.multiplatform.compose.RememberSaveableKt",
112+
// The fork's design systems (issue #408), one package each.
113+
"org.thisisthepy.compose.designsystem",
114+
"org.thisisthepy.compose.material3",
115+
"org.thisisthepy.compose.breeze",
116+
"org.thisisthepy.compose.cupertino",
117+
"org.thisisthepy.compose.deepin",
118+
"org.thisisthepy.compose.fluent",
119+
"org.thisisthepy.compose.gnome",
120+
"org.thisisthepy.compose.liquidglass",
101121
),
102122
)
103123
}

‎python-multiplatform-gradle-plugin/src/main/kotlin/python/multiplatform/gradle/artifact/ArtifactScanner.kt‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ internal object ArtifactScanner {
462462
functions = functionsOf(metadata.kmPackage),
463463
ownerNode = node,
464464
classpath = classpath,
465-
) + extensionPropertyCandidates(metadata.kmPackage, node, owner, classpath)
465+
) + extensionPropertyCandidates(metadata.kmPackage, node, owner, classpath) +
466+
constantsOf(metadata.kmPackage.properties, node, boundOwner = owner, callOwner = owner, classpath = classpath, ownerIsClass = false)
466467
}
467468
is KotlinClassMetadata.MultiFileClassFacade -> metadata.partClassNames.flatMap { partBinaryName ->
468469
val partNode = classpath.classNode(partBinaryName) ?: return@flatMap emptyList()
@@ -475,7 +476,8 @@ internal object ArtifactScanner {
475476
functions = functionsOf(partMetadata.kmPackage),
476477
ownerNode = partNode,
477478
classpath = classpath,
478-
) + extensionPropertyCandidates(partMetadata.kmPackage, partNode, owner, classpath)
479+
) + extensionPropertyCandidates(partMetadata.kmPackage, partNode, owner, classpath) +
480+
constantsOf(partMetadata.kmPackage.properties, partNode, boundOwner = owner, callOwner = owner, classpath = classpath, ownerIsClass = false)
479481
}
480482
// A lone part is package-private and never reaches here on its own (the `ACC_PUBLIC`
481483
// guard above already excluded it) -- only through the facade case, which fetches it by
@@ -875,7 +877,23 @@ internal object ArtifactScanner {
875877
boundOwner: String,
876878
callOwner: String,
877879
classpath: ArtifactClasspath,
878-
): List<Candidate> = kmClass.properties.mapNotNull { property ->
880+
): List<Candidate> = constantsOf(
881+
properties = kmClass.properties,
882+
declaringNode = declaringNode,
883+
boundOwner = boundOwner,
884+
callOwner = callOwner,
885+
classpath = classpath,
886+
ownerIsClass = true,
887+
)
888+
889+
private fun constantsOf(
890+
properties: List<kotlin.metadata.KmProperty>,
891+
declaringNode: ClassNode,
892+
boundOwner: String,
893+
callOwner: String,
894+
classpath: ArtifactClasspath,
895+
ownerIsClass: Boolean = true,
896+
): List<Candidate> = properties.mapNotNull { property ->
879897
if (property.visibility != Visibility.PUBLIC) return@mapNotNull null
880898
if (property.receiverParameterType != null) return@mapNotNull null
881899
// A `@Composable get()` reads the composition, so its value does not exist outside one --
@@ -928,7 +946,7 @@ internal object ArtifactScanner {
928946
declaration = DeclarationModel(
929947
simpleName = property.name,
930948
owner = boundOwner,
931-
ownerIsClass = true,
949+
ownerIsClass = ownerIsClass,
932950
receiver = null,
933951
parameters = emptyList(),
934952
returnType = returnModel,

‎python-multiplatform-gradle-plugin/src/main/kotlin/python/multiplatform/gradle/stubs/PyiRendering.kt‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,49 @@ private class StubRenderer(declarations: List<DeclarationModel>) {
280280
/** Class qualified name -> its bound constructors, in table-key order; filled by [renderModuleDefs]. */
281281
private val constructorsByClass = sortedMapOf<String, MutableList<DeclarationModel>>()
282282

283+
private val supertypes: Map<String, List<String>> = bound
284+
.filter { it.returnSupertypes.isNotEmpty() }
285+
.groupBy { it.returnType.qualifiedName }
286+
.mapValues { (_, entries) -> entries.first().returnSupertypes }
287+
283288
/**
284-
* Module prefixes (every module and every directory above it) that name one directory on a
285-
* case-insensitive filesystem together with a sibling (issue #44). In each such group the
286-
* all-lower-case spelling keeps its path -- a Kotlin package -- and every other spelling is a
287-
* class module that is emitted inside its parent package's `__init__.pyi` instead.
289+
* Module prefixes folded into their parent package's `__init__.pyi`.
290+
*
291+
* Two reasons fold a class module into its parent:
292+
* (a) Case-insensitive path collision with a sibling (issue #44): in each such group the
293+
* all-lower-case spelling keeps its path -- a Kotlin package -- and every other spelling
294+
* is a class module emitted inside its parent package's `__init__.pyi`.
295+
* (b) A receiver class (with instance methods or properties and a companion handle) whose companion
296+
* module only publishes constants (`Material3DesignSystem.Dark`), where the runtime
297+
* (`class_wins_over_module`, issue #322) serves the class on the parent package and the constants
298+
* on the class, provided `module` is not a supertype of another bound type (so an interface like
299+
* `DrawScope` stays a module while a concrete receiver class like `Material3DesignSystem` is folded).
288300
*/
289301
private val foldedPrefixes: Set<String> = run {
290302
val prefixes = byModule.keys.flatMap { module ->
291303
val parts = module.split('.')
292304
parts.indices.map { parts.take(it + 1).joinToString(".") }
293305
}.toSet()
294-
prefixes.groupBy { it.lowercase() }.values
306+
val caseColliding = prefixes.groupBy { it.lowercase() }.values
295307
.filter { it.size > 1 }
296308
.flatten()
297309
.filter { '.' in it && it.substringAfterLast('.') != it.substringAfterLast('.').lowercase() }
298310
.toSet()
311+
val allSupertypes = supertypes.values.flatten().toSet()
312+
val companionConstantClasses = byModule.keys.filter { module ->
313+
module !in allSupertypes &&
314+
module in companionHandles &&
315+
(module in methods || module in properties) &&
316+
byModule[module]?.all { it.kind == "STATIC_GETTER" } == true &&
317+
module.substringAfterLast('.') !in takenNames[module.substringBeforeLast('.', "")].orEmpty() &&
318+
run {
319+
val prefix = "$module."
320+
bound.none { it.returnType.qualifiedName.startsWith(prefix) || it.owner.startsWith(prefix) } &&
321+
methods.keys.none { it.startsWith(prefix) } &&
322+
properties.keys.none { it.startsWith(prefix) }
323+
}
324+
}.toSet()
325+
caseColliding + companionConstantClasses
299326
}
300327

301328
/** The shortest folded prefix of [module] (the module itself included), or `null` if it keeps its own path. */
@@ -307,11 +334,6 @@ private class StubRenderer(declarations: List<DeclarationModel>) {
307334
/** The modules that are still files: a folded class module is a class, not a module, for `classReference`. */
308335
private val moduleNames: Set<String> = byModule.keys.filter { foldedPrefixOf(it) == null }.toSet()
309336

310-
private val supertypes: Map<String, List<String>> = bound
311-
.filter { it.returnSupertypes.isNotEmpty() }
312-
.groupBy { it.returnType.qualifiedName }
313-
.mapValues { (_, entries) -> entries.first().returnSupertypes }
314-
315337
// ----------------------------------------------------------------------- per-module output
316338

317339
private class ClassNode(val name: String) {

0 commit comments

Comments
 (0)