-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a UV package manager * The command is `uv pip install` * Update logging * Add noisy logs * Fiddling with debug * revert test results * Use a different test output helper for this test suite * Add debug traces * Extra debug output * Add an extra debug flag * Refactor into util class for process spawning * Run UV with the VIRTUAL_ENV environment variable * Run UV in verbose mode * Propagate uv cache variables * Document UV support * Refactor the process util to it's rightful place
- Loading branch information
1 parent
9978049
commit 606e883
Showing
12 changed files
with
189 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using CSnakes.Runtime.EnvironmentManagement; | ||
using Microsoft.Extensions.Logging; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace CSnakes.Runtime.PackageManagement; | ||
|
||
internal class UVInstaller(ILogger<UVInstaller> logger, string requirementsFileName) : IPythonPackageInstaller | ||
{ | ||
static readonly string binaryName = $"uv{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}"; | ||
|
||
public Task InstallPackages(string home, IEnvironmentManagement? environmentManager) | ||
{ | ||
string requirementsPath = Path.GetFullPath(Path.Combine(home, requirementsFileName)); | ||
if (File.Exists(requirementsPath)) | ||
{ | ||
logger.LogDebug("File {Requirements} was found.", requirementsPath); | ||
InstallPackagesWithUv(home, environmentManager, $"-r {requirementsFileName} --verbose", logger); | ||
} | ||
else | ||
{ | ||
logger.LogWarning("File {Requirements} was not found.", requirementsPath); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
static internal void InstallPackagesWithUv(string home, IEnvironmentManagement? environmentManager, string requirements, ILogger logger) | ||
{ | ||
string fileName = binaryName; | ||
string workingDirectory = home; | ||
string path = ""; | ||
string arguments = $"pip install {requirements}"; | ||
|
||
if (environmentManager is not null) | ||
{ | ||
string virtualEnvironmentLocation = Path.GetFullPath(environmentManager.GetPath()); | ||
logger.LogDebug("Using virtual environment at {VirtualEnvironmentLocation} to install packages with uv.", virtualEnvironmentLocation); | ||
string venvScriptPath = Path.Combine(virtualEnvironmentLocation, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Scripts" : "bin"); | ||
string uvPath = Path.Combine(venvScriptPath, binaryName); | ||
|
||
// Is UV installed? | ||
if (!File.Exists(uvPath)) | ||
{ | ||
// Install it with pip | ||
PipInstaller.InstallPackagesWithPip(home, environmentManager, "uv", logger); | ||
} | ||
|
||
fileName = uvPath; | ||
path = $"{venvScriptPath};{Environment.GetEnvironmentVariable("PATH")}"; | ||
IReadOnlyDictionary<string, string?> extraEnv = new Dictionary<string, string?> | ||
{ | ||
{ "VIRTUAL_ENV", virtualEnvironmentLocation }, | ||
{ "UV_CACHE_DIR", Environment.GetEnvironmentVariable("UV_CACHE_DIR") }, | ||
{ "UV_NO_CACHE", Environment.GetEnvironmentVariable("UV_NO_CACHE") } | ||
}; | ||
|
||
ProcessUtils.ExecuteProcess(fileName, arguments, workingDirectory, path, logger, extraEnv); | ||
} else | ||
{ | ||
ProcessUtils.ExecuteProcess(fileName, arguments, workingDirectory, path, logger); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.