From f4417e0055d4e53097018ef3e5b7dda8f1fb7ca2 Mon Sep 17 00:00:00 2001 From: Vitaly Legchilkin Date: Wed, 12 Feb 2025 13:08:59 +0100 Subject: [PATCH] [python] add hatch constants (PY-60410) GitOrigin-RevId: ee70a8086df97880b84fd24de5dea9e4eebfb1bd --- .../intellij/python/hatch/HatchConstants.kt | 44 +++++++++++++++++++ .../com/intellij/python/hatch/HatchRuntime.kt | 10 +++++ .../src/com/intellij/python/hatch/hatch.kt | 8 ++-- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 python/python-hatch/src/com/intellij/python/hatch/HatchConstants.kt diff --git a/python/python-hatch/src/com/intellij/python/hatch/HatchConstants.kt b/python/python-hatch/src/com/intellij/python/hatch/HatchConstants.kt new file mode 100644 index 000000000000..bd67260c6ca5 --- /dev/null +++ b/python/python-hatch/src/com/intellij/python/hatch/HatchConstants.kt @@ -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" + } +} diff --git a/python/python-hatch/src/com/intellij/python/hatch/HatchRuntime.kt b/python/python-hatch/src/com/intellij/python/hatch/HatchRuntime.kt index 754dac64ccd9..43b36e87d55d 100644 --- a/python/python-hatch/src/com/intellij/python/hatch/HatchRuntime.kt +++ b/python/python-hatch/src/com/intellij/python/hatch/HatchRuntime.kt @@ -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. diff --git a/python/python-hatch/src/com/intellij/python/hatch/hatch.kt b/python/python-hatch/src/com/intellij/python/hatch/hatch.kt index 7f7d0fcfdf92..eb5ec2ff4f68 100644 --- a/python/python-hatch/src/com/intellij/python/hatch/hatch.kt +++ b/python/python-hatch/src/com/intellij/python/hatch/hatch.kt @@ -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}", )