Skip to content

Commit

Permalink
Deploy Python
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpaul committed Dec 11, 2023
1 parent e968026 commit c323e9e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ ext {
setProperty('services', services)
smallServices = services.findAll { it.small }
serviceNaming = services.collectEntries { [it.id, it.name] }
serviceNamingCamel = services.collectEntries {
[it.id, it.name.substring(0, 1).toLowerCase() + it.name.substring(1)]
}
}

// Generate a full client for each service
Expand Down
7 changes: 1 addition & 6 deletions node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ project.ext {
def services = project.ext.services as List<Service>

// Service renaming
Map<String, String> serviceNaming = (project.ext.serviceNaming as Map<String, String>)
.collectEntries {
[it.key, it.value.substring(0, 1).toLowerCase() + it.value.substring(1)]
}

// Service renaming
Map<String, String> serviceNaming = project.ext.serviceNamingCamel
serviceNaming.putAll([
'posterminalmanagement': 'terminalManagement'
])
Expand Down
75 changes: 73 additions & 2 deletions python/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,79 @@
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
id 'adyen.sdk-automation-conventions'
}

project.ext {
// @TODO paths from config file don't work
// configFile = 'templates/config.yaml'
generator = 'python'
removeTags = false
}

List<Service> services = project.ext.services
services.find { it.id == 'payment' }.small = false

// Service renaming
Map<String, String> serviceNaming = project.ext.serviceNamingCamel
serviceNaming.putAll([
'binlookup': 'binlookup',
'payment' : 'payments',
'payout' : 'payouts'
])

services.<Service> each { Service svc ->
String serviceName = serviceNaming[svc.id]

// Generation
tasks.named("generate${svc.name}", GenerateTask) {
configFile.set("$projectDir/config.yaml")
additionalProperties.putAll([
'serviceName': serviceName,
])
}

// Deployment
def deployServices = tasks.register("deploy${svc.name}Services", Sync) {
group 'deploy'
description "Deploy $svc.name into the repo."
dependsOn "generate$svc.name"
outputs.upToDateWhen { false }
onlyIf { !svc.small && !svc.webhook }

from layout.buildDirectory.dir("services/$svc.id/openapi_client/api")
include '*_api.py'
into layout.projectDirectory.dir("repo/Adyen/services/" + serviceName)

from(layout.buildDirectory.dir("services/$svc.id/api")) {
include 'api-single.py'
rename 'api-single.py', '__init__.py'
}
}

def deploySmallService = tasks.register("deploy${svc.name}SmallService", Copy) {
group 'deploy'
description "Copy $svc.name into the repo."
dependsOn "generate$svc.name"
outputs.upToDateWhen { false }
onlyIf { svc.small }

from layout.buildDirectory.file("services/$svc.id/openapi_client/api/default_api-small.py")
rename 'default_api-small.py', "${serviceName}.py"
into layout.projectDirectory.dir("repo/Adyen/services")
}

tasks.named(svc.id) { dependsOn deployServices, deploySmallService }
}

// Tests
tasks.named('checkout') {
doLast {
assert file("${layout.projectDirectory}/repo/Adyen/services/checkout/payments_api.py").exists()
assert file("${layout.projectDirectory}/repo/Adyen/services/checkout/__init__.py").exists()
}
}
tasks.named('binlookup') {
doLast {
assert file("${layout.projectDirectory}/repo/Adyen/services/binlookup.py").exists()
assert !file("${layout.projectDirectory}/repo/Adyen/services/binlookup").exists()
}
}
12 changes: 12 additions & 0 deletions python/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
files:
api-single.mustache:
folder: api
destinationFilename: api-single.py
templateType: SupportingFiles
api-small.mustache:
destinationFilename: -small.py
templateType: API
api-test-single.mustache:
folder: api
destinationFilename: api-test.py
templateType: SupportingFiles

0 comments on commit c323e9e

Please sign in to comment.