Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single file inputs for buf format #2516

Open
andrewparmet opened this issue Oct 26, 2023 · 5 comments
Open

Single file inputs for buf format #2516

andrewparmet opened this issue Oct 26, 2023 · 5 comments
Labels
Cleanup Cleanup tasks

Comments

@andrewparmet
Copy link

I'm trying to format a single file using Spotless' Buf integration. Spotless is running the following:

/absolute/path/to/buf format /absolute/path/to/file.proto

The file is not in a workspace; there is no buf.work.yaml anywhere in the file hierarchy.

I'm getting the same error as in #1056:

Failure: source /absolute/path/to/file.proto was not found - is the directory containing this file defined in your buf.work.yaml?

Is there any way around this? I'm mystified that this ever worked.

@bufdev
Copy link
Member

bufdev commented Oct 26, 2023

We'll look into it! Thanks for the bug report.

@andrewparmet
Copy link
Author

andrewparmet commented Oct 26, 2023

Aha - I think I've figured out why it used to work; in a sibling directory we do have a buf.work.yaml - the one generated by buf-gradle-plugin. I can rework our task order to prevent this from breaking, but it can't be a complete solution because we won't be able to achieve build idempotency; as soon as buf-gradle-plugin runs its lint check Spotless will fail again.

It seems odd that this should cause a problem. Here's the relevant portion of my file tree:

.
├── api
│   ├── buf.yaml
│   ├── build
│   │   ├── bufbuild
│   │   │   ├── buf.work.yaml
│   │   │   ├── build-extracted--include--protos-main -> ../extracted-include-protos/main
│   │   │   └── src-main-proto -> ../../src/main/proto
│   ├── build.gradle.kts
│   └── src
│       ├── main
│       │   └── proto
│       │       └── packagename
│       │           └── file.proto

And I'm running /path/to/buf format /path/to/api/src/main/proto/packagename/file.proto

Maybe this is more indicative of how it's breaking?

@andrewparmet
Copy link
Author

Here's the hack that gets it working non-idempotently:

afterEvaluate {
    tasks.withType<WriteWorkspaceYamlTask> {
        dependsOn(tasks.withType<SpotlessTask>())
    }
    tasks.withType<CreateSymLinksToModulesTask> {
        dependsOn(tasks.withType<SpotlessTask>())
    }
}

@nchursin
Copy link

Same issue here. I have no buf.work.yaml at all, buf.yaml and buf.gen.yaml are in the root of the project. Still when I try to format a file, I get

Failure: source /absolute/path/to/file.proto was not found - is the directory containing this file defined in your buf.work.yaml?

Running simply

buf format /path/to/file

I tried both absolute and relative paths, but same result anyway

@bufdev
Copy link
Member

bufdev commented Jan 16, 2024

We're working on some wholesale fixes to path targeting in a branch right now that will come out in the coming weeks - we hope this will be fixed as part of that process.

@doriable doriable added the Cleanup Cleanup tasks label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Cleanup tasks
Projects
None yet
Development

No branches or pull requests

4 participants