in language-extensions/python/src/PythonLibrarySession.cpp [254:310]
vector<fs::directory_entry> PythonLibrarySession::GetTopLevel(string libName, string installDir)
{
vector<fs::directory_entry> artifacts;
regex_constants::syntax_option_type caseInsensitive = regex_constants::icase;
// Normalize library names by replacing all dashes and underscores with regex for either
//
string regexLibName = regex_replace(libName, regex("(-|_)"), "(-|_)");
if (fs::exists(installDir))
{
for (const fs::directory_entry &entry : fs::directory_iterator(installDir))
{
string pathFilename = entry.path().filename().string();
// The top_level.txt file is in the egg-info or dist-info folder
//
regex egg("^" + regexLibName + "-(.*)egg(.*)", caseInsensitive);
regex distinfo("^" + regexLibName + "-(.*)dist-info", caseInsensitive);
if (regex_match(pathFilename, egg) ||
regex_match(pathFilename, distinfo))
{
artifacts.push_back(entry);
// The top_level.txt file tells us what items this package put into the
// installation directory that we will need to delete to uninstall.
//
fs::path topLevelPath = entry.path();
topLevelPath = topLevelPath.append("top_level.txt");
if (fs::exists(topLevelPath))
{
// Read in the top_level file to find what the top_level folders and files are
//
ifstream topLevelFile(topLevelPath);
string str;
while (getline(topLevelFile, str))
{
if (str.size() > 0)
{
fs::path path(installDir);
artifacts.push_back(fs::directory_entry(path.append(str)));
}
}
topLevelFile.close();
break;
}
break;
}
}
}
return artifacts;
}