File tree 3 files changed +18
-7
lines changed
3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change
1
+ New in master
2
+ =============
3
+
4
+ Features
5
+ --------
6
+
7
+ * Better support for a tree of files in ``data/ ``
8
+
1
9
New in v7.8.0
2
10
=============
3
11
Original file line number Diff line number Diff line change 32
32
from copy import copy
33
33
from pkg_resources import resource_filename
34
34
import datetime
35
- import glob
36
35
import locale
37
36
import os
38
37
import json
@@ -1136,12 +1135,13 @@ def _set_global_context_from_config(self):
1136
1135
1137
1136
def _set_global_context_from_data (self ):
1138
1137
"""Load files from data/ and put them in the global context."""
1139
- self ._GLOBAL_CONTEXT ['data' ] = {}
1140
- for fname in glob .glob ('data/*' ):
1141
- data = utils .load_data (fname )
1142
- key = os .path .basename (fname )
1143
- key = os .path .splitext (key )[0 ]
1144
- self ._GLOBAL_CONTEXT ['data' ][key ] = data
1138
+ self ._GLOBAL_CONTEXT ['data' ] = defaultdict (defaultdict )
1139
+ for root , dirs , files in os .walk ('data' , followlinks = True ):
1140
+ for fname in files :
1141
+ fname = os .path .join (root , fname )
1142
+ data = utils .load_data (fname )
1143
+ key = os .path .splitext (fname .split (os .sep , 1 )[1 ])[0 ]
1144
+ self ._GLOBAL_CONTEXT ['data' ][key ] = data
1145
1145
1146
1146
def _activate_plugins_of_category (self , category ):
1147
1147
"""Activate all the plugins of a given category and return them."""
Original file line number Diff line number Diff line change @@ -1923,6 +1923,7 @@ def prefixed_lines():
1923
1923
def load_data (path ):
1924
1924
"""Given path to a file, load data from it."""
1925
1925
ext = os .path .splitext (path )[- 1 ]
1926
+ loader = None
1926
1927
if ext in {'.yml' , '.yaml' }:
1927
1928
loader = yaml
1928
1929
if yaml is None :
@@ -1935,5 +1936,7 @@ def load_data(path):
1935
1936
req_missing (['toml' ], 'use TOML data files' )
1936
1937
return {}
1937
1938
loader = toml
1939
+ if loader is None :
1940
+ return
1938
1941
with io .open (path , 'r' , encoding = 'utf8' ) as inf :
1939
1942
return loader .load (inf )
You can’t perform that action at this time.
0 commit comments