cleanup [python]: hide implementation details

GitOrigin-RevId: ee75d9d12e9029cea86c668edd996339d59c0a9c
This commit is contained in:
Ilya.Kazakevich
2026-06-09 18:39:25 +00:00
committed by intellij-monorepo-bot
parent 71f2147a5e
commit 9a3b4166f8
18 changed files with 52 additions and 49 deletions
+4 -3
View File
@@ -40,7 +40,10 @@ jvm_library(
],
allow_empty = True,
),
module_name = "intellij.python.test.env.junit5",
associates = [
"//python:python-community-impl",
"//python:python-community-impl_test_lib",
],
resource_strip_prefix = "resources",
resources = glob(
["resources/**/*"],
@@ -82,8 +85,6 @@ jvm_library(
"//python/python-sdk:sdk_test_lib",
"//python/junit5Tests-framework:community-junit5Tests-framework",
"//python/junit5Tests-framework:community-junit5Tests-framework_test_lib",
"//python:python-community-impl",
"//python:python-community-impl_test_lib",
"//platform/execution",
"//platform/execution:execution_test_lib",
"//python/python-test-env/conda",
@@ -34,4 +34,5 @@
<orderEntry type="module" module-name="intellij.platform.testFramework.common" scope="TEST" />
<orderEntry type="module" module-name="intellij.python.community.services.systemPython" scope="TEST" />
</component>
<component name="TestModuleProperties" production-module="intellij.python.community.impl" />
</module>
@@ -25,7 +25,7 @@ internal class HatchSdkFlavorProvider : PythonFlavorProvider {
override fun getFlavor(): PythonSdkFlavor<*> = HatchSdkFlavor
}
class HatchSdkAdditionalData(
internal class HatchSdkAdditionalData(
val hatchWorkingDirectory: Path?,
val hatchEnvironmentName: String?,
) : PythonSdkAdditionalData(PyFlavorAndData(data = HatchSdkFlavorData, flavor = HatchSdkFlavor)) {
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.ApiStatus
import java.nio.file.Path
@ApiStatus.Internal
suspend fun HatchVirtualEnvironment.createSdk(workingDirectoryPath: Path): PyResult<Sdk> {
internal suspend fun HatchVirtualEnvironment.createSdk(workingDirectoryPath: Path): PyResult<Sdk> {
if (pythonVirtualEnvironment !is PythonVirtualEnvironment.Existing) {
return Result.failure(BasePythonExecutableNotFoundHatchError(null as String?))
}
@@ -61,7 +61,7 @@ private val POETRY_TOOL: ToolCommandExecutor = ToolCommandExecutor(
private val POETRY_EXCLUDE_NON_DIGITS_REGEX = Regex("""\D+$""")
@Internal
suspend fun runPoetry(
internal suspend fun runPoetry(
projectPath: Path?,
vararg args: String,
inProjectEnv: Boolean? = null,
@@ -84,14 +84,14 @@ suspend fun runPoetry(
* Returns the configured poetry executable or detects it automatically on the given [fileSystem].
*/
@Internal
suspend fun <P : PathHolder> getPoetryExecutable(fileSystem: FileSystem<P>): P? =
internal suspend fun <P : PathHolder> getPoetryExecutable(fileSystem: FileSystem<P>): P? =
POETRY_TOOL.getToolExecutable(fileSystem, pathFromSdk = null)
/**
* Returns the configured poetry executable or detects it automatically.
*/
@Internal
suspend fun getPoetryExecutable(eel: EelApi = localEel): Path? =
internal suspend fun getPoetryExecutable(eel: EelApi = localEel): Path? =
getPoetryExecutable(EelFileSystem(eel))?.path
/**
@@ -101,7 +101,7 @@ suspend fun getPoetryExecutable(eel: EelApi = localEel): Path? =
* 2. `poetry [args]`
*/
@Internal
suspend fun runPoetryWithSdk(sdk: Sdk, vararg args: String): PyResult<String> {
internal suspend fun runPoetryWithSdk(sdk: Sdk, vararg args: String): PyResult<String> {
val projectPath = sdk.associatedModulePath?.let { Path.of(it) }
?: return PyResult.localizedError(poetryNotFoundException) // Choose a correct sdk
val pythonHomePath = sdk.pyRichSdkAsync().pythonHomePath
@@ -121,7 +121,7 @@ suspend fun runPoetryWithSdk(sdk: Sdk, vararg args: String): PyResult<String> {
* @return the path to the poetry environment.
*/
@Internal
suspend fun setupPoetry(
internal suspend fun setupPoetry(
projectPath: Path,
basePythonBinaryPath: PythonBinary,
installPackages: Boolean,
@@ -181,13 +181,13 @@ private suspend fun getPythonExecutable(homePathString: String): PythonBinary? =
* @param [extraArgs] Additional arguments to pass to the Poetry add command.
*/
@Internal
suspend fun poetryInstallPackage(sdk: Sdk, packages: List<String>, extraArgs: List<String>): PyResult<String> {
internal suspend fun poetryInstallPackage(sdk: Sdk, packages: List<String>, extraArgs: List<String>): PyResult<String> {
val args = listOf("add") + packages + extraArgs
return runPoetryWithSdk(sdk, *args.toTypedArray())
}
@Internal
suspend fun poetryInstallPackageDetached(sdk: Sdk, packages: List<String>, extraArgs: List<String>): PyResult<String> {
internal suspend fun poetryInstallPackageDetached(sdk: Sdk, packages: List<String>, extraArgs: List<String>): PyResult<String> {
val args = listOf("run", "pip", "install") + packages + extraArgs
return runPoetryWithSdk(sdk, *args.toTypedArray())
}
@@ -199,7 +199,7 @@ suspend fun poetryInstallPackageDetached(sdk: Sdk, packages: List<String>, extra
* @param [packages] The name of the package to be uninstalled.
*/
@Internal
suspend fun poetryRemovePackage(sdk: Sdk, vararg packages: String): PyResult<String> = runPoetryWithSdk(sdk, "remove", *packages)
internal suspend fun poetryRemovePackage(sdk: Sdk, vararg packages: String): PyResult<String> = runPoetryWithSdk(sdk, "remove", *packages)
@Internal
suspend fun poetryUninstallPackage(sdk: Sdk, vararg packages: String): PyResult<String> {
@@ -208,7 +208,7 @@ suspend fun poetryUninstallPackage(sdk: Sdk, vararg packages: String): PyResult<
}
@Internal
fun parsePoetryShow(input: String): List<PythonPackage> {
internal fun parsePoetryShow(input: String): List<PythonPackage> {
val result = mutableListOf<PythonPackage>()
input.split("\n").forEach { line ->
if (line.isNotBlank()) {
@@ -221,14 +221,14 @@ fun parsePoetryShow(input: String): List<PythonPackage> {
}
@Internal
suspend fun poetryShowOutdated(sdk: Sdk): PyResult<Map<String, PythonOutdatedPackage>> {
internal suspend fun poetryShowOutdated(sdk: Sdk): PyResult<Map<String, PythonOutdatedPackage>> {
val output = runPoetryWithSdk(sdk, "show", "--all", "--outdated").getOr { return it }
return parsePoetryShowOutdated(output).let { PyResult.success(it) }
}
@Internal
suspend fun poetryListPackages(sdk: Sdk): PyResult<Pair<List<PyPackage>, List<PyRequirement>>> {
internal suspend fun poetryListPackages(sdk: Sdk): PyResult<Pair<List<PyPackage>, List<PyRequirement>>> {
val version = getPoetryVersion()?.toVersion()
// Ensure that the lock file is up to date.
@@ -244,7 +244,7 @@ suspend fun poetryListPackages(sdk: Sdk): PyResult<Pair<List<PyPackage>, List<Py
}
@Internal
suspend fun checkLock(sdk: Sdk, version: Version?): Boolean {
internal suspend fun checkLock(sdk: Sdk, version: Version?): Boolean {
// From Poetry 1.6.0 and forward, `poetry check --lock` should be used to figure out the validity of the lock file.
// However, this command fails whenever a README file (as described in pyproject.toml) is absent, without even checking the lock file.
// The old command, albeit deprecated, doesn't check for the README; instead, it only checks for the validity of the lock file.
@@ -257,7 +257,7 @@ suspend fun checkLock(sdk: Sdk, version: Version?): Boolean {
}
@Internal
suspend fun fixLock(sdk: Sdk, version: Version?): PyResult<String> {
internal suspend fun fixLock(sdk: Sdk, version: Version?): PyResult<String> {
if (version == null || version >= VERSION_2) {
return runPoetryWithSdk(sdk, "lock")
}
@@ -266,7 +266,7 @@ suspend fun fixLock(sdk: Sdk, version: Version?): PyResult<String> {
}
@Internal
fun parsePoetryInstallDryRun(input: String): Pair<List<PyPackage>, List<PyRequirement>> {
internal fun parsePoetryInstallDryRun(input: String): Pair<List<PyPackage>, List<PyRequirement>> {
val installedLines = listOf("Already installed", "Skipping", "Updating", "Downgrading")
fun getNameAndVersion(line: String): Triple<String, String, String> {
@@ -313,7 +313,7 @@ fun parsePoetryInstallDryRun(input: String): Pair<List<PyPackage>, List<PyRequir
* @param [args] A vararg array of String arguments to pass to the Poetry configuration command.
*/
@Internal
suspend fun configurePoetryEnvironment(modulePath: Path?, vararg args: String) {
internal suspend fun configurePoetryEnvironment(modulePath: Path?, vararg args: String) {
runPoetry(modulePath, "config", *args)
}
@@ -9,6 +9,6 @@ import com.jetbrains.python.packaging.management.PythonPackageManagerProvider
* This source code is created by @koxudaxi Koudai Aono <koxudaxi@gmail.com>
*/
class PoetryPackageManagerProvider : PythonPackageManagerProvider {
internal class PoetryPackageManagerProvider : PythonPackageManagerProvider {
override fun createPackageManagerForSdk(project: Project, sdk: Sdk): PythonPackageManager? = if (sdk.isPoetry) PoetryPackageManager(project, sdk) else null
}
@@ -9,7 +9,7 @@ import java.nio.file.Path
* This source code is edited by @koxudaxi Koudai Aono <koxudaxi@gmail.com>
*/
class PyPoetrySdkAdditionalData : PythonSdkAdditionalData {
internal class PyPoetrySdkAdditionalData : PythonSdkAdditionalData {
constructor(associatedModulePath: Path?) : super(PyPoetrySdkFlavor) {
this.associatedModulePath = associatedModulePath?.toString()
}
@@ -5,6 +5,7 @@ import com.intellij.python.community.impl.poetry.common.icons.PythonCommunityImp
import com.jetbrains.python.sdk.flavors.CPythonSdkFlavor
import com.jetbrains.python.sdk.flavors.PyFlavorData
import com.jetbrains.python.sdk.flavors.PythonFlavorProvider
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor
import java.nio.file.Path
import javax.swing.Icon
@@ -13,13 +14,13 @@ import javax.swing.Icon
* This source code is edited by @koxudaxi Koudai Aono <koxudaxi@gmail.com>
*/
object PyPoetrySdkFlavor : CPythonSdkFlavor<PyFlavorData.Empty>() {
internal object PyPoetrySdkFlavor : CPythonSdkFlavor<PyFlavorData.Empty>() {
override fun getIcon(): Icon = PythonCommunityImplPoetryCommonIcons.Poetry
override fun getFlavorDataClass(): Class<PyFlavorData.Empty> = PyFlavorData.Empty::class.java
override fun isValidSdkPath(pythonBinaryPath: Path): Boolean = false
}
class PyPoetrySdkFlavorProvider : PythonFlavorProvider {
override fun getFlavor(): PyPoetrySdkFlavor = PyPoetrySdkFlavor
internal class PyPoetrySdkFlavorProvider : PythonFlavorProvider {
override fun getFlavor(): PythonSdkFlavor<*> = PyPoetrySdkFlavor
}
@@ -23,11 +23,11 @@ import kotlin.io.path.pathString
@Internal
fun suggestedSdkName(basePath: Path): @NlsSafe String = "Poetry (${PathUtil.getFileName(basePath.pathString)})"
internal fun suggestedSdkName(basePath: Path): @NlsSafe String = "Poetry (${PathUtil.getFileName(basePath.pathString)})"
@Internal
suspend fun createNewPoetrySdk(
internal suspend fun createNewPoetrySdk(
moduleBasePath: Path,
basePythonBinaryPath: PythonBinary,
installPackages: Boolean,
@@ -43,7 +43,7 @@ suspend fun createNewPoetrySdk(
}
@Internal
suspend fun createPoetrySdk(
internal suspend fun createPoetrySdk(
basePath: Path,
pythonBinaryPath: PathHolder.Eel,
): PyResult<Sdk> = withProgressText(PyBundle.message("python.sdk.progress.poetry.configuring")) {
@@ -69,7 +69,7 @@ private suspend fun setUpPoetry(moduleBasePath: Path, basePythonBinaryPath: Pyth
return PyResult.success(pythonBinaryPath)
}
fun parsePoetryShowOutdated(input: String): Map<String, PythonOutdatedPackage> {
internal fun parsePoetryShowOutdated(input: String): Map<String, PythonOutdatedPackage> {
return input
.lines()
.map { it.trim() }
+3 -3
View File
@@ -13,12 +13,12 @@ import org.jetbrains.annotations.ApiStatus
import java.nio.file.Path
@ApiStatus.Internal
interface UvCli<P : PathHolder> {
internal interface UvCli<P : PathHolder> {
suspend fun runUv(workingDir: Path, venvPath: P?, canChangeTomlOrLock: Boolean, vararg args: String): PyResult<String>
}
@ApiStatus.Internal
interface UvLowLevel<P : PathHolder> {
internal interface UvLowLevel<P : PathHolder> {
suspend fun initializeEnvironment(init: Boolean, version: Version?, clearExisting: Boolean = false): PyResult<P>
suspend fun listUvPythons(): PyResult<Set<Path>>
@@ -50,7 +50,7 @@ interface UvLowLevel<P : PathHolder> {
}
@ApiStatus.Internal
sealed class ScriptSyncCheckResult {
internal sealed class ScriptSyncCheckResult {
data object Synced : ScriptSyncCheckResult()
data object NotSynced : ScriptSyncCheckResult()
data object NoInlineMetadata : ScriptSyncCheckResult()
@@ -156,7 +156,7 @@ private class MyService(val coroutineScope: CoroutineScope)
internal suspend fun Sdk.getUvExecutionContext(project: Project? = null): UvExecutionContext<*>? =
getUvExecutionContextAsync(service<MyService>().coroutineScope, project)?.await()
suspend fun setupNewUvSdkAndEnv(uvExecutable: Path, workingDir: Path, version: Version?, errorSink: ErrorSink): PyResult<Sdk> =
internal suspend fun setupNewUvSdkAndEnv(uvExecutable: Path, workingDir: Path, version: Version?, errorSink: ErrorSink): PyResult<Sdk> =
setupNewUvSdkAndEnv(
uvExecutable = PathHolder.Eel(uvExecutable),
workingDir = workingDir,
@@ -166,7 +166,7 @@ suspend fun setupNewUvSdkAndEnv(uvExecutable: Path, workingDir: Path, version: V
errorSink = errorSink,
)
suspend fun <P : PathHolder> setupNewUvSdkAndEnv(
internal suspend fun <P : PathHolder> setupNewUvSdkAndEnv(
uvExecutable: P,
workingDir: Path,
venvPath: P?,
@@ -200,7 +200,7 @@ suspend fun <P : PathHolder> setupNewUvSdkAndEnv(
return PyResult.success(sdk)
}
suspend fun setupExistingEnvAndSdk(
internal suspend fun setupExistingEnvAndSdk(
pythonBinary: PythonBinary,
uvPath: Path,
envWorkingDir: Path,
@@ -214,7 +214,7 @@ suspend fun setupExistingEnvAndSdk(
usePip = usePip
)
suspend fun <P : PathHolder> setupExistingEnvAndSdk(
internal suspend fun <P : PathHolder> setupExistingEnvAndSdk(
pythonBinary: P,
uvPath: P,
workingDir: Path,
@@ -311,7 +311,7 @@ internal class UvPackageManager internal constructor(project: Project, sdk: Sdk,
}
}
class UvPackageManagerProvider : PythonPackageManagerProvider {
internal class UvPackageManagerProvider : PythonPackageManagerProvider {
override fun createPackageManagerForSdk(project: Project, sdk: Sdk): PythonPackageManager? {
if (!sdk.isUv) {
return null
@@ -14,17 +14,17 @@ import org.apache.tuweni.toml.TomlTable
import org.jetbrains.annotations.ApiStatus
@ApiStatus.Internal
sealed class UvPyProjectIssue {
internal sealed class UvPyProjectIssue {
data object SafeGetError : UvPyProjectIssue()
}
@ApiStatus.Internal
data class UvPyProjectTable(
internal data class UvPyProjectTable(
val uvDevDependencies: List<String>?,
)
@ApiStatus.Internal
data class UvPyProject(val project: UvPyProjectTable?, val issues: List<UvPyProjectIssue>) {
internal data class UvPyProject(val project: UvPyProjectTable?, val issues: List<UvPyProjectIssue>) {
fun matchOutdatedPackages(
module: Module,
pyProject: PyProjectToml,
@@ -19,7 +19,7 @@ import java.nio.file.Path
import javax.swing.Icon
import kotlin.io.path.pathString
class UvSdkAdditionalData : PythonSdkAdditionalData {
internal class UvSdkAdditionalData : PythonSdkAdditionalData {
internal val flavorData: UvSdkFlavorData
constructor(uvWorkingDirectory: Path?, usePip: Boolean?, venvPath: FullPathOnTarget?, uvPath: FullPathOnTarget?) : this(UvSdkFlavorData(
@@ -3,5 +3,5 @@ package com.jetbrains.python.sdk.uv
import com.intellij.openapi.diagnostic.Logger
val LOGGER: Logger = Logger.getInstance("#com.jetbrains.python.sdk.uv")
internal val LOGGER: Logger = Logger.getInstance("#com.jetbrains.python.sdk.uv")
@@ -87,7 +87,7 @@ private class UvCliImpl<P : PathHolder>(val dispatcher: CoroutineDispatcher, val
suspend fun getUvExecutableLocal(eel: EelApi = localEel): Path? = getUvExecutable(EelFileSystem(eel), null)?.path
suspend fun <P : PathHolder> getUvExecutable(fileSystem: FileSystem<P>, pathFromSdk: FullPathOnTarget?): P? =
internal suspend fun <P : PathHolder> getUvExecutable(fileSystem: FileSystem<P>, pathFromSdk: FullPathOnTarget?): P? =
UV_TOOL.getToolExecutable(fileSystem, pathFromSdk)
fun setUvExecutableLocal(path: Path) {
@@ -98,11 +98,11 @@ suspend fun hasUvExecutableLocal(): Boolean {
return getUvExecutableLocal() != null
}
suspend fun createUvCliLocal(uv: Path? = null, dispatcher: CoroutineDispatcher = Dispatchers.IO): PyResult<UvCli<PathHolder.Eel>> {
internal suspend fun createUvCliLocal(uv: Path? = null, dispatcher: CoroutineDispatcher = Dispatchers.IO): PyResult<UvCli<PathHolder.Eel>> {
return createUvCli(uv?.let { PathHolder.Eel(it) }, EelFileSystem(localEel), dispatcher)
}
suspend fun <P : PathHolder> createUvCli(
internal suspend fun <P : PathHolder> createUvCli(
uv: P?,
fileSystem: FileSystem<P>,
dispatcher: CoroutineDispatcher = Dispatchers.IO,
@@ -315,13 +315,13 @@ private class UvLowLevelImpl<P : PathHolder>(
}
}
fun createUvLowLevelLocal(cwd: Path, uvCli: UvCli<PathHolder.Eel>): UvLowLevel<PathHolder.Eel> =
internal fun createUvLowLevelLocal(cwd: Path, uvCli: UvCli<PathHolder.Eel>): UvLowLevel<PathHolder.Eel> =
createUvLowLevel(cwd, uvCli, EelFileSystem(localEel), null)
fun <P : PathHolder> createUvLowLevel(cwd: Path, uvCli: UvCli<P>, fileSystem: FileSystem<P>, venvPath: P?): UvLowLevel<P> =
internal fun <P : PathHolder> createUvLowLevel(cwd: Path, uvCli: UvCli<P>, fileSystem: FileSystem<P>, venvPath: P?): UvLowLevel<P> =
UvLowLevelImpl(cwd, venvPath, uvCli, fileSystem)
suspend fun createUvLowLevelLocal(cwd: Path): PyResult<UvLowLevel<PathHolder.Eel>> =
internal suspend fun createUvLowLevelLocal(cwd: Path): PyResult<UvLowLevel<PathHolder.Eel>> =
createUvCli(null, EelFileSystem(localEel)).mapSuccess { createUvLowLevelLocal(cwd, it) }
private fun tryExtractStderr(err: PyError): String? =
@@ -104,7 +104,7 @@ private suspend fun checkRequiresSync(
}
@ApiStatus.Internal
suspend fun requiresSync(
internal suspend fun requiresSync(
uv: UvLowLevel<PathHolder.Eel>,
options: UvRunConfigurationOptions,
logger: Logger,