[python] add hatch constants (PY-60410)

GitOrigin-RevId: ee70a8086df97880b84fd24de5dea9e4eebfb1bd
This commit is contained in:
Vitaly Legchilkin
2025-02-12 21:19:30 +00:00
committed by intellij-monorepo-bot
parent 5612bb30e7
commit f4417e0055
3 changed files with 58 additions and 4 deletions
@@ -0,0 +1,44 @@
package com.intellij.python.hatch
@Suppress("unused")
object HatchConstants {
object AppEnvVars {
const val ENV: String = "HATCH_ENV"
const val ENV_ACTIVE: String = "HATCH_ENV_ACTIVE"
const val ENV_OPTION_PREFIX: String = "HATCH_ENV_TYPE_"
const val QUIET: String = "HATCH_QUIET"
const val VERBOSE: String = "HATCH_VERBOSE"
const val INTERACTIVE: String = "HATCH_INTERACTIVE"
const val PYTHON: String = "HATCH_PYTHON"
const val NO_COLOR: String = "NO_COLOR" // https://no-color.org
const val FORCE_COLOR: String = "FORCE_COLOR"
}
object ConfigEnvVars {
const val PROJECT: String = "HATCH_PROJECT"
const val DATA: String = "HATCH_DATA_DIR"
const val CACHE: String = "HATCH_CACHE_DIR"
const val CONFIG: String = "HATCH_CONFIG"
}
object PublishEnvVars {
const val USER: String = "HATCH_INDEX_USER"
const val AUTH: String = "HATCH_INDEX_AUTH"
const val REPO: String = "HATCH_INDEX_REPO"
const val CA_CERT: String = "HATCH_INDEX_CA_CERT"
const val CLIENT_CERT: String = "HATCH_INDEX_CLIENT_CERT"
const val CLIENT_KEY: String = "HATCH_INDEX_CLIENT_KEY"
const val PUBLISHER: String = "HATCH_PUBLISHER"
const val OPTIONS: String = "HATCH_PUBLISHER_OPTIONS"
}
object PythonEnvVars {
const val CUSTOM_SOURCE_PREFIX: String = "HATCH_PYTHON_CUSTOM_SOURCE_"
const val CUSTOM_PATH_PREFIX: String = "HATCH_PYTHON_CUSTOM_PATH_"
const val CUSTOM_VERSION_PREFIX: String = "HATCH_PYTHON_CUSTOM_VERSION_"
}
object VersionEnvVars {
const val VALIDATE_BUMP: String = "HATCH_VERSION_VALIDATE_BUMP"
}
}
@@ -25,6 +25,16 @@ class HatchRuntime(
return HatchRuntime(this.hatchBinary, execOptions)
}
fun withBasePythonPath(basePythonPath: Path): HatchRuntime {
val execOptions = with(this.execOptions) {
val modifiedEnv = env + mapOf(
HatchConstants.AppEnvVars.PYTHON to basePythonPath.toString()
)
ExecOptions(modifiedEnv, workingDirectory, processDescription, timeout)
}
return HatchRuntime(this.hatchBinary, execOptions)
}
/**
* Pure execution of [hatchBinary] with command line [arguments] and [execOptions] by [execService]
* Doesn't make any validation of stdout/stderr content.
@@ -8,8 +8,8 @@ import com.intellij.platform.eel.provider.localEel
import com.intellij.python.community.execService.ExecOptions
import com.intellij.python.community.execService.WhatToExec
import com.jetbrains.python.Result
import java.nio.file.Path
import com.jetbrains.python.errorProcessing.PyError
import java.nio.file.Path
sealed class HatchError(message: @NlsSafe String) : PyError.Message(message)
@@ -31,10 +31,10 @@ suspend fun createHatchRuntime(
val hatchExecutable = HatchConfiguration.getOrDetectHatchExecutablePath(eelApi).getOr { return it }
val defaultVariables = mapOf(
HatchConstants.AppEnvVars.NO_COLOR to "1",
HatchConstants.AppEnvVars.VERBOSE to "1",
HatchConstants.AppEnvVars.INTERACTIVE to "0",
"TERM" to "dumb",
"NO_COLOR" to "1",
"HATCH_VERBOSE" to "1",
"HATCH_INTERACTIVE" to "0",
"COLUMNS" to "${0x7FFF}",
"LINES" to "${0x7FFF}",
)