Skip to content

Commit 4fe4c47

Browse files
authored
Silence Path allow_not_exist missing-path warnings (#580)
1 parent 3bfafb9 commit 4fe4c47

File tree

9 files changed

+24
-126
lines changed

9 files changed

+24
-126
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to Semantic Versioning (https://semver.org/spec/v2.0.0.
1111
### Changed
1212

1313
- Use zstd level 17 (was 15) when embedding STEP 3D models into KiCad footprints.
14+
- `Path(..., allow_not_exist=True)` no longer emits missing-path warnings.
1415

1516
### Fixed
1617

crates/pcb-zen-core/src/lang/file.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use starlark::environment::GlobalsBuilder;
2-
use starlark::errors::EvalSeverity;
32
use starlark::eval::Evaluator;
43
use starlark::starlark_module;
54
use starlark::values::Value;
65

7-
use crate::Diagnostic;
86
use crate::lang::evaluator_ext::EvaluatorExt;
97
use crate::load_spec::LoadSpec;
108
use crate::resolution::ResolutionResult;
@@ -98,44 +96,6 @@ pub(crate) fn file_globals(builder: &mut GlobalsBuilder) {
9896
.resolve_spec(&load_spec, current_file)
9997
.map_err(|e| anyhow::anyhow!("Failed to resolve path '{}': {}", path, e))?;
10098

101-
if !eval_context.file_provider().exists(&resolved_path) {
102-
let call_stack = eval.call_stack();
103-
104-
let deepest_frame = &call_stack.frames[call_stack.frames.len() - 1];
105-
let location = deepest_frame.location.as_ref().unwrap();
106-
let mut diagnostic = Diagnostic {
107-
path: location.file.filename().to_string(),
108-
span: Some(location.resolve_span()),
109-
severity: EvalSeverity::Warning,
110-
body: format!("Path '{}' does not exist", path),
111-
call_stack: None,
112-
child: None,
113-
source_error: None,
114-
suppressed: false,
115-
};
116-
117-
for (i, frame) in call_stack.frames.iter().enumerate().rev().skip(1) {
118-
if let Some(location) = &frame.location {
119-
diagnostic = Diagnostic {
120-
path: location.file.filename().to_string(),
121-
span: Some(location.resolve_span()),
122-
severity: EvalSeverity::Warning,
123-
body: format!("Path does not exist in {} call", frame.name),
124-
call_stack: if i == 0 {
125-
Some(call_stack.clone())
126-
} else {
127-
None
128-
},
129-
suppressed: false,
130-
child: Some(Box::new(diagnostic)),
131-
source_error: None,
132-
};
133-
}
134-
}
135-
136-
eval.add_diagnostic(diagnostic);
137-
}
138-
13999
let stable_str = stable_path_string(resolution, &resolved_path);
140100

141101
Ok(eval.heap().alloc_str(&stable_str).to_value())

crates/pcb/tests/snapshots/path__path_local_mixed_build.snap

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,4 @@ Existing file: package://boards/existing.toml
1313
Nonexistent file: package://boards/missing.toml
1414
Existing directory: package://boards/config
1515
Nonexistent directory: package://boards/missing_dir
16-
Warning: Path 'build/LocalPathTest' does not exist
17-
╭─[ <TEMP_DIR>/.pcb/cache/github.com/diodeinc/stdlib/<STDLIB_VERSION>/properties.zen:68:37 ]
18-
68 │ add_property("layout_path", Path(path, allow_not_exist=True))
19-
│ ╰──────────────── Path 'build/LocalPathTest' does not exist
20-
├─[ <TEMP_DIR>/boards/LocalPathTest.zen:4:1 ]
21-
4 │Layout(name="LocalPathTest", path="build/LocalPathTest", bom_profile=None)
22-
│ ╰───────────────────────────────────── Path does not exist in Layout call
23-
24-
Warning: Path 'missing.toml' does not exist
25-
╭─[ <TEMP_DIR>/boards/LocalPathTest.zen:7:20 ]
26-
7 │nonexistent_file = Path("missing.toml", allow_not_exist=True)
27-
│ ╰───────────────────── Path 'missing.toml' does not exist
28-
29-
Warning: Path 'missing_dir' does not exist
30-
╭─[ <TEMP_DIR>/boards/LocalPathTest.zen:9:19 ]
31-
9 │nonexistent_dir = Path("missing_dir", allow_not_exist=True)
32-
│ ╰───────────────────── Path 'missing_dir' does not exist
33-
3416
LocalPathTest.zen (0 components)

crates/pcb/tests/snapshots/release__publish_source_only.snap

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,7 @@ expression: sb.snapshot_dir(&staging_dir)
55
---
66
=== diagnostics.json
77
{
8-
"boards/TestBoard.zen": [
9-
{
10-
"location": "<TEMP_DIR>/src/.pcb/releases/TestBoard-<GIT_HASH>/src/vendor/github.com/diodeinc/stdlib/<STDLIB_VERSION>/properties.zen:68:37-69",
11-
"severity": "warning",
12-
"body": "Path 'build/TestBoard' does not exist",
13-
"suppressed": false,
14-
"occurrences": 1,
15-
"stack": [
16-
{
17-
"location": "<TEMP_DIR>/src/.pcb/releases/TestBoard-<GIT_HASH>/src/boards/TestBoard.zen:5:1-67",
18-
"message": "Path does not exist in Layout call"
19-
}
20-
]
21-
}
22-
]
8+
"boards/TestBoard.zen": []
239
}
2410
=== metadata.json
2511
{

crates/pcb/tests/snapshots/release__publish_with_description.snap

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,7 @@ expression: sb.snapshot_dir(&staging_dir)
55
---
66
=== diagnostics.json
77
{
8-
"boards/DescBoard.zen": [
9-
{
10-
"location": "<TEMP_DIR>/src/.pcb/releases/DescBoard-<GIT_HASH>/src/vendor/github.com/diodeinc/stdlib/<STDLIB_VERSION>/properties.zen:68:37-69",
11-
"severity": "warning",
12-
"body": "Path 'build/TestBoard' does not exist",
13-
"suppressed": false,
14-
"occurrences": 1,
15-
"stack": [
16-
{
17-
"location": "<TEMP_DIR>/src/.pcb/releases/DescBoard-<GIT_HASH>/src/boards/DescBoard.zen:5:1-67",
18-
"message": "Path does not exist in Layout call"
19-
}
20-
]
21-
}
22-
]
8+
"boards/DescBoard.zen": []
239
}
2410
=== metadata.json
2511
{

crates/pcb/tests/snapshots/release__publish_with_file.snap

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
---
22
source: crates/pcb/tests/release.rs
3+
assertion_line: 319
34
expression: sb.snapshot_dir(&staging_dir)
45
---
56
=== diagnostics.json
67
{
7-
"boards/TB0002.zen": [
8-
{
9-
"location": "<TEMP_DIR>/src/.pcb/releases/TB0002-<GIT_HASH>/src/vendor/github.com/diodeinc/stdlib/<STDLIB_VERSION>/properties.zen:68:37-69",
10-
"severity": "warning",
11-
"body": "Path 'build/TestBoard' does not exist",
12-
"suppressed": false,
13-
"occurrences": 1,
14-
"stack": [
15-
{
16-
"location": "<TEMP_DIR>/src/.pcb/releases/TB0002-<GIT_HASH>/src/boards/TB0002.zen:4:1-67",
17-
"message": "Path does not exist in Layout call"
18-
}
19-
]
20-
}
21-
]
8+
"boards/TB0002.zen": []
229
}
2310
=== metadata.json
2411
{

crates/pcb/tests/snapshots/release__publish_with_version.snap

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,7 @@ expression: sb.snapshot_dir(staging_dir)
55
---
66
=== diagnostics.json
77
{
8-
"boards/TB0001.zen": [
9-
{
10-
"location": "<TEMP_DIR>/src/.pcb/releases/TB0001-v1.3.0/src/vendor/github.com/diodeinc/stdlib/<STDLIB_VERSION>/properties.zen:68:37-69",
11-
"severity": "warning",
12-
"body": "Path 'build/TestBoard' does not exist",
13-
"suppressed": false,
14-
"occurrences": 1,
15-
"stack": [
16-
{
17-
"location": "<TEMP_DIR>/src/.pcb/releases/TB0001-v1.3.0/src/boards/TB0001.zen:5:1-67",
18-
"message": "Path does not exist in Layout call"
19-
}
20-
]
21-
}
22-
]
8+
"boards/TB0001.zen": []
239
}
2410
=== metadata.json
2511
{
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/pcb/tests/simple.rs
3+
assertion_line: 152
34
expression: output
45
---
56
Command: pcb build boards/TestBoard.zen
@@ -8,12 +9,4 @@ Exit Code: 0
89
--- STDOUT ---
910

1011
--- STDERR ---
11-
Warning: Path 'build/TestBoard' does not exist
12-
╭─[ <TEMP_DIR>/.pcb/cache/github.com/diodeinc/stdlib/<STDLIB_VERSION>/properties.zen:68:37 ]
13-
68 │ add_property("layout_path", Path(path, allow_not_exist=True))
14-
│ ╰──────────────── Path 'build/TestBoard' does not exist
15-
├─[ <TEMP_DIR>/boards/TestBoard.zen:5:1 ]
16-
5 │Layout(name="TestBoard", path="build/TestBoard", bom_profile=None)
17-
│ ╰───────────────────────────────── Path does not exist in Layout call
18-
1912
TestBoard.zen (10 components)

docs/pages/spec.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,23 @@ When the parent does not provide a value:
518518
- `optional=True`: returns `default` (after conversion) when present, otherwise `None`.
519519
- `optional=False`: during strict module instantiation, emits a missing-input error diagnostic, then continues evaluation using fallback behavior (`default` if provided, otherwise a generated type default).
520520

521+
### Path()
522+
523+
Resolve a file or directory path and return a stable path string (for example, `package://...` when applicable).
524+
525+
**Signature:** `Path(path, allow_not_exist=False)`
526+
527+
- `path`: Local path or other supported load-spec string.
528+
- `allow_not_exist`: Named boolean (default `False`).
529+
- `False`: unresolved/missing paths raise an error.
530+
- `True`: missing local paths are allowed and no diagnostic is emitted.
531+
- Can only be used with local path specs.
532+
533+
```python
534+
existing = Path("config/settings.toml")
535+
future_output = Path("build/MyBoard", allow_not_exist=True)
536+
```
537+
521538
### builtin.physical_value()
522539

523540
**Built-in function** that creates unit-specific physical value constructor types for electrical quantities.

0 commit comments

Comments
 (0)