Skip to content

Commit

Permalink
Add "Configuration file" as a setting for uv
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo committed Sep 3, 2024
1 parent 48cb2b4 commit c13cdd4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import insyncwithfoo.ryecharm.message

internal class UVConfigurations : DisplayableState(), HasTimeouts, Copyable {
var executable by string(null)
var configurationFile by string(null)

var packageManaging by property(false)

override var timeouts by map<SettingName, MillisecondsOrNoLimit>()
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/insyncwithfoo/ryecharm/configurations/uv/Panels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ private fun Row.makeExecutableInput(block: Cell<TextFieldWithBrowseButton>.() ->
singleFileTextField().makeFlexible().apply(block)


private fun Row.makeConfigurationFileInput(block: Cell<TextFieldWithBrowseButton>.() -> Unit) =
singleFileTextField().makeFlexible().apply(block)


private fun Row.makePackageManagingInput(block: Cell<JBCheckBox>.() -> Unit) =
checkBox(message("configurations.uv.packageManaging.label")).apply(block)

Expand All @@ -46,6 +50,13 @@ private fun UVPanel.makeComponent() = panel {
makeOverrideCheckboxIfApplicable(state::executable)
}

row {
makeConfigurationFileInput { bindText(state::configurationFile) }
makeOverrideCheckboxIfApplicable(state::configurationFile)
}

separator()

group(message("configurations.uv.groups.packageManagement")) {
row {
makePackageManagingInput { bindSelected(state::packageManaging) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ internal class CleanCache : AnAction(), DumbAware {
return project.unableToRunCommand()
}

project.runRuffCleanAndReport(ruff, projectPath)
project.runCommandAndReport(ruff, projectPath)
}

private fun Project.runRuffCleanAndReport(ruff: Ruff, path: Path) = runAction {
private fun Project.runCommandAndReport(ruff: Ruff, path: Path) = runAction {
val command = ruff.clean(path)
val output = runInBackground(command)

runInBackground(command) { output ->
notifyProcessResult(command, output)
}
notifyProcessResult(command, output)
}

}
15 changes: 14 additions & 1 deletion src/main/kotlin/insyncwithfoo/ryecharm/uv/commands/UV.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,24 @@ internal class UV private constructor(
PipListCommand().build(arguments = listOf("list", "--format", "json"))

private fun Command.build(arguments: Arguments? = null) = this.apply {
this.arguments = arguments ?: emptyList()
this.arguments = arguments?.withGlobalOptions() ?: emptyList()

setExecutableAndWorkingDirectory()
}

private fun Arguments.withGlobalOptions(): Arguments {
val new = this.toMutableList()

val configurations = project?.uvConfigurations
val configurationFile = configurations?.configurationFile

if (configurationFile != null) {
new.addAll(0, listOf("--config-file", configurationFile))
}

return new
}

companion object {

fun create(project: Project): UV? = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.jetbrains.python.sdk.flavors.PyFlavorData
import insyncwithfoo.ryecharm.uv.sdk.UVSDKAdditionalData.Companion.IS_UV
import org.jdom.Element


/**
* Additional data for uv-created SDKs.
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages/ryecharm.properties
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ configurations.uv.groups.packageManagement = Package management
configurations.uv.executable.label = Executable:
configurations.uv.executable.placeholder = Unable to detect executable

configurations.uv.configurationFile.label = Configuration file:

configurations.uv.packageManaging.label = Use uv for package operations

######################################## endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ internal class UVConfigurationsTest : ConfigurationsTest<UVConfigurations>() {

@Test
fun `test - shape`() {
doShapeTest(expectedSize = 3) {
doShapeTest(expectedSize = 4) {
assertEquals(null, executable)
assertEquals(null, configurationFile)

assertEquals(false, packageManaging)

assertEquals(emptyMap<SettingName, MillisecondsOrNoLimit>(), timeouts)
Expand Down

0 comments on commit c13cdd4

Please sign in to comment.