Comptibility issues with ruby 3.1

17 views
Skip to first unread message

Kazuhiro Ito

unread,
Oct 10, 2022, 7:32:19 AM10/10/22
to mhc-...@googlegroups.com
伊藤です。

MSYS2 で入る MinGW64 の Ruby が 3.1.2 になったのですが、
YAML.load の非互換性に関する問題でエラーが起きるようになったので
報告です。

https://www.docswell.com/s/pink_bangbi/K67RV5-2022-01-06-201330

のスライドが分かりやすいと思いますが、

--- a/lib/mhc/config.rb
+++ b/lib/mhc/config.rb
@@ -52,7 +52,7 @@ module Mhc
end

def self.create_from_yaml_string(yaml_string, filename = nil)
- hash = YAML.load(yaml_string, filename) || {}
+ hash = YAML.load(yaml_string, filename: filename) || {}
return new(hash)
end

のよな変更が必要になります。
また、 samples/DOT.mhc-config.yml で使われている alias が使えない
ようなので、これも変更する必要がありそうです。
alias を使いつつ Ruby 3.1 と古いバージョンで両立できるコードの書き方が
あるのかはよく分かりませんでした。

--
伊藤 和博(Kazuhiro Ito)

Kazuhiro NISHIYAMA

unread,
Oct 10, 2022, 8:21:27 PM10/10/22
to mhc-...@googlegroups.com
西山和広です。

古いバージョンと同時に対応するには
https://github.com/rails/rails/blob/ca114316475326962493c294df3e9a1b3922474e/activesupport/lib/active_support/encrypted_configuration.rb#L60-L62
のように YAML.respond_to?(:unsafe_load) で分岐すれば alias 対応を両立できそうです。

2022年10月10日(月) 20:32 Kazuhiro Ito <kz...@d1.dion.ne.jp>:
> --
> You received this message because you are subscribed to the Google Groups "mhc-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mhc-talk+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mhc-talk/86y1tnc3sy.wl--xmue%40d1.dion.ne.jp.

Yoshinari Nomura

unread,
Oct 10, 2022, 8:59:35 PM10/10/22
to mhc-...@googlegroups.com
伊藤さん,皆さん,乃村です.

御無沙汰しています.情報ありがとうございます.
修正したいと思います.

> config = YAML.respond_to?(:unsafe_load) ?
> YAML.unsafe_load(content, filename: content_path) :
> YAML.load(content, filename: content_path)

ということは,3.1 以前でも filename: content_path の
記法を受け付けるってことですかね.いつからなのだろう.

余談ですが,MHC は CalDAV で Google カレンダーとやりとりしています.
少し前から mhc の設定ファイルにアカウントのパスワードを書いている
人は同期が失敗するようになったかもしれません.

これは,以前から「アプリパスワード」を設定することで回避できます.
myaccount.google.com/security から,「アプリパスワード」を選択,
「カレンダー」「Mac」で追加してやると,ランダムなパスワードが生成される
ので,それを使って認証する方法です.

OAuth 使って Google Calendar API を使うほうがいいのかもしれませんが,
対応できていません.

On Mon, 10 Oct 2022 20:32:13 +0900,
Kazuhiro Ito said:

> +++ b/lib/mhc/config.rb
> @@ -52,7 +52,7 @@ module Mhc
> end
>
> def self.create_from_yaml_string(yaml_string, filename = nil)
> - hash = YAML.load(yaml_string, filename) || {}
> + hash = YAML.load(yaml_string, filename: filename) || {}
> return new(hash)
> end

Kazuhiro Ito

unread,
Oct 11, 2022, 5:00:01 AM10/11/22
to mhc-...@googlegroups.com
伊藤です。

> > config = YAML.respond_to?(:unsafe_load) ?
> > YAML.unsafe_load(content, filename: content_path) :
> > YAML.load(content, filename: content_path)
>
> ということは,3.1 以前でも filename: content_path の
> 記法を受け付けるってことですかね.いつからなのだろう.

対応するコミットは

https://github.com/ruby/psych/commit/4d4439d6d0adfcbd211ea295779315f1baa7dadd

で、psych としては 3.1.0 からで、 Ruby のバージョンだと 2.6 からのようです。
# ちなみに、Cygwin の Ruby は 2.6.4 です。

もう少し古い環境にも対応させるなら

config = YAML.respond_to?(:unsafe_load) ?
YAML.unsafe_load(content, filename: content_path) :
YAML.load(content, content_path)

のような感じでしょうか。

--
伊藤 和博(Kazuhiro Ito)

Yoshinari Nomura

unread,
Oct 12, 2022, 5:06:06 AM10/12/22
to mhc-...@googlegroups.com
伊藤さん,西山さん,皆さん乃村です.

ありがとうございます.以下の変更を master に
push しました.動作確認いただけると助かります.

diff --git a/lib/mhc/config.rb b/lib/mhc/config.rb
index 9861cc9..5f6c718 100644
--- a/lib/mhc/config.rb
+++ b/lib/mhc/config.rb
@@ -52,7 +52,11 @@ def self.create_from_yaml_file(yaml_file)
end

def self.create_from_yaml_string(yaml_string, filename = nil)
- hash = YAML.load(yaml_string, filename) || {}
+ hash = if YAML.respond_to?(:unsafe_load)
+ YAML.unsafe_load(yaml_string, filename: filename)
+ else
+ YAML.load(yaml_string, filename)
+ end || {}
return new(hash)
end

依存する thor の更新で PR いただいていますね.
ちょっと確認してみます.
--
nom

Kazuhiro Ito

unread,
Oct 12, 2022, 11:28:56 AM10/12/22
to mhc-...@googlegroups.com
伊藤です。

> ありがとうございます.以下の変更を master に
> push しました.動作確認いただけると助かります.

対応ありがとうございました。Ruby 3.1.2 と 2.6.4 で動作を確認しました。

> 依存する thor の更新で PR いただいていますね.
> ちょっと確認してみます.

PR のところには大分はしょって書いてますが、Ruby 3.1 と古い thor の
組み合わせだと warning が表示されて、Emacs で M-x mhc した際にエラーに
なるというものです。
よろしくお願いします。

--
伊藤 和博(Kazuhiro Ito)

Yoshinari Nomura

unread,
Oct 13, 2022, 2:03:28 AM10/13/22
to mhc-...@googlegroups.com
乃村です.

On Thu, 13 Oct 2022 00:28:51 +0900,
Kazuhiro Ito <kz...@d1.dion.ne.jp> said:

> PR のところには大分はしょって書いてますが、Ruby 3.1 と古い thor の
> 組み合わせだと warning が表示されて、Emacs で M-x mhc した際にエラーに
> なるというものです。
> よろしくお願いします。

マージしておきました.

これに加えて gemspec に rexml を足しました.
bundled gems というのになったようです.
--
nom

Kazuhiro Ito

unread,
Oct 13, 2022, 9:49:15 AM10/13/22
to mhc-...@googlegroups.com
伊藤です。

対応ありがとうございました。

> これに加えて gemspec に rexml を足しました.
> bundled gems というのになったようです.

こちらでも rexml の追加は必要だったのですが、Ruby のバージョンだけの
問題かがよく分かってなかったので保留にしていました。

--
伊藤 和博(Kazuhiro Ito)
Reply all
Reply to author
Forward
0 new messages