MCPcopy Create free account
hub / github.com/LAStools/LAStools / findLatestCondaInstallationPath

Function findLatestCondaInstallationPath

src/proj_loader.cpp:514–665  ·  view source on GitHub ↗

Finds the latest PROJ installation path in Conda environments

Source from the content-addressed store, hash-verified

512
513/// Finds the latest PROJ installation path in Conda environments
514static std::string findLatestCondaInstallationPath(std::set<std::filesystem::path>& searchedPaths) {
515 // 1. Check the environment variable CONDA_PREFIX
516 const char* condaPathEnv = getenv("CONDA_PREFIX");
517 std::filesystem::path binPath;
518 std::string latestVersionPath;
519 std::string latestVersionName;
520
521#ifdef _WIN32
522 if (condaPathEnv) {
523 try {
524 if (std::filesystem::exists(condaPathEnv)) {
525 std::filesystem::path path(condaPathEnv);
526 path /= "Library"; // Append "Library" to the path
527 path /= "bin"; // Append "bin" to the path
528 if (std::filesystem::exists(path)) {
529 searchedPaths.insert(path);
530 LASMessage(LAS_VERY_VERBOSE, "PROJ library used via Conda installation path: %s", path.string().c_str());
531 return path.string();
532 } else {
533 LASMessage(LAS_WARNING, "CONDA_PREFIX set but bin Library/bin folder [%s] not found", path.string().c_str());
534 }
535 } else {
536 LASMessage(LAS_WARNING, "CONDA_PREFIX set [%s] but not found", condaPathEnv);
537 }
538 }
539 catch (const std::filesystem::filesystem_error&) {
540 }
541 }
542
543 // 2. If the environment variable is not set, check standart path
544 const char* homeDir = getHomeDirectory();
545 if (!homeDir) return "";
546
547 std::filesystem::path homePath(homeDir);
548
549 // Iterate through directories in the home directory
550 for (const auto& entry : std::filesystem::directory_iterator(homePath)) {
551 searchedPaths.insert(entry.path());
552 try {
553 std::string directoryName = entry.path().filename().string();
554 if (directoryName.find("miniconda") == 0 || directoryName.find("anaconda") == 0) {
555 binPath = entry.path() / "Library" / "bin";
556
557 if (std::filesystem::exists(binPath) && std::filesystem::is_directory(binPath)) {
558 searchedPaths.insert(binPath);
559 std::string proj = findLatestProjLibraryPath(binPath.string().c_str());
560
561 if (!proj.empty()) {
562 std::filesystem::path projPath(proj);
563 std::string fileName = projPath.filename().string();
564
565 if (latestVersionName.empty() || compareVersions(fileName, latestVersionName)) {
566 latestVersionName = fileName;
567 latestVersionPath = projPath.parent_path().string();
568 }
569 }
570 }
571 }

Callers 1

load_proj_libraryFunction · 0.85

Calls 8

LASMessageFunction · 0.85
getHomeDirectoryFunction · 0.85
compareVersionsFunction · 0.85
getProjLibraryPathFunction · 0.85
emptyMethod · 0.80
insertMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected