Skip to content

Commit

Permalink
Environment fixes and run-configs come back
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Dec 12, 2024
1 parent f39ebea commit d50e47d
Show file tree
Hide file tree
Showing 26 changed files with 599 additions and 63 deletions.
25 changes: 10 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,25 @@
"**/Thumbs.db": true,
"_config.yml": true,
".gradle": true,
".vscode": true,
".idea": true,
".pytest_cache": true,
".gitattributes": true,
".gitconfig": true,
".gitignore": true,
".pylintrc": true,
"buildTools.txt": true,
"AskAI.code-workspace": true,
"gradlew.bat": true,
"gradlew": true,
"bumpver.toml": true,
".editorconfig": true,
"**/__pycache__": true,
"**/__pycache__.*": true,
"**/*.egg-info": true
"**/*.egg-info": true,
".run": true,
".vscode": true,
"run-configs": true,
"AskAI.code-workspace": true,
".gitattributes": true,
".gitconfig": true,
".gitignore": true,
".gitmodules": true
},
"hide-files.files": [],
"cSpell.words": [
"aporetti",
"askai",
"clitt",
"hspylib",
"syserr",
"unior"
]
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "00_Run __main__.py",
"label": "python: Run __main__.py",
"type": "process",
"command": "python3.11",
"args": [
Expand Down
3 changes: 2 additions & 1 deletion AskAI.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
".gitattributes",
".gitconfig",
".gitignore",
".gitmodules"
".gitmodules",
"gradle/wrapper"
],
"cSpell.words": [
"destfile",
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ idea {
}
}

apply from: "${gradleDir}/idea.gradle"
apply from: "${gradleDir}/dependencies.gradle"
apply from: "${gradleDir}/python.gradle"
apply from: "${gradleDir}/versioning.gradle"
Expand Down
51 changes: 30 additions & 21 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ import org.gradle.internal.os.OperatingSystem;
String detectPython() {
def pythonHome = System.getenv('PYTHON_HOME') ?: null
if (pythonHome != null) {
return pythonHome + '/python3'
return pythonHome + '/python3.11'
}

def output = new ByteArrayOutputStream()
exec {
commandLine 'bash', '-c', 'command -v python3'
commandLine 'bash', '-c', 'command -v python3.11'
standardOutput = output
}

pythonHome = output.toString().trim()
assert pythonHome != null && !pythonHome.isEmpty(), "Could not find any installed python3 version"
assert pythonHome != null && !pythonHome.isEmpty(), "Could not find any installed python3.11 version"

print("Python successfully detected: " + pythonHome)

exec {
commandLine python3.11, '-V'
}

return pythonHome
}
Expand Down Expand Up @@ -55,7 +61,7 @@ String detectSpace() {
standardOutput = output
}
def is_venv = Boolean.parseBoolean(output.toString())
println "> Build is" + (is_venv ? ' ' : ' NOT ') + "running under a virtual environment (venv)."
println("> Build is" + (is_venv ? ' ' : ' NOT ') + "running under a virtual environment (venv).")

return is_venv ? '--global' : '--user'
}
Expand All @@ -67,40 +73,40 @@ void readDependencies() {
def dep = null
// Python Packages {
// All fields syntax
if (dep = line =~ /package: (([\w.-]+)(\[[\w.-]+\])?), version: (latest|\d+(\.\d+){0,4}), mode: (lt|le|eq|compat|ne|gt|ge|none)/) {
if ((dep = line =~ /package: (([\w.-]+)(\[[\w.-]+\])?), version: (latest|\d+(\.\d+){0,4}), mode: (lt|le|eq|compat|ne|gt|ge|none)/)) {
dep.each {
deps << [package: "${it[1]}", version: "${it[4]}", mode: "${it[6]}"]
}
}
// All except mode syntax
else if (dep = line =~ /package: (([\w.-]+)(\[[\w.-]+\])?), version: (latest|\d+(\.\d+){0,4})/) {
else if ((dep = line =~ /package: (([\w.-]+)(\[[\w.-]+\])?), version: (latest|\d+(\.\d+){0,4})/)) {
dep.each {
deps << [package: "${it[1]}", version: "${it[4]}", mode: it[4] && it[4] != "latest" ? "compat" : "ge"]
}
}
// Only package syntax
else if (dep = line =~ /package: (([\w.-]+)(\[[\w.-]+\])?)/) {
else if ((dep = line =~ /package: (([\w.-]+)(\[[\w.-]+\])?)/)) {
dep.each {
deps << [package: "${it[1]}", version: "latest", mode: "ge"]
}
}
// } Python Packages
// System Apps {
// All fields syntax
else if (dep = line =~ /binary: (([\w.-]+)(\[[\w.-]+\])?), version: (latest|\d+(\.\d+){0,4})/) {
else if ((dep = line =~ /binary: (([\w.-]+)(\[[\w.-]+\])?), version: (latest|\d+(\.\d+){0,4})/)) {
dep.each {
apps << [binary: "${it[1]}", version: "${it[4]}"]
}
}
// Only binary syntax
else if (dep = line =~ /binary: (([\w.-]+)(\[[\w.-]+\])?)/) {
else if ((dep = line =~ /binary: (([\w.-]+)(\[[\w.-]+\])?)/)) {
dep.each {
apps << [binary: "${it[1]}", version: "latest"]
}
}
// } system Apps
else {
if ( line.startsWith('package: ') ) {
if (line.startsWith('package: ')) {
throw new GradleException("Invalid hspd syntax $line. Usage: "
+ "package: <pkg_name>, version: [<latest>|versionNum], "
+ "[mode: <lt|le|eq|compat|ne|gt|ge|none>]")
Expand All @@ -122,7 +128,7 @@ task listDependencies(type: Task) {
group = 'Dependencies'
description = 'List project dependencies'
doLast {
println "\nListing dependencies from:\n\t${depsFile}\n"
println("\nListing dependencies from:\n\t${depsFile}\n")
readDependencies()
deps.each { dep ->
println(
Expand Down Expand Up @@ -158,15 +164,18 @@ task installPackages(type: Task) {
dependsOn syncRequirements
doLast {
def req_file = new File(reqsFile)
println "\nInstalling \"${project.name}\" dependencies using ${project.python}"
println "Requirements file: \n\t" + req_file
println "Required Packages:"
print("\nInstalling \"${project.name}\" dependencies using: ${project.python} => ")
exec {
commandLine project.python, '-V'
}
println("Requirements file: \n\t" + req_file)
println("Required Packages:")
req_file.each { dep ->
if (dep && ! dep.startsWith("#")) {
println " |-" + dep
println(" |-" + dep)
}
}
println "Space: ${project.space}"
println("Space: ${project.space}")
def args = [
project.python, '-m', 'pip', 'install', '--no-warn-script-location',
project.space, '--upgrade', '-r', req_file.toString(),
Expand All @@ -188,15 +197,15 @@ task removePackages(type: Task) {
dependsOn syncRequirements
doLast {
def req_file = new File("${project.ext.sourceRoot}/main/requirements.txt")
println "\nUninstalling \"${project.name}\" dependencies using ${project.python}"
println "Requirements file: \n\t" + req_file
println "Installed Packages:"
println("\nUninstalling \"${project.name}\" dependencies using ${project.python}")
println("Requirements file: \n\t" + req_file)
println("Installed Packages:")
req_file.each { dep ->
if (dep && ! dep.startsWith("#")) {
println " |-" + dep
println(" |-" + dep)
}
}
println "Space: ${project.space}"
println("Space: ${project.space}")
def args = [
project.python, '-m', 'pip', 'uninstall', '-y',
'-r', req_file.toString(), '--break-system-packages'
Expand Down
6 changes: 3 additions & 3 deletions gradle/docgen.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ task syncFileHeaders(type: Task) {
finalizedBy optimizeImports
doLast {
def replaceHeaders = project.hasProperty("replaceHeaders")
println "Synchronizing python headers replace: ${replaceHeaders}"
println("Synchronizing python headers replace: ${replaceHeaders}")
def files = filesByPattern(sourceRoot, /.*(?<!__init__)\.py$/)
files.each {
println "Processing file: ${it}"
println("Processing file: ${it}")
def fh_file = new File(it)
def headers = processPythonHeader(fh_file, PY_FILE_HEADER)
def parseState = 'headers' // headers -> imports -> code
Expand Down Expand Up @@ -127,6 +127,6 @@ task syncFileHeaders(type: Task) {
}
fh_file.setText("${has_old_headers ? old_headers.join('\n') : headers }\n${imports.join('\n')}${code.join('\n')}\n")
}
println "Finished processing all python files"
println("Finished processing all python files")
}
}
37 changes: 37 additions & 0 deletions gradle/idea.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Gradle IDEA extension
Created: 18th April, 2023
License: MIT - Please refer to <https://opensource.org/licenses/MIT>
Copyright·(c)·2024,·HSPyLib
*/

/* Export Run Configurations */
task exportRunConfigurations(type: Copy) {
group = 'Idea'
description = "Export run configurations"
from("${rootDir}/.idea/runConfigurations") {
include '*.xml'
}
into "${rootDir}/run-configs/idea"
}

/* Import Run Configurations */
task importRunConfigurations(type: Copy) {
group = 'Idea'
description = "Import run configurations"
from("${rootDir}/run-configs/idea") {
include '*.xml'
}
into "${rootDir}/.idea/runConfigurations"
}

/* Clear Run Configurations */
task clearRunConfigurations(type: Delete) {
group = 'Idea'
description = "Delete all run configurations"
delete fileTree("${rootDir}/.idea/runConfigurations") {
include "**/*.xml"
}
followSymlinks = true
}
2 changes: 1 addition & 1 deletion gradle/pypi-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ task checkDist(type: Task) {
include "**/setup.py"
}.each { File module ->
def distDir = "${buildDir}/dist"
println "Checking distribution files -> ${buildDir}"
println("Checking distribution files -> ${buildDir}")
exec {
workingDir buildDir
commandLine project.python, '-m', 'twine', 'check', "${distDir}/*"
Expand Down
Loading

0 comments on commit d50e47d

Please sign in to comment.