Begin Showing Proposals In Subdirectories Of '/proposals'
Introduction
As part of our ongoing efforts to improve the Swift Evolution process, we have recently launched a Testing Workgroup in Swift. This initiative aims to bring together experts and enthusiasts to focus on testing-related proposals. As a result, we are beginning to place proposals focused on Swift Testing in a new /proposals/testing
subdirectory of the swift-evolution repo. In this article, we will explore the process of adding formal support for including proposals in this directory and showing them on the Swift Evolution Dashboard.
Background
We recently launched the Testing Workgroup in Swift, and as part of that, we're beginning to place proposals focused on Swift Testing in a new /proposals/testing
subdirectory of the swift-evolution repo. As of https://github.com/swiftlang/swift-evolution/pull/2721, that subdirectory now exists and contains historical proposals which were approved before Swift Testing began formally participating in the evolution process.
However, shortly after that landed, someone realized that swift-evolution-metadata-extractor had broken and was no longer successfully processing proposal updates. @hborla landed a quick fix for that issue in https://github.com/swiftlang/swift-evolution-metadata-extractor/pull/48, which simply ignored all content in the /proposals/testing
directory. This issue tracks adding formal support for including the proposals in that directory and showing them on the Swift Evolution Dashboard.
Requirements
To add formal support for including proposals in the /proposals/testing
subdirectory, we need to:
- Find proposals in the
/proposals/testing
subdirectory: We need to find a way to locate proposals in this subdirectory and include them in the Swift Evolution Dashboard. - Adjust anything else necessary to successfully parse the header of these proposals: We need to ensure that the header of these proposals is parsed correctly, which may involve adjusting the metadata extractor or the proposal template.
- Ensure that Swift Testing's custom "ST-NNNN" prefix is handled correctly: We need to ensure that the custom prefix used by Swift Testing is handled correctly, which is intentionally different from the "SE-NNNN" prefix used by Swift and SwiftPM.
Finding Proposals in Subdirectories
To find proposals in the /proposals/testing
subdirectory, we can use a recursive approach to traverse the directory tree and locate all proposals. We can use a combination of glob
and fs
modules to achieve this.
import Foundation
func findProposals(in directory: String) -> [String] {
var proposals: [String] = []
do {
let files = try FileManager.default.contentsOfDirectory(atPath: directory)
for file in files {
let filePath = directory + "/" + file
if file.hasSuffix(".md") {
proposals.append(filePath)
} else if file.hasSuffix("/") {
let subdirectory = directory + "/" + file
proposals.append(contentsOf: findProposals(in: subdirectory))
}
}
} catch {
print("Error finding proposals: \(error)")
}
return proposals
}
Adjusting the Metadata Extractor
To adjust the metadata extractor, we need to ensure that it can correctly parse the header of proposals in the /proposals/testing
subdirectory. We can do this by modifying the swift-evolution-metadata-extractor
to handle the custom prefix used by Swift Testing.
import Foundation
func parseProposalHeader(from file: String) -> String? {
let content = try! String(contentsOfFile: file, encoding: .utf8)
let lines = content.components(separatedBy: "\n")
var header: String?
for line in lines {
if line.hasPrefix("ST-") {
header = line
break
}
}
return header
}
Ensuring Correct Handling of Custom Prefix
To ensure that the custom prefix used by Swift Testing is handled correctly, we need to modify the swift-evolution-metadata-extractor
to recognize the "ST-NNNN" prefix.
import Foundation
func extractProposalMetadata(from file: String) -> [String: String]? {
let header = parseProposalHeader(from: file)
if let header = header {
let parts = header.components(separatedBy: "-")
if parts.count == 3 && parts[0] == "ST" {
return ["prefix": "ST", "number": parts[1]]
}
}
return nil
}
Conclusion
In this article, we have explored the process of adding formal support for including proposals in the /proposals/testing
subdirectory and showing them on the Swift Evolution Dashboard. We have discussed the requirements for finding proposals in subdirectories, adjusting the metadata extractor, and ensuring correct handling of the custom prefix used by Swift Testing. By following these steps, we can ensure that proposals in the /proposals/testing
subdirectory are correctly included in the Swift Evolution Dashboard.
Future Work
In the future, we can consider adding support for including proposals in any subdirectory of /proposals
to future-proof the process. We can also consider modifying the swift-evolution-metadata-extractor
to handle other custom prefixes used by different Swift initiatives.
References
- Swift Evolution Dashboard
- swift-evolution-metadata-extractor
- swift-evolution
Q&A: Adding Formal Support for Proposals in Subdirectories ===========================================================
Introduction
In our previous article, we explored the process of adding formal support for including proposals in the /proposals/testing
subdirectory and showing them on the Swift Evolution Dashboard. In this article, we will answer some frequently asked questions (FAQs) related to this topic.
Q: Why do we need to add formal support for proposals in subdirectories?
A: We need to add formal support for proposals in subdirectories because the current implementation of the Swift Evolution Dashboard only includes proposals in the root /proposals
directory. By adding support for subdirectories, we can include proposals from other Swift initiatives, such as the Testing Workgroup.
Q: How do we find proposals in subdirectories?
A: We can use a recursive approach to traverse the directory tree and locate all proposals. We can use a combination of glob
and fs
modules to achieve this.
import Foundation
func findProposals(in directory: String) -> [String] {
var proposals: [String] = []
do {
let files = try FileManager.default.contentsOfDirectory(atPath: directory)
for file in files {
let filePath = directory + "/" + file
if file.hasSuffix(".md") {
proposals.append(filePath)
} else if file.hasSuffix("/") {
let subdirectory = directory + "/" + file
proposals.append(contentsOf: findProposals(in: subdirectory))
}
}
} catch {
print("Error finding proposals: \(error)")
}
return proposals
}
Q: How do we adjust the metadata extractor to handle proposals in subdirectories?
A: We need to modify the swift-evolution-metadata-extractor
to handle the custom prefix used by Swift Testing. We can do this by modifying the parseProposalHeader
function to recognize the "ST-NNNN" prefix.
import Foundation
func parseProposalHeader(from file: String) -> String? {
let content = try! String(contentsOfFile: file, encoding: .utf8)
let lines = content.components(separatedBy: "\n")
var header: String?
for line in lines {
if line.hasPrefix("ST-") {
header = line
break
}
}
return header
}
Q: How do we ensure that the custom prefix used by Swift Testing is handled correctly?
A: We need to modify the swift-evolution-metadata-extractor
to recognize the "ST-NNNN" prefix. We can do this by modifying the extractProposalMetadata
function to handle the custom prefix.
import Foundation
func extractProposalMetadata(from file: String) -> [String: String]? {
let header = parseProposalHeader(from: file)
if let header = header {
let parts = header.components(separatedBy: "-")
if parts.count == 3 && parts[0] == "ST" {
return ["prefix": "ST", "number": parts[1]]
}
}
return nil
}
Q: What are the benefits of adding formal support for proposals in subdirectories?
A: The benefits of adding formal support for proposals in subdirectories include:
- Improved discoverability: By including proposals from other Swift initiatives, we can improve discoverability and make it easier for developers to find relevant proposals.
- Increased participation: By supporting proposals from other Swift initiatives, we can increase participation and engagement from the Swift community.
- Better representation: By including proposals from other Swift initiatives, we can better represent the diversity of the Swift community and ensure that all voices are heard.
Q: What are the next steps for adding formal support for proposals in subdirectories?
A: The next steps for adding formal support for proposals in subdirectories include:
- Implementing the recursive approach: We need to implement the recursive approach to traverse the directory tree and locate all proposals.
- Modifying the metadata extractor: We need to modify the
swift-evolution-metadata-extractor
to handle the custom prefix used by Swift Testing. - Testing and validation: We need to test and validate the implementation to ensure that it works correctly and handles all edge cases.
Conclusion
In this article, we have answered some frequently asked questions (FAQs) related to adding formal support for proposals in subdirectories. We have discussed the benefits of adding formal support, the next steps for implementation, and the importance of testing and validation. By following these steps, we can ensure that proposals in subdirectories are correctly included in the Swift Evolution Dashboard.