回答編集履歴

3

追記

2018/09/03 13:56

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -26,11 +26,9 @@
26
26
 
27
27
  ```
28
28
 
29
- ◆追記
29
+ ミニマムコードで問題が再現できたので追記
30
30
 
31
- ミニマムコードで再現できたので追記。
32
-
33
- 実際のファイルは文字で作成し、コマンドプロンプトよりdirファイル名を確認。
31
+ ファイルは文字で作成し、コマンドプロンプトよりdirにて実際のファイル名を確認。
34
32
 
35
33
 
36
34
 
@@ -38,7 +36,7 @@
38
36
 
39
37
  # -*- coding: utf-8 -*-
40
38
 
41
- from pathlib import Path, PurePath
39
+ from pathlib import Path
42
40
 
43
41
  search_target_dir = r"K:\BGM\ENE"
44
42
 
@@ -48,15 +46,27 @@
48
46
 
49
47
  line = "111111_ZA.txt"
50
48
 
49
+
50
+
51
51
  for p in search_target_path.glob("**/" + line):
52
52
 
53
- print(p)
53
+ print(p) # K:\BGM\ENE\111111_za.txt
54
54
 
55
55
  ```
56
56
 
57
+ ◆発生条件
58
+
59
+ 0. OSが`Windows`
60
+
61
+ 0. `Pathlib#glob`の引数に渡したファイル名が`case insensitive`で一致。
62
+
63
+ ※line = "111111_*.txt"なら再現しない。
57
64
 
58
65
 
66
+
59
- 問題が発生するのは**Windows環境**のみかと
67
+ この2つの条件を満たす時に質文の問題が発生する。
68
+
69
+
60
70
 
61
71
  ◆原因
62
72
 
@@ -74,7 +84,7 @@
74
84
 
75
85
  raise NotImplementedError("Non-relative patterns are unsupported")
76
86
 
77
- selector = _make_selector(tuple(pattern_parts)) # こで作ているselectorが最終的な原因
87
+ selector = _make_selector(tuple(pattern_parts)) # この行で作成しているselectorが原因
78
88
 
79
89
  for p in selector.select_from(self):
80
90
 

2

追記

2018/09/03 13:56

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -84,4 +84,4 @@
84
84
 
85
85
 
86
86
 
87
- _PreciseSelector#_select_from関数にブレイクポイントを置て動作確認すると変数の値が分かりやすいかもです。
87
+ [_PreciseSelector#_select_from](https://github.com/python/cpython/blob/3.6/Lib/pathlib.py#L506)関数にブレイクポイントをて動作確認すると変数の値が分かりやすいかもです。

1

原因を追記

2018/09/03 11:55

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -1,12 +1,12 @@
1
- 手元の環境で再現しなかったのでそこまで深くは追いかけてませんが。
2
-
3
1
  ◆実行環境
4
2
 
5
3
  3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]
6
4
 
7
5
 
8
6
 
9
- 「pathlib glob lowercase」でググると[Windows pathlib.Path.glob(pattern) fixed part of the pattern changed to lowercase whereas it should be unchanged.](https://github.com/python/cpython/pull/3087)のPRがあって棄却されているので仕様みたいで
7
+ 「pathlib glob lowercase」でググると[Windows pathlib.Path.glob(pattern) fixed part of the pattern changed to lowercase whereas it should be unchanged.](https://github.com/python/cpython/pull/3087)のPRがあ**宛先ブランチ間違いでReject**されていす。
8
+
9
+ その後、PRが再送信された形跡がないので、**現状の仕様(不具合)**みたいですね。
10
10
 
11
11
 
12
12
 
@@ -25,3 +25,63 @@
25
25
  return [p.lower() for p in parts]
26
26
 
27
27
  ```
28
+
29
+ ◆追記
30
+
31
+ ミニマムコードで再現できたので追記。
32
+
33
+ 実際のファイルは小文字で作成し、コマンドプロンプトよりdirでファイル名を確認。
34
+
35
+
36
+
37
+ ```Python
38
+
39
+ # -*- coding: utf-8 -*-
40
+
41
+ from pathlib import Path, PurePath
42
+
43
+ search_target_dir = r"K:\BGM\ENE"
44
+
45
+ search_target_path = Path(search_target_dir)
46
+
47
+
48
+
49
+ line = "111111_ZA.txt"
50
+
51
+ for p in search_target_path.glob("**/" + line):
52
+
53
+ print(p)
54
+
55
+ ```
56
+
57
+
58
+
59
+ 問題が発生するのは**Windows環境**のみかと。
60
+
61
+ ◆原因
62
+
63
+ [pathlib.py#glob](https://github.com/python/cpython/blob/3.6/Lib/pathlib.py#L1095)より引用
64
+
65
+
66
+
67
+ ```Python
68
+
69
+ pattern = self._flavour.casefold(pattern) # この行でglobで渡された引数を小文字に
70
+
71
+ drv, root, pattern_parts = self._flavour.parse_parts((pattern,)) # pattern_partsに
72
+
73
+ if drv or root:
74
+
75
+ raise NotImplementedError("Non-relative patterns are unsupported")
76
+
77
+ selector = _make_selector(tuple(pattern_parts)) # ここで作っているselectorが最終的な原因
78
+
79
+ for p in selector.select_from(self):
80
+
81
+ yield p
82
+
83
+ ```
84
+
85
+
86
+
87
+ _PreciseSelector#_select_from関数にブレイクポイントを置いて動作確認すると変数の値が分かりやすいかもです。