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.

Know a tox or Nox folder by what it holds where only its tag names it

Țugui Dragoșde6423d66b5c
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index 02382c21..a2f7e344 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -163,6 +163,8 @@ public enum ProjectArtifacts {
enum Proof: Sendable {
/// A file the tool always writes inside, as `venv` writes `pyvenv.cfg`.
case holds(String)
+ /// That file, inside or in a folder directly inside: tox and Nox tag the folder that holds their environments.
+ case holdsAtOrOneLevelDown(String)
/// Nothing but files with this ending, as Python writes only compiled `.pyc` files into `__pycache__`.
case holdsOnlyFilesEnding(String)
/// Nothing but entries with these names, `including` among them.
@@ -176,6 +178,9 @@ public enum ProjectArtifacts {
var info = stat()
let path = url.appending(path: name).path(percentEncoded: false)
return lstat(path, &info) == 0 && info.st_mode & S_IFMT == S_IFREG
+ case .holdsAtOrOneLevelDown(let name):
+ let inside = ProjectArtifacts.contents(of: url)?.filter(ProjectArtifacts.isRealFolder) ?? []
+ return ([url] + inside).contains { Proof.holds(name).holds(at: $0) }
case .holdsOnly(let names, let including):
let path = url.path(percentEncoded: false)
let entries = Set((try? FileManager.default.contentsOfDirectory(atPath: path)) ?? [])
@@ -553,7 +558,8 @@ public enum ProjectArtifacts {
// uv and virtualenv tag every environment they make as a cache, whatever it is called.
Definition(
name: "*", markers: [], tool: "Python", isGeneric: false, isEnvironment: true,
- source: "https://peps.python.org/pep-0405/", proof: .holds("pyvenv.cfg"), isFoundOnlyByItsTag: true
+ source: "https://peps.python.org/pep-0405/", proof: .holdsAtOrOneLevelDown("pyvenv.cfg"),
+ isFoundOnlyByItsTag: true
),
// And beside a Python project's own file, any folder holding `pyvenv.cfg` is one, whatever it is called.
Definition(
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index 754ebcfb..118c896d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -1526,6 +1526,21 @@ struct ProjectArtifactsTests {
#expect(scan.refusedRoots.map(\.reason) == [.notAFolder])
}
+ @Test func aFolderOfEnvironmentsKnownOnlyByItsTagIsNoCache() async throws {
+ let directory = try TemporaryDirectory()
+ let tag = Data("Signature: 8a477f597d28d172789f06886806bc55\n".utf8)
+ try directory.file("Code/tool/main.py")
+ try directory.file("Code/tool/.tox/CACHEDIR.TAG", contents: tag)
+ try directory.file("Code/tool/.tox/py311/pyvenv.cfg")
+ try age(directory.url, days: 60)
+
+ let scan = await ProjectArtifacts.scan(roots: [directory.url.appending(path: "Code")])
+
+ #expect(scan.artifacts.map(\.name) == [".tox"])
+ #expect(scan.artifacts.first?.isEnvironment == true)
+ #expect(scan.artifacts.first?.isRecommended == false)
+ }
+
@Test func oneChosenFolderInsideAnotherNamesTheSameProjectEveryTime() async throws {
let directory = try TemporaryDirectory()
try directory.directory("root/repo/.git")
@@ -1561,7 +1576,7 @@ struct ProjectArtifactsTests {
let name = definition.name.hasSuffix("*") ? definition.name.dropLast() + "debug" : definition.name
let artifact = "\(project)/\(name)"
switch definition.proof {
- case .holds(let file): try directory.file("\(artifact)/\(file)")
+ case .holds(let file), .holdsAtOrOneLevelDown(let file): try directory.file("\(artifact)/\(file)")
case .holdsOnlyFilesEnding(let ending): try directory.file("\(artifact)/module\(ending)")
case .holdsOnly(_, let including): try directory.file("\(artifact)/\(including)/content")
case .holdsOnlyFoldersNamedByDigest(let characters):