Rust-clippy: Clippy Python scripts portablility

Created on 29 Jun 2018  路  16Comments  路  Source: rust-lang/rust-clippy


Currently all Python scripts in this repository use shebang #!/usr/bin/env python.

The problem

This is bad because python means default system Python which is Python 3 for Arch and scripts don't work.
Other distributions are going to follow it sooner or later because Python 2 won't be maintained since 2020, for an example: Fedora proposal. Also many distributions like Ubuntu, OpenSUSE, Fedora want to ship only with Python 3 preinstalled.

Behaviour on different platforms

I've checked many Linux distributions and all of them had python2, python2.7, python3, python3.X (X differs based on the version).
All I know about OSX is it doesn't have python2 but has python2.7, it would be great if somebody could reply with list of all variants.
MSYS2 (aka windows-gnu) does it just like Linux, no idea about windows-msvc (does #!/usr/bin/env even work there?).

Possible solutions

  1. Use #!/usr/bin/env python2; probably would work everywhere (sometimes it's not installed but available in repo) but note that, Python 2 is almost dead already.
  2. Port scrips to Python 3; I have no idea about OSX and MSVC, should work everywhere else.
  3. RIIR; everything will work on every supported platform, it's win-win but takes more effort.

cc no idea

O-windows P-help-wanted

Most helpful comment

Alternative: Port the scripts to Rust.

All 16 comments

Alternative: Port the scripts to Rust.

RIIR all the things

I feel so dump I haven't thought about it earlier.
Edited OP.

How would option 3 work? Would you create a utility binary crate or somehow use a Rust build script?

Yea, just add a crate and maybe a bat and an sh script for convenient invocation together with a .rustup file pointing to stable so the utils aren't rebuilt whenever nightly is bumped

I guess portability is a good reason to use Rust here. Another good thing about using Rust would be that we can add some unit tests to these scripts. The scripts are somewhat complicated already. I remember that the update_lints script had issues before and there are no tests that prevent those issues from appearing again.

I would be happy to work on this, actually.

@oli-obk Did you mean the rust-toolchain file instead of .rustup?

yes

I have looked a bit into this during my ongoing vacation and I believe this could even be written without using regex so a simple .rs file that implements all the functions would work good enough.

@llogiq Were you thinking of using Clippys lint registry to do it without Regex? I have a basic version that uses regex now, and it seems simple enough to continue.

No, just str::split and friends. But using regex is fine, too.

Quick summary of what's left to do for update_lints.py:

  • [x] Handle -c/--check flag, and use it in CI
  • [x] Generate the pub mod xxx section (gen_mods in update_lints.py)
  • [x] Generate the module::lint_name section (gen_group in update_lints.py)
  • [x] Generate the deprecated lints section (gen_deprecated in update_lints.py)

There's also export.py and lintlib.py which need to be rewritten, too.

I think this is done.

Actually I am not sure it is totally done, unless these two rewriting have been dropped or done by other means?

There's also export.py and lintlib.py which need to be rewritten, too.

They seem to be used only on the CI so there is no portability issue for the developers.

True, we don't have a clippy_dev subcommand to create the lints.json yet, right? lintlib shouldn't be needed anymore AFAIR.

Was this page helpful?
0 / 5 - 0 ratings