Skip to content

Commit

Permalink
chore: Switch to use swagger codegen for python builds
Browse files Browse the repository at this point in the history
  • Loading branch information
petebuletza committed Feb 2, 2024
1 parent 2231614 commit 5da9d35
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 62 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ jobs:
with:
arguments: build
- name: Build with Poetry
working-directory: ./python-client
working-directory: ./generated-python
run: poetry build
- name: Publish package distributions to TestPyPI
if: github.ref == 'refs/heads/dev'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: python-client/dist/
packages-dir: generated-python/dist/
- name: Publish release package to PyPI
if: startsWith(github.ref, 'ref/heads/release')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python-client/dist/
packages-dir: generated-python/dist/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ build.sbt
# swagger
.swagger-codegen/
generated/
generated-python/
python-client/

# intellij
.idea
poetry.lock

.DS_Store
10 changes: 3 additions & 7 deletions PYPI-README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# cachethq-client
A Python package with client-side methods for the Cachet Status Page https://cachethq.io/
A Python client library the Cachet Status Page https://cachethq.io/

This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:

- API version: 1.0.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.PythonPydanticV1ClientCodegen

## Requirements.
## Requirements

Python 3.7+
100 changes: 57 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath('io.swagger.codegen.v3:swagger-codegen:3.0.52')
Expand All @@ -16,7 +15,6 @@ plugins {
id 'maven-publish'
id 'signing'
id 'org.ajoberstar.grgit' version '2.2.1'
id "org.openapi.generator" version "7.2.0"
}

import org.ajoberstar.grgit.Grgit
Expand All @@ -25,9 +23,10 @@ apply from: 'versioning.gradle'

group = applicationGroupId

def codegenOutputDir = "generated"
def codegenSrcDir = codegenOutputDir + "/src/main/java"
def codegenResourceDir = codegenOutputDir + "/src/main/resources"
def codegenJavaDir = "$project.rootDir/generated"
def codegenPythonDir = "$project.rootDir/generated-python"
def codegenJavaSrcDir = codegenJavaDir + "/src/main/java"
def codegenJavaResourceDir = codegenJavaDir + "/src/main/resources"

configurations {
all {
Expand All @@ -46,7 +45,6 @@ configurations {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}

dependencies {
Expand All @@ -55,22 +53,22 @@ dependencies {
implementation 'io.swagger.core.v3:swagger-annotations:2.2.20'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp:logging-interceptor:2.7.5'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.3'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'joda-time:joda-time:2.10'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.1'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'joda-time:joda-time:2.12.6'
implementation 'io.gsonfire:gson-fire:1.9.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.1'
}

sourceSets {
main {
java {
srcDirs = [ codegenSrcDir ]
srcDirs = [ codegenJavaSrcDir ]
}
resources {
srcDirs = [ codegenResourceDir ]
srcDirs = [ codegenJavaResourceDir ]
}
}
}
Expand Down Expand Up @@ -107,7 +105,7 @@ ext {
project.version = getDevVersion()
artifactoryRepo = 'libs-snapshot-local'
} else {
branchVersionIdentifier = gitBranch.replaceAll("[\\W]", "_")
def branchVersionIdentifier = gitBranch.replaceAll("[\\W]", "_")
println 'Building branch: ' + branchVersionIdentifier
project.version = getReleaseVersion(branchVersionIdentifier)
artifactoryRepo = 'libs-release-local'
Expand Down Expand Up @@ -171,45 +169,25 @@ publishing {
}
}

import io.swagger.codegen.v3.config.CodegenConfigurator
import io.swagger.codegen.v3.DefaultGenerator
import io.swagger.codegen.v3.CodegenConfigLoader
import io.swagger.codegen.v3.ClientOptInput
import io.swagger.codegen.v3.ClientOpts
import io.swagger.v3.parser.OpenAPIV3Parser

task copyPyProjectFile(type: Copy, dependsOn: classes) {
into rootProject.projectDir

into('python-client') {
from "${rootProject.projectDir}/pyproject.toml"
from "${rootProject.projectDir}/PYPI-README.md"
}
}

openApiGenerate {
generatorName.set("python-pydantic-v1")
inputSpec.set("$rootDir/swagger.yaml")
outputDir.set("$rootDir/python-client")
packageName.set("cachethq_client")
}

task generateApi {
task generateJavaClient {
FileTree swaggerFiles = fileTree('.') {
include '*.yaml'
include 'swagger.yaml'
}

inputs.files(swaggerFiles)
outputs.dir('generated/src/main/java/com/elyxor/cachethq/model')
outputs.dir('generated/src/main/java/com/elyxor/cachethq/api')
outputs.dir('generated/src/test/java/com/elyxor/cachethq/api')
outputs.dir('generated/gradle/wrapper')
outputs.dir(codegenJavaDir)

doLast {
swaggerFiles.each { File file ->
println "Processing file: " + file
println "Java Client Generator: processing file - " + file
def codegenConfig = CodegenConfigLoader.forName('java')
codegenConfig.setOutputDir(codegenOutputDir)
codegenConfig.setOutputDir(codegenJavaDir)
codegenConfig.setLibrary('okhttp-gson')
def options = new ClientOpts()
options.setProperties([
Expand All @@ -231,11 +209,47 @@ task generateApi {
}
}

compileJava.dependsOn generateApi
generateApi.finalizedBy tasks.openApiGenerate
tasks.openApiGenerate.finalizedBy copyPyProjectFile
task generatePythonClient {
FileTree swaggerFiles = fileTree('.') {
include 'swagger.yaml'
}

inputs.files(swaggerFiles)
outputs.dir(codegenPythonDir)

doLast {
swaggerFiles.each { File file ->
println "Python Client Generator: processing file - " + file
def codegenConfig = CodegenConfigLoader.forName('python')
codegenConfig.setOutputDir(codegenPythonDir)
def options = new ClientOpts()
options.setProperties([
'packageName': 'cachethq_client',
'projectName': 'cachethq-client',
])
def openAPI = new OpenAPIV3Parser().read(file.toString(), null, null)
def clientOpts = new ClientOptInput()
clientOpts.setOpenAPI(openAPI)
clientOpts.setConfig(codegenConfig)
clientOpts.setOpts(options)

new DefaultGenerator().opts(clientOpts).generate()

}
}
}

task copyPyProjectFile(type: Copy) {
from "${rootProject.projectDir}/pyproject.toml"
from "${rootProject.projectDir}/PYPI-README.md"
into(codegenPythonDir)
}

compileJava.dependsOn generateJavaClient
compileJava.dependsOn generatePythonClient
tasks.generatePythonClient.finalizedBy copyPyProjectFile

clean.doFirst {
delete(codegenOutputDir)
delete('python-client')
delete(codegenJavaDir)
delete(codegenPythonDir)
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
artifactMajorVersion = 0
artifactMinorVersion = 1
artifactPatchVersion = 11
artifactMajorVersion = 1
artifactMinorVersion = 0
artifactPatchVersion = 2

applicationGroupId = com.elyxor.cachethq
applicationTitle = Cachet HQ okhttp-gson API Client (java)
Expand Down
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "cachethq_client"
version = "1.0.2"
description = ""
authors = ["cbrand <chris.brandom@elyxor.com>"]
description = "A python client library for connection to a CachetHQ Server"
authors = ["elyxor <info@elyxor.com>"]
readme = "PYPI-README.md"
repository = "https://github.com/ElyxorCorp/cachethq-swagger"
documentation = "https://github.com/ElyxorCorp/cachethq-swagger/tree/dev/api-doc/README.md"
Expand All @@ -14,21 +14,18 @@ include = [
]

[tool.poetry.dependencies]
python = ">=3.7"
python = ">=3.8"
certifi = "^2023.11.17"
six = "^1.16.0"
python-dateutil = "^2.8.2"
setuptools = "^69.0.3"
urllib3 = "^2.1.0"
pydantic = "^1.10.5"
aenum = ">=3.1.11"

[tool.poetry.dev-dependencies]
pytest = ">=7.2.1"
tox = ">=3.9.0"
flake8 = ">=4.0.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit 5da9d35

Please sign in to comment.