-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataset_reader.dart
More file actions
73 lines (61 loc) · 2.18 KB
/
dataset_reader.dart
File metadata and controls
73 lines (61 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'dart:io';
import 'package:path/path.dart' as p;
import 'filesystem_utils.dart';
/// Global accessor for the dataset reader singleton.
DatasetReader get datasetReader => DatasetReader();
/// Reads dataset YAML files for configuration.
class DatasetReader {
DatasetReader._();
static final DatasetReader _instance = DatasetReader._();
factory DatasetReader() => _instance;
String? _cachedDatasetPath;
/// Clears the cached dataset path. Useful for testing.
void clearCache() {
_cachedDatasetPath = null;
}
/// Gets the path to the dataset directory.
String get datasetDirPath {
_cachedDatasetPath ??= findDatasetDirectory();
return _cachedDatasetPath!;
}
/// Gets the path to the tasks directory.
String get tasksDirPath => p.join(datasetDirPath, 'tasks');
/// Returns the list of task names discovered from tasks/ directory.
///
/// Each subdirectory in tasks/ that contains a task.yaml file is a task.
/// The task name is derived from the directory name.
List<String> getTasks() {
final tasksDir = Directory(tasksDirPath);
if (!tasksDir.existsSync()) {
return [];
}
final taskNames = <String>[];
for (final entity in tasksDir.listSync()) {
if (entity is Directory) {
final taskFile = File(p.join(entity.path, 'task.yaml'));
if (taskFile.existsSync()) {
taskNames.add(p.basename(entity.path));
}
}
}
taskNames.sort();
return taskNames;
}
/// Returns the set of existing task names for duplicate checking.
Set<String> getExistingTaskNames() => getTasks().toSet();
/// Returns the list of available variant names.
///
/// These come from the [DefaultVariants] enum, which defines the
/// built-in variant configurations (baseline, flutter_rules, etc.).
List<String> getVariants() {
return DefaultVariants.values.map((v) => v.variantName).toList();
}
/// Returns task function info discovered from task.yaml files.
///
/// Reads the `func` and optional `description` field from each task.yaml.
List<({String name, String? help})> getTaskFuncs() {
return getTasks().map((name) {
return (name: name, help: null as String?);
}).toList();
}
}