Gradle Version Catalog への書き換えツールを作る【python】

素晴らしいツールを公開されています。

👉 takahirom/gradle-version-catalog-converter: Convert `implementation 'androidx.core:core-ktx:1.7.0'` into `androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidxCore" }` hatena-bookmark

結果は以下。

gradle-version-catalog-converter


implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
implementation 'com.google.accompanist:accompanist-swiperefresh:0.26.5-rc'


[versions]
comGoogleAccompanist = "0.17.0"

[libraries]
com-google-accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "comGoogleAccompanist" }
com-google-accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "comGoogleAccompanist" }

build.gradle
implementation libs.com.google.accompanist.systemuicontroller
implementation libs.com.google.accompanist.swiperefresh

build.gradle.kts
implementation(libs.com.google.accompanist.systemuicontroller)
implementation(libs.com.google.accompanist.swiperefresh)

高機能で便利です。

作った動機はだれもが同感できるでしょう。

ということで、

私も python の勉強がてら雑魚ツールを作ります。

クリップボードにコピーした


implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
implementation 'com.google.accompanist:accompanist-swiperefresh:0.26.5-rc'

を python スクリプト実行後すると


* source
  implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
  implementation 'com.google.accompanist:accompanist-swiperefresh:0.26.5-rc'

* gradle/libs.versions.toml
[libraries]
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version = "0.17.0"" }
accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version = "0.26.5-rc" }

* build.gradle
implementation libs.accompanist.systemuicontroller
implementation libs.accompanist.swiperefresh

と表示します。

まずは、ただそれだけです。

[versions] を設定するのもだるい implementation 単独バージョンのライブラリ用。

幼稚なスクリプトなので拡張や変更、削除しやすいです。

重複に注意です。

このへんの変換処理は、

きっと、Android Studio プラグインが登場して、

そのあと、Android Studio に取り込まれいく

のだろうと妄想しています。

それまでのつなぎで。

※ このページは gist を更新しながら更新していきます。

※ 追記: こんなのあったんですね!


👉 「⚠ This project uses Gradle Version Catalogs: this tool may not behave as expected.」→ 今現在、Gradle Version Catalog には gradle-versions-plugin が必須では? hatena-bookmark

👉 【Gradle Version Catalog】libs.versions.toml キー名の形式 camelCase vs kebab-case hatena-bookmark


【Python】「pip search」の代わりは何なの?

モジュールがないといわれるので、


pip search ***

で調べようとしますが、

使えません。

ERROR: XMLRPC request failed [code: -32500] RuntimeError: PyPI's XMLRPC API is currently disabled due to unmanageable load and will be deprecated in the near future.

👉 Remove the pip search command · Issue #5216 · pypa/pip hatena-bookmark

👉 Search results · PyPI hatena-bookmark

代替はこれですかね、「pip-search」 。

ERROR: XMLRPC request failed [code: -32500] RuntimeError: PyPI's XMLRPC API is currently disabled due to unmanageable load and will be deprecated in the near future.

「pip」 にラッパー気味に関数をセットしながら使うといいようです。


alias pip='function _pip(){
    if [ $1 = "search" ]; then
        pip_search "$2";
    else pip "$@";
    fi;
};_pip'

👉 pip-search · PyPI hatena-bookmark

しかしこれ公式ではないですよね?

👉 victorgarric/pip_search: Searching thought pip when hard times strike hatena-bookmark

みんなはどうしてるの?

ブラウザで検索してるの?

最近、python コマンドラインのまわりはいろいろ混乱します。

👉 macOS 12.3 で Python2 が消え、スクリプトが「bad interpreter: /usr/bin/python: no such file or directory」とは。 hatena-bookmark


macOS 12.3 で Python2 が消え、スクリプトが「bad interpreter: /usr/bin/python: no such file or directory」とは。

便利スクリプトツールたちが使えなくなってつらし。


#!/usr/bin/python -u
...

macOS 12.3 で /usr/bin/python は削除され、 /usr/bin/python3 しかないのですが。という件。

👉 `pidcat` installed via `brew` no longer works on macOS 12.3, due to Python 2 having been removed · Issue #180 · JakeWharton/pidcat hatena-bookmark

python 2 をインストールして、そのパスに1行目を書き換える。


#!/usr/bin/env -S python -u


#!/Users/<user>/.pyenv/versions/2.7.18/bin/python -u


#!/usr/local/Cellar/python@2/2.7.15_1/bin/python2 -u

macOS SIP により python から python3ln -s で向けることはできない。

👉 Mac のシステム整合性保護について - Apple サポート (日本) hatena-bookmark

まとめ

pidcat に関しては以下で。


❯ pyenv global 2.7.18

❯ pyenv versions
  system
* 2.7.18 (set by /Users/username/.pyenv/version)
  3.10.4


#!/usr/bin/env -S python -u
...

bad interpreter: /usr/bin/python: no such file or directory

しかし、pyenv て便利なやつだなあ。

👉 pyenv/pyenv: Simple Python version management hatena-bookmark

👉 【Python】「pip search」の代わりは何なの? hatena-bookmark