@@ -20,11 +20,21 @@ std::filesystem::path GetUvPath() {
2020 const auto bin_name = system_info->os == kWindowsOs ? " uv.exe" : " uv" ;
2121 return GetPythonEnginesPath () / " bin" / bin_name;
2222}
23+ bool UvCleanCache () {
24+ auto cmd = UvBuildCommand (" cache" );
25+ cmd.push_back (" clean" );
26+ auto result = cortex::process::SpawnProcess (cmd);
27+ if (result.has_error ()) {
28+ CTL_INF (result.error ());
29+ return false ;
30+ }
31+ return cortex::process::WaitProcess (result.value ());
32+ }
2333
24- bool IsUvInstalled () {
34+ bool UvIsInstalled () {
2535 return std::filesystem::exists (GetUvPath ());
2636}
27- cpp::result<void , std::string> InstallUv () {
37+ cpp::result<void , std::string> UvInstall () {
2838 const auto py_bin_path = GetPythonEnginesPath () / " bin" ;
2939 std::filesystem::create_directories (py_bin_path);
3040
@@ -75,7 +85,7 @@ cpp::result<void, std::string> InstallUv() {
7585 // this Python installation.
7686 // we can add this once we allow passing custom env var to SpawnProcess().
7787 // https://docs.astral.sh/uv/reference/cli/#uv-python-install
78- std::vector<std::string> command = BuildUvCommand (" python" );
88+ std::vector<std::string> command = UvBuildCommand (" python" );
7989 command.push_back (" install" );
8090 command.push_back (" 3.10" );
8191
@@ -92,7 +102,7 @@ cpp::result<void, std::string> InstallUv() {
92102 return {};
93103}
94104
95- std::vector<std::string> BuildUvCommand (const std::string& action,
105+ std::vector<std::string> UvBuildCommand (const std::string& action,
96106 const std::string& directory) {
97107 // use our own cache dir so that when users delete cortexcpp/, everything is deleted.
98108 const auto cache_dir = GetPythonEnginesPath () / " cache" / " uv" ;
@@ -106,31 +116,4 @@ std::vector<std::string> BuildUvCommand(const std::string& action,
106116 return command;
107117}
108118
109- // cpp::result<void, std::string> UvDownloadDeps(
110- // const std::filesystem::path& model_dir) {
111- // if (!IsUvInstalled())
112- // return cpp::fail(
113- // "uv is not installed. Please run `cortex engines install python`.");
114-
115- // std::vector<std::string> command = BuildUvCommand("sync", model_dir.string());
116-
117- // // script mode. 1st argument is path to .py script
118- // if (!std::filesystem::exists(model_dir / "pyproject.toml")) {
119- // config::PythonModelConfig py_cfg;
120- // py_cfg.ReadFromYaml((model_dir / "model.yml").string());
121- // command.push_back("--script");
122- // command.push_back(py_cfg.entrypoint[0]);
123- // }
124-
125- // auto result = cortex::process::SpawnProcess(command);
126- // if (result.has_error())
127- // return cpp::fail("Fail to install Python dependencies. " + result.error());
128-
129- // if (!cortex::process::WaitProcess(result.value())) {
130- // return cpp::fail("Fail to install Python dependencies.");
131- // }
132-
133- // return {};
134- // }
135-
136119} // namespace python_utils
0 commit comments