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

Conflict between docformatter --check and --in-place options when using Pants #21306

Open
totaln opened this issue Aug 14, 2024 · 10 comments
Open
Labels

Comments

@totaln
Copy link

totaln commented Aug 14, 2024

Describe the bug
When using Pants with docformatter, there's a conflict between the --check and --in-place options. Even though only --check is specified in the configuration, the error message suggests that --in-place is being added somewhere in the process. This prevents docformatter from running correctly through Pants.
Specifically, when running:
pants --docformatter-args="--check --diff" lint test.py
The following error is encountered:

ProcessExecutionFailure: Process 'Run Docformatter on 1 file.' failed with exit code 2.
stderr:
docformatter: error: argument -c/--check: not allowed with argument -i/--in-place

Pants version
2.2.1

OS
MacOS

Additional info

  1. Configuration in pants.toml:
[GLOBAL]
pants_version = "2.21.1"
backend_packages.add = [
  "pants.backend.python.lint.docformatter",
  # ... other backends ...
]


[docformatter]
args = ["--check", "--diff"]
  1. Running docformatter directly on the file works as expected.
  2. Attempts to resolve:
    Explicitly added --no-in-place to the args in pants.toml.
    Updated Pants to the latest version (2.21.1).
    Checked for conflicting configurations in other files.
  3. Questions:
    Why is the--in-place option being added when not specified?
    How can this conflict be resolved by running docformatter with --check through Pants?
    Is there a known issue with docformatter integration in Pants 2.21.1?
@totaln totaln added the bug label Aug 14, 2024
@krishnan-chandra
Copy link
Contributor

Hey there! It looks like --in-place is applied inline as part of the docformatter backend.

Some work may be needed to allow running docformatter in both check and format modes through Pants. If you'd like to contribute it, that'd be most welcome! You can find a similar PR for Ruff here.

@benjyw
Copy link
Contributor

benjyw commented Aug 14, 2024

Presumably we add --in-place so we can capture the outputs easily.

Yeah, running as a checker would require a little work, but probably not much, if you'd like to take it on!

@totaln
Copy link
Author

totaln commented Aug 20, 2024

hi @benjyw , @krishnan-chandra! Is there any happy path (except docs) to run pants locally on the MacOS (M-chip)?
I've been trying for a few days but facing multiple errors with libiconv, tokio, and other libs repeatedly...

@benjyw
Copy link
Contributor

benjyw commented Aug 21, 2024

It should just work and indeed works fine on my M1 by cloning the repo and running pants.

It will be difficult to provide further help without a lot more detail on what you're doing and the exact errors you're seeing...

@totaln
Copy link
Author

totaln commented Aug 21, 2024

I understand.

So I just follow the pants local development guide (installed python3.9, nix-shell, rustup, updated openssl, etc., so it's not just to clone repo and run pants), then under nix-shell running pants, and after some time of compiling it throws different errors:

1. the first error

error[E0432]: unresolved import `tokio::task::Id`
   --> task_executor/src/lib.rs:14:19
    |
14  | use tokio::task::{Id, JoinError, JoinHandle, JoinSet};
    |                   ^^ no `Id` in `task`
    |
note: found an item that was configured out
   --> /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/task/mod.rs:321:40
    |
321 |         pub use crate::runtime::task::{Id, id, try_id};
    |                                        ^^

error[E0599]: no method named `join_next_with_id` found for struct `JoinSet` in the current scope
   --> task_executor/src/lib.rs:324:44
    |
324 |               next_result = inner.task_set.join_next_with_id() => {
    |                                            ^^^^^^^^^^^^^^^^^
    |
help: there is a method `join_next` with a similar name
    |
324 |               next_result = inner.task_set.join_next() => {
    |                                            ~~~~~~~~~

error[E0599]: no method named `id` found for struct `tokio::task::AbortHandle` in the current scope
   --> task_executor/src/lib.rs:291:35
    |
291 |         inner.id_to_name.insert(h.id(), name.to_string());
    |                                   ^^ method not found in `AbortHandle`

error: unused import: `itertools::Itertools`
  --> task_executor/src/lib.rs:11:5
   |
11 | use itertools::Itertools;
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D unused-imports` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unused_imports)]`

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `task_executor` (lib) due to 4 previous errors

2. I tried to change lib.rs to fix it, then this error appeared:

   error: linking with `cc` failed: exit status: 1
  = note: ld: warning: directory not found for option '-L/usr/local/opt/libiconv/lib'
          ld: framework not found DiskArbitration
          clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
          
          error: could not compile `sysinfo` (lib) due to 1 previous error

I tried to run pants both from my terminal and from nix-shell
I have the following paths in my zshrc, but not sure they are correct

export HOMEBREW_PREFIX=$(brew --prefix)
export LIBICONV_PREFIX="$HOMEBREW_PREFIX/opt/libiconv"
export LIBRARY_PATH="$LIBICONV_PREFIX/lib:$LIBRARY_PATH"
export LDFLAGS="-L$LIBICONV_PREFIX/lib $LDFLAGS"
export CPPFLAGS="-I$LIBICONV_PREFIX/include $CPPFLAGS"
export RUSTFLAGS="-L $LIBICONV_PREFIX/lib $RUSTFLAGS"
export SDKROOT=$(xcrun --show-sdk-path)
export PATH="/opt/homebrew/opt/libiconv/bin:$PATH"

so for me, this doesn't seem to be straightforward...sorry if I missed something.

thanks!

@benjyw
Copy link
Contributor

benjyw commented Aug 22, 2024

Ah, it wasn't clear to me that you are trying to build Pants itself, rather than using a released version.

@benjyw
Copy link
Contributor

benjyw commented Aug 22, 2024

You shouldn't need nix-shell, and in fact I have no idea if that would cause problems.

@benjyw
Copy link
Contributor

benjyw commented Aug 22, 2024

But I guess you've run this in terminal and it still fails. That rust compilation error is very suspicious. The Pants rust code should definitely compile without error...

@benjyw
Copy link
Contributor

benjyw commented Aug 22, 2024

tokio-1.32.0 seems like the correct version though.

@benjyw
Copy link
Contributor

benjyw commented Aug 22, 2024

This comment seems relevant:

# NOTE: See `src/rust/engine/.cargo/config` for `--cfg` flags enabled for these crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants