-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
171 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
Gradle PyPi publisher extension | ||
Created: 23rd April, 2021 | ||
License: MIT - Please refer to <https://opensource.org/licenses/MIT> | ||
Copyright·(c)·2024,·HSPyLib | ||
*/ | ||
|
||
import groovy.json.JsonSlurper | ||
|
||
ext { | ||
pypiRepository = System.getenv("PYPI_REPOSITORY") ?: 'https://test.pypi.org/legacy' | ||
pypiModuleUrl = System.getenv("PYPI_MODULE_URL") ?: 'https://test.pypi.org/pypi' | ||
pypiUsername = System.getenv("PYPI_USERNAME") ?: '' | ||
pypiPassword = System.getenv("PYPI_PASSWORD") ?: '' | ||
} | ||
|
||
|
||
/* Helper Functions -------------------------------------------------------- */ | ||
|
||
Collection dirsByPattern(String baseDir, String pattern) { | ||
def paths = [] | ||
fileTree(baseDir).visit { FileVisitDetails details -> | ||
if (details.isDirectory() && details.name ==~ pattern) paths << details.file.path | ||
} | ||
return paths | ||
} | ||
|
||
String dirName(File file) { | ||
file.getParentFile().getPath() | ||
} | ||
|
||
/* Tasks ------------------------------------------------------------------- */ | ||
|
||
/* Cleanup distribution files from sourceRoot */ | ||
task cleanDist(type: Task) { | ||
group = 'Build' | ||
description = "Cleanup distribution files from sourceRoot" | ||
doLast { | ||
println "Cleanup distribution files \n\t from $sourceRoot" | ||
delete dirsByPattern(sourceRoot, /.*dist$/) | ||
delete dirsByPattern(sourceRoot, /.*build$/) | ||
delete dirsByPattern(sourceRoot, /.*egg-info$/) | ||
} | ||
} | ||
|
||
/* Copy LICENSE and README files into main folder */ | ||
task copyLicenseAndReadme(type: Copy) { | ||
group = 'Publish' | ||
description = "Copy LICENSE file into main folder" | ||
from(rootDir) { | ||
include 'LICENSE*' | ||
include 'README*' | ||
} | ||
into "${sourceRoot}/main" | ||
} | ||
|
||
/* Check files created in dist folder */ | ||
task checkDist(type: Task) { | ||
group = 'Publish' | ||
description = 'Check files created in dist folder' | ||
doLast { | ||
fileTree(sourceRoot).matching { | ||
include "**/setup.py" | ||
}.each { File module -> | ||
def moduleDir = dirName(module) | ||
def distDir = "${moduleDir}/dist" | ||
println "Checking distribution files -> $distDir" | ||
exec { | ||
workingDir moduleDir | ||
commandLine project.python, '-m', 'twine', 'check', "${distDir}/*" | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* Generate PyPi distribution files */ | ||
task sdist(type: Task) { | ||
group = 'Publish' | ||
description = 'Generate PyPi distribution files' | ||
if (!project.hasProperty('no-patch') || !Boolean.valueOf(project.getProperty('no-patch'))) { | ||
dependsOn patchVersion | ||
} | ||
dependsOn cleanDist | ||
dependsOn copyLicenseAndReadme | ||
dependsOn syncRequirements | ||
finalizedBy checkDist | ||
doLast { | ||
fileTree("$sourceRoot").matching { | ||
include "**/setup.py" | ||
}.each { File module -> | ||
def moduleDir = dirName(module) | ||
println "Generating distribution files -> $moduleDir" | ||
exec { | ||
workingDir "$moduleDir" | ||
commandLine project.python, "-m", "build", "--sdist" | ||
} | ||
exec { | ||
workingDir "$moduleDir" | ||
commandLine project.python, "-m", "build", "--wheel" | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* Publish the module to PyPi repository */ | ||
task publish(type: Task) { | ||
group = 'Publish' | ||
description = "Publish the module to PyPi repository" | ||
def url = project.ext.pypiRepository | ||
def un = project.ext.pypiUsername | ||
def pw = project.ext.pypiPassword | ||
doLast { | ||
fileTree("$sourceRoot").matching { | ||
include "**/setup.py" | ||
}.each { File module -> | ||
def moduleDir = dirName(module) | ||
def distDir = "${moduleDir}/dist" | ||
println "--- ${project.name} details ---" | ||
println "|-version: ${project.ext.app_version}" | ||
println "|-setup: ${module}" | ||
println "|-url: ${url}" | ||
println "|-user: ${un}" | ||
println "|-dist: ${distDir}/*" | ||
println '-------------------------------' | ||
println "Publishing module to PyPi => ${url}" | ||
} | ||
exec { | ||
commandLine 'git', 'tag', '-a', "v${app_version}", '-m', "New PyPi version v${app_version}" | ||
} | ||
exec { | ||
commandLine 'git', 'push', 'origin', "v${app_version}" | ||
} | ||
} | ||
} | ||
|
||
/* Show PyPi module details */ | ||
task pypiShow(type: Task) { | ||
group = 'Publish' | ||
description = "Show PyPi module details" | ||
doLast { | ||
def tempDir = System.getenv("TEMP") ?: '/tmp' | ||
def url = project.ext.pypiModuleUrl + "/${app_name}/json" | ||
def outFile = "${tempDir}/${app_name}-info.json" | ||
println("PyPi Instance: " + url) | ||
exec { | ||
commandLine 'curl', '-s', '-o', outFile, url | ||
} | ||
def json = new JsonSlurper().parseText(new File(outFile).getText()) | ||
println("\n--------------------------------------------------------------------------------") | ||
println("|-AppName: ${json.info.package_url}") | ||
println("|-Summary: ${json.info.summary}") | ||
println("|-Version: ${json.info.version}") | ||
println("|-License: ${json.info.license}") | ||
println("|-Python: ${json.info.requires_python}") | ||
println("|-Keywords: \n ${json.info.keywords ? '#' + json.info.keywords.split(',').join(' #') : 'None'}") | ||
println("|-Classifiers: \n ${json.info.classifiers ? '|-' + json.info.classifiers.join('\n |-') : 'None'}") | ||
println("|-Dependencies: \n ${json.info.requires_dist ? '|-' + json.info.requires_dist.join('\n |-') : 'None'} ") | ||
println("--------------------------------------------------------------------------------") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters