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

fix(poetry): parse arg in script shebang line #1028

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

AThePeanut4
Copy link
Contributor

What does this PR do

Parse the shebang line in the poetry wrapper script to ignore leading spaces, and split out any arguments, so that e.g. #! /usr/bin/python3 -sP doesn't error. On Windows, take into account the possibility that the interpreter path may be double-quoted so that it can contain spaces.

Fixes #1021

Standards checklist

  • The PR title is descriptive
  • I have read [CONTRIBUTING.md](http://contributing.md/)
  • Optional: I have tested the code myself
  • If this PR introduces new user-facing messages they are translated

@SteveLauC
Copy link
Member

Thanks for the patch! @AThePeanut4

cc @tsvikas, here is a build for Linux with this patch included, welcome to give it a test: https://github.com/SteveLauC/topgrade/releases/tag/pr1028

@tsvikas
Copy link

tsvikas commented Feb 25, 2025

thanks!

just checked - the patch does work with my poetry :)

however, it seems that the behaviour around uv changed

❯ topgrade --only uv  # topgrade 16.0.2

── 13:04:59 - uv ───────────────────────────────────────────────────────────────
error: uv was installed through an external package manager, and self-update is not available. Please use your package manager to update uv.
Nothing to upgrade

── 13:04:59 - Summary ──────────────────────────────────────────────────────────
uv: OK

~ via 🐍 v3.13.2 
❯ ~/Downloads/topgrade --only uv  # pr1208 link above

── 13:05:06 - uv ───────────────────────────────────────────────────────────────
error: uv was installed through an external package manager, and self-update is not available. Please use your package manager to update uv.
uv failed: 
   0: Command failed: `/usr/bin/uv self update`
   1: `/usr/bin/uv` failed: exit status: 2

Location:
   src/steps/generic.rs:1227
Retry? (y)es/(N)o/(s)hell/(q)uit

── 13:05:07 - Summary ──────────────────────────────────────────────────────────
uv: FAILED

i am using uv 0.5.30 - this is the most recent version available on dnf (fedora 41)

@tsvikas
Copy link

tsvikas commented Feb 25, 2025

verbose output:

❯ ~/Downloads/topgrade --only uv -v
DEBUG Current system locale is en-IL
DEBUG Configuration at /home/tsvika/.config/topgrade.toml
DEBUG Loaded configuration: ConfigFile { include: Some(Include { paths: None }), misc: Some(Misc { pre_sudo: None, sudo_command: None, disable: None, ignore_failures: None, remote_topgrades: None, remote_topgrade_path: None, ssh_arguments: None, tmux_arguments: None, set_title: None, display_time: None, assume_yes: None, no_retry: None, run_in_tmux: None, tmux_session_mode: None, cleanup: None, notify_each_step: None, skip_notify: None, bashit_branch: None, only: None, no_self_update: None, log_filters: None }), pre_commands: Some({}), post_commands: Some({}), commands: Some({}), python: Some(Python { enable_pip_review: None, enable_pip_review_local: None, enable_pipupgrade: None, pipupgrade_arguments: None, poetry_force_self_update: None }), composer: Some(Composer { self_update: None }), brew: Some(Brew { greedy_cask: None, greedy_latest: None, greedy_auto_updates: None, autoremove: None, fetch_head: None }), linux: Some(Linux { yay_arguments: None, aura_aur_arguments: None, aura_pacman_arguments: None, arch_package_manager: None, show_arch_news: None, garuda_update_arguments: None, trizen_arguments: None, pikaur_arguments: None, pamac_arguments: None, dnf_arguments: None, nix_arguments: None, nix_env_arguments: None, apt_arguments: None, enable_tlmgr: None, redhat_distro_sync: None, suse_dup: None, rpm_ostree: None, bootc: None, emerge_sync_flags: None, emerge_update_flags: None, home_manager_arguments: None }), git: Some(Git { max_concurrency: None, arguments: None, repos: None, pull_predefined: None }), containers: Some(Containers { ignored_containers: None, runtime: None }), windows: Some(Windows { accept_all_updates: None, self_rename: None, open_remotes_in_new_terminal: None, wsl_update_pre_release: None, wsl_update_use_web_download: None }), npm: Some(NPM { use_sudo: None }), yarn: Some(Yarn { use_sudo: None }), deno: Some(Deno { version: None }), vim: Some(Vim { force_plug_update: None }), firmware: Some(Firmware { upgrade: None }), vagrant: Some(Vagrant { directories: None, power_on: None, always_suspend: None }), flatpak: Some(Flatpak { use_sudo: None }), distrobox: Some(Distrobox { use_root: None, containers: None }), lensfun: Some(Lensfun { use_sudo: None }), julia: Some(JuliaConfig { startup_file: None }) }
DEBUG Version: 16.0.2
DEBUG OS: x86_64-unknown-linux-gnu
DEBUG Args { inner: ["/home/tsvika/Downloads/topgrade", "--only", "uv", "-v"] }
DEBUG Binary path: Ok("/home/tsvika/Downloads/topgrade")
DEBUG self-update Feature Enabled: false
DEBUG Configuration: Config { opt: CommandLineArgs { edit_config: false, show_config_reference: false, run_in_tmux: false, cleanup: false, dry_run: false, no_retry: false, disable: [], only: [Uv], custom_commands: [], env: [], verbose: true, keep_at_end: false, skip_notify: false, yes: None, disable_predefined_git_repos: false, config: None, remote_host_limit: None, show_skipped: false, log_filter: "warn", gen_completion: None, gen_manpage: false, no_self_update: false }, config_file: ConfigFile { include: Some(Include { paths: None }), misc: Some(Misc { pre_sudo: None, sudo_command: None, disable: None, ignore_failures: None, remote_topgrades: None, remote_topgrade_path: None, ssh_arguments: None, tmux_arguments: None, set_title: None, display_time: None, assume_yes: None, no_retry: None, run_in_tmux: None, tmux_session_mode: None, cleanup: None, notify_each_step: None, skip_notify: None, bashit_branch: None, only: None, no_self_update: None, log_filters: None }), pre_commands: Some({}), post_commands: Some({}), commands: Some({}), python: Some(Python { enable_pip_review: None, enable_pip_review_local: None, enable_pipupgrade: None, pipupgrade_arguments: None, poetry_force_self_update: None }), composer: Some(Composer { self_update: None }), brew: Some(Brew { greedy_cask: None, greedy_latest: None, greedy_auto_updates: None, autoremove: None, fetch_head: None }), linux: Some(Linux { yay_arguments: None, aura_aur_arguments: None, aura_pacman_arguments: None, arch_package_manager: None, show_arch_news: None, garuda_update_arguments: None, trizen_arguments: None, pikaur_arguments: None, pamac_arguments: None, dnf_arguments: None, nix_arguments: None, nix_env_arguments: None, apt_arguments: None, enable_tlmgr: None, redhat_distro_sync: None, suse_dup: None, rpm_ostree: None, bootc: None, emerge_sync_flags: None, emerge_update_flags: None, home_manager_arguments: None }), git: Some(Git { max_concurrency: None, arguments: None, repos: None, pull_predefined: None }), containers: Some(Containers { ignored_containers: None, runtime: None }), windows: Some(Windows { accept_all_updates: None, self_rename: None, open_remotes_in_new_terminal: None, wsl_update_pre_release: None, wsl_update_use_web_download: None }), npm: Some(NPM { use_sudo: None }), yarn: Some(Yarn { use_sudo: None }), deno: Some(Deno { version: None }), vim: Some(Vim { force_plug_update: None }), firmware: Some(Firmware { upgrade: None }), vagrant: Some(Vagrant { directories: None, power_on: None, always_suspend: None }), flatpak: Some(Flatpak { use_sudo: None }), distrobox: Some(Distrobox { use_root: None, containers: None }), lensfun: Some(Lensfun { use_sudo: None }), julia: Some(JuliaConfig { startup_file: None }) }, allowed_steps: [Uv] }
DEBUG Cannot find "pwsh"
DEBUG Cannot find "powershell"
DEBUG Path "/home/tsvika/.config/emacs" doesn't exist
DEBUG Path "/home/tsvika/.emacs.d" doesn't exist
DEBUG Cannot find "doas"
DEBUG Detected "/usr/bin/sudo" as "sudo"
DEBUG Step "uv"
DEBUG Detected "/usr/bin/uv" as "uv"

── 13:09:21 - uv ───────────────────────────────────────────────────────────────
DEBUG Executing command `/usr/bin/uv self --help`
DEBUG Executing command `/usr/bin/uv self update`
error: uv was installed through an external package manager, and self-update is not available. Please use your package manager to update uv.
DEBUG Command failed: Err(
   0: Command failed: `/usr/bin/uv self update`
   1: `/usr/bin/uv` failed: exit status: 2

Location:
   src/steps/generic.rs:1227)
DEBUG Step "uv" failed: 
   0: Command failed: `/usr/bin/uv self update`
   1: `/usr/bin/uv` failed: exit status: 2

Location:
   src/steps/generic.rs:1227
uv failed: 
   0: Command failed: `/usr/bin/uv self update`
   1: `/usr/bin/uv` failed: exit status: 2

Location:
   src/steps/generic.rs:1227
Retry? (y)es/(N)o/(s)hell/(q)uit

@SteveLauC
Copy link
Member

SteveLauC commented Feb 25, 2025

The uv error is not related to this PR, so I will merge this PR:)

Thanks for the patch again! @AThePeanut4

@SteveLauC
Copy link
Member

SteveLauC commented Feb 25, 2025

@tsvikas, please do:

$ uv self --help
$ echo $?

And paste the output

Update: no need to provide the output, I installed uv on my Fedora box.

@AThePeanut4
Copy link
Contributor Author

@tsvikas I'd assume that's caused by #1000, which was merged after the v16.0.2 release. This PR doesn't change anything related to the uv step.

@SteveLauC The issue there is that uv self update can fail even if uv was compiled with self-update support, if it detects that it was installed through a package manager. I think the only reliable way to avoid the error is to actually check the output of uv self update. See https://github.com/astral-sh/uv/blob/275db0668d787866344ac9bb4512077877b4c9b0/crates/uv/src/commands/self_update.rs#L15.

@SteveLauC
Copy link
Member

SteveLauC commented Feb 25, 2025

@AThePeanut4, I think we need to revert https://github.com/topgrade-rs/topgrade/pull/971/files, but reverting it will make #942 happen again 🫠

@SteveLauC SteveLauC merged commit 488ae14 into topgrade-rs:main Feb 25, 2025
12 checks passed
@AThePeanut4 AThePeanut4 deleted the fix-poetry-fedora branch February 25, 2025 12:05
@tsvikas
Copy link

tsvikas commented Feb 25, 2025

awesome thanks!

(shouldn't we move the uv issue to a new issue?)

FYI - uv developers seems very responsive, you might want to request them to have different error codes for 'self update not supported' vs 'self update failed'

@SteveLauC
Copy link
Member

SteveLauC commented Feb 25, 2025

(shouldn't we move the uv issue to a new issue?)

We continue the issue there #942

FYI - uv developers seems very responsive, you might want to request them to have different error codes for 'self update not supported' vs 'self update failed'

Yeah, we should reach out to them if we cannot solve this ourselves

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

Successfully merging this pull request may close these issues.

topgrade errors on the poetry step
3 participants