Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

virtualenvwrapper's environments are offered, never its hook scripts

Țugui Dragoșa96ea72d91ed
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index 53828361..0235cd48 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -219,7 +219,9 @@ public enum DeveloperCaches {
Folder(".local/share/virtualenvs", .environments),
]),
Definition(id: "virtualenvwrapper", name: "virtualenvwrapper", systemImage: "chevron.left.forwardslash.chevron.right", appBundleIdentifiers: [], folders: [
- Folder(".virtualenvs", .environments),
+ // The environments, not the hook scripts virtualenvwrapper keeps beside them: a pattern that ends in `/`
+ // matches folders only.
+ Folder(".virtualenvs/*/", .environments),
]),
Definition(id: "conda", name: "Conda", systemImage: "chevron.left.forwardslash.chevron.right", appBundleIdentifiers: [], folders: [
Folder("miniconda3/pkgs", .environments),
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 728311a6..2af9fd1d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -218,11 +218,14 @@ struct DeveloperCachesTests {
var expected: Set<String> = []
for definition in DeveloperCaches.definitions {
for path in definition.folders.map(\.path) {
- // A wildcard becomes a name it matches: `*` any folder, `[0-9a-f]` one of ccache's shards.
+ // A wildcard becomes a name it matches: `*` any folder, `[0-9a-f]` one of ccache's shards. A pattern
+ // that ends in `/` matches every folder beside, so what sits beside its match is a file.
let concrete = path.replacingOccurrences(of: "*", with: "match").replacingOccurrences(of: "[0-9a-f]", with: "a")
- try directory.file("\(concrete)/content", bytes: 400_000)
- expected.insert(concrete)
- try directory.file("\(concrete)/../elsewhere-\(definition.id)/content", bytes: 400_000)
+ let foldersOnly = concrete.hasSuffix("/")
+ let entry = foldersOnly ? String(concrete.dropLast()) : concrete
+ try directory.file("\(entry)/content", bytes: 400_000)
+ expected.insert(entry)
+ try directory.file("\(entry)/../elsewhere-\(definition.id)" + (foldersOnly ? "" : "/content"), bytes: 400_000)
}
}
@@ -290,6 +293,23 @@ struct DeveloperCachesTests {
#expect(suggested == ["pnpm"], "a store installed packages link into was suggested")
}
+ /// virtualenvwrapper keeps the user's hook scripts beside the environments in `~/.virtualenvs`, so only the
+ /// environments are offered, and a link among them is left where it is, never followed.
+ @Test func offersVirtualenvwrappersEnvironmentsAndNotItsHooks() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file(".virtualenvs/web/bin/python", bytes: 400_000)
+ try directory.file(".virtualenvs/postactivate", bytes: 64)
+ try directory.file(".virtualenvs/hook.log", bytes: 64)
+ let elsewhere = try directory.directory("Volumes/Fast/env")
+ try directory.file("Volumes/Fast/env/bin/python", bytes: 400_000)
+ try FileManager.default.createSymbolicLink(at: directory.url.appending(path: ".virtualenvs/fast"), withDestinationURL: elsewhere)
+ let wrapper = DeveloperCaches.definitions.filter { $0.id == "virtualenvwrapper" }
+
+ let offered = await DeveloperCaches.scan(wrapper, homeDirectory: directory.url).flatMap(\.locations).map(\.url.lastPathComponent)
+
+ #expect(offered == ["web"])
+ }
+
/// Nx answers a cache hit from its database alone, so a workspace's `cache` and `databases` go together: the
/// folder that holds both is offered as one, and nothing else in `~/.nx` is.
@Test func offersNxsCacheAndDatabaseOnlyTogether() async throws {