Skip to content

Commit 99988b9

Browse files
authored
Merge branch 'master' into Fix-AttrDict-copy
2 parents f591902 + 6eefae3 commit 99988b9

File tree

14 files changed

+613
-169
lines changed

14 files changed

+613
-169
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ jobs:
112112
- name: Test fastai notebooks
113113
run: |
114114
cd fastai
115-
nbdev_test --flags '' --n_workers 3 --pause 1.5 --fname "nbs/[0-9]${{matrix.nb}}*.ipynb"
115+
nbdev_test --flags '' --n_workers 3 --pause 1.5 --file_re "[0-9]${{matrix.nb}}.*"

fastcore/_modidx.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Autogenerated by nbdev
22

3-
d = { 'settings': { 'audience': 'Developers',
3+
d = { 'settings': { 'allowed_cell_metadata_keys': '',
4+
'allowed_metadata_keys': '',
5+
'audience': 'Developers',
46
'author': 'Jeremy Howard and Sylvain Gugger',
57
'author_email': '[email protected]',
8+
'black_formatting': 'False',
69
'branch': 'master',
710
'copyright': 'fast.ai',
811
'custom_sidebar': 'False',
@@ -20,8 +23,11 @@
2023
'license': 'apache2',
2124
'min_python': '3.7',
2225
'nbs_path': 'nbs',
26+
'readme_nb': 'index.ipynb',
27+
'recursive': 'False',
2328
'status': '4',
2429
'title': 'fastcore',
30+
'tst_flags': '',
2531
'user': 'fastai',
2632
'version': '1.5.15'},
2733
'syms': { 'fastcore.all': {},

fastcore/foundation.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,19 @@ def read_config_file(file, **kwargs):
249249
# %% ../nbs/02_foundation.ipynb 131
250250
class Config:
251251
"Reading and writing `ConfigParser` ini files"
252-
def __init__(self, cfg_path, cfg_name, create=None):
252+
def __init__(self, cfg_path, cfg_name, create=None, save=True, extra_files=None):
253253
cfg_path = Path(cfg_path).expanduser().absolute()
254254
self.config_path,self.config_file = cfg_path,cfg_path/cfg_name
255-
if not self.config_file.exists():
256-
if create:
257-
self.d = create
255+
self._cfg = ConfigParser()
256+
self.d = self._cfg['DEFAULT']
257+
found = [Path(o) for o in self._cfg.read(L(extra_files)+[self.config_file])]
258+
if self.config_file not in found and create is not None:
259+
self._cfg.read_dict({'DEFAULT':create})
260+
if save:
258261
cfg_path.mkdir(exist_ok=True, parents=True)
259-
self.save()
260-
else: raise FileNotFoundError(f"Could not find {cfg_name}")
261-
self.d = read_config_file(self.config_file)
262+
save_config_file(self.config_file, create)
262263

264+
def __repr__(self): return repr(dict(self._cfg.items('DEFAULT', raw=True)))
263265
def __setitem__(self,k,v): self.d[k] = str(v)
264266
def __contains__(self,k): return k in self.d
265267
def save(self): save_config_file(self.config_file,self.d)

fastcore/imports.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def is_coll(o):
2929

3030
def all_equal(a,b):
3131
"Compares whether `a` and `b` are the same length and have the same contents"
32-
if not is_iter(b): return False
32+
if not is_iter(b): return a==b
3333
return all(equals(a_,b_) for a_,b_ in itertools.zip_longest(a,b))
3434

3535
def noop (x=None, *args, **kwargs):
@@ -49,7 +49,8 @@ def isinstance_str(x, cls_name):
4949
def array_equal(a,b):
5050
if hasattr(a, '__array__'): a = a.__array__()
5151
if hasattr(b, '__array__'): b = b.__array__()
52-
return (a==b).all()
52+
if isinstance_str(a, 'ndarray') and isinstance_str(b, 'ndarray'): return (a==b).all()
53+
return all_equal(a,b)
5354

5455
def df_equal(a,b): return a.equals(b) if isinstance_str(a, 'NDFrame') else b.equals(a)
5556

fastcore/parallel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,21 @@ def add_one(x, a=1):
123123
time.sleep(random.random()/80)
124124
return x+a
125125

126-
# %% ../nbs/03a_parallel.ipynb 22
126+
# %% ../nbs/03a_parallel.ipynb 21
127127
def run_procs(f, f_done, args):
128128
"Call `f` for each item in `args` in parallel, yielding `f_done`"
129129
processes = L(args).map(Process, args=arg0, target=f)
130130
for o in processes: o.start()
131131
yield from f_done()
132132
processes.map(Self.join())
133133

134-
# %% ../nbs/03a_parallel.ipynb 23
134+
# %% ../nbs/03a_parallel.ipynb 22
135135
def _f_pg(obj, queue, batch, start_idx):
136136
for i,b in enumerate(obj(batch)): queue.put((start_idx+i,b))
137137

138138
def _done_pg(queue, items): return (queue.get() for _ in items)
139139

140-
# %% ../nbs/03a_parallel.ipynb 24
140+
# %% ../nbs/03a_parallel.ipynb 23
141141
def parallel_gen(cls, items, n_workers=defaults.cpus, **kwargs):
142142
"Instantiate `cls` in `n_workers` procs & call each on a subset of `items` in parallel."
143143
if not parallelable('n_workers', n_workers): n_workers = 0

fastcore/script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _f(*args, **kwargs):
116116
return tfunc(**merge(args, args_from_prog(func, xtra)))
117117

118118
mod = inspect.getmodule(inspect.currentframe().f_back)
119-
if getattr(mod, __name__, '') =="__main__":
119+
if getattr(mod, '__name__', '') =="__main__":
120120
setattr(mod, func.__name__, _f)
121121
SCRIPT_INFO.func = func.__name__
122122
return _f()

fastcore/xdg.py

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,58 @@
1-
# Copyright © 2016-2021 Scott Stevenson <[email protected]>
2-
# Modifications copyright © 2022 onwards Jeremy Howard
1+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/09_xdg.ipynb.
32

4-
"""XDG Base Directory Specification variables.
3+
# %% auto 0
4+
__all__ = ['xdg_cache_home', 'xdg_config_dirs', 'xdg_config_home', 'xdg_data_dirs', 'xdg_data_home', 'xdg_runtime_dir',
5+
'xdg_state_home']
56

6-
xdg_cache_home(), xdg_config_home(), xdg_data_home(), and xdg_state_home()
7-
return pathlib.Path objects containing the value of the environment variable
8-
named XDG_CACHE_HOME, XDG_CONFIG_HOME, XDG_DATA_HOME, and XDG_STATE_HOME
9-
respectively, or the default defined in the specification if the environment
10-
variable is unset, empty, or contains a relative path rather than absolute
11-
path.
7+
# %% ../nbs/09_xdg.ipynb 3
8+
from .utils import *
129

13-
xdg_config_dirs() and xdg_data_dirs() return a list of pathlib.Path
14-
objects containing the value, split on colons, of the environment
15-
variable named XDG_CONFIG_DIRS and XDG_DATA_DIRS respectively, or the
16-
default defined in the specification if the environment variable is
17-
unset or empty. Relative paths are ignored, as per the specification.
18-
19-
xdg_runtime_dir() returns a pathlib.Path object containing the value of
20-
the XDG_RUNTIME_DIR environment variable, or None if the environment
21-
variable is not set, or contains a relative path rather than absolute path.
22-
"""
23-
24-
import os
25-
from pathlib import Path
26-
from typing import List, Optional
27-
28-
__all__ = [ "xdg_cache_home", "xdg_config_dirs", "xdg_config_home", "xdg_data_dirs", "xdg_data_home", "xdg_runtime_dir", "xdg_state_home",
29-
"XDG_CACHE_HOME", "XDG_CONFIG_DIRS", "XDG_CONFIG_HOME", "XDG_DATA_DIRS", "XDG_DATA_HOME", "XDG_RUNTIME_DIR" ]
30-
31-
32-
def _path_from_env(variable: str, default: Path) -> Path:
10+
# %% ../nbs/09_xdg.ipynb 10
11+
def _path_from_env(variable, default):
3312
value = os.environ.get(variable)
3413
if value and os.path.isabs(value): return Path(value)
3514
return default
3615

37-
def _paths_from_env(variable: str, default: List[Path]) -> List[Path]:
16+
# %% ../nbs/09_xdg.ipynb 11
17+
def _paths_from_env(variable, default):
3818
value = os.environ.get(variable)
3919
if value:
40-
paths = [ Path(path) for path in value.split(":") if os.path.isabs(path) ]
20+
paths = [Path(o) for o in value.split(":") if os.path.isabs(o)]
4121
if paths: return paths
4222
return default
4323

44-
def xdg_cache_home() -> Path:
45-
"""Path corresponding to XDG_CACHE_HOME."""
24+
# %% ../nbs/09_xdg.ipynb 12
25+
def xdg_cache_home():
26+
"Path corresponding to `XDG_CACHE_HOME`"
4627
return _path_from_env("XDG_CACHE_HOME", Path.home()/".cache")
4728

48-
def xdg_config_dirs() -> List[Path]:
49-
"""Paths corresponding to XDG_CONFIG_DIRS."""
29+
# %% ../nbs/09_xdg.ipynb 15
30+
def xdg_config_dirs():
31+
"Paths corresponding to `XDG_CONFIG_DIRS`"
5032
return _paths_from_env("XDG_CONFIG_DIRS", [Path("/etc/xdg")])
5133

52-
def xdg_config_home() -> Path:
53-
"""Path corresponding to XDG_CONFIG_HOME."""
34+
# %% ../nbs/09_xdg.ipynb 17
35+
def xdg_config_home():
36+
"Path corresponding to `XDG_CONFIG_HOME`"
5437
return _path_from_env("XDG_CONFIG_HOME", Path.home()/".config")
5538

56-
def xdg_data_dirs() -> List[Path]:
57-
"""Paths corresponding to XDG_DATA_DIRS."""
58-
return _paths_from_env( "XDG_DATA_DIRS", [Path(path) for path in "/usr/local/share/:/usr/share/".split(":")])
39+
# %% ../nbs/09_xdg.ipynb 19
40+
def xdg_data_dirs():
41+
"Paths corresponding to XDG_DATA_DIRS`"
42+
return _paths_from_env( "XDG_DATA_DIRS", [Path(o) for o in "/usr/local/share/:/usr/share/".split(":")])
5943

60-
def xdg_data_home() -> Path:
61-
"""Path corresponding to XDG_DATA_HOME."""
44+
# %% ../nbs/09_xdg.ipynb 21
45+
def xdg_data_home():
46+
"Path corresponding to `XDG_DATA_HOME`"
6247
return _path_from_env("XDG_DATA_HOME", Path.home()/".local"/"share")
6348

64-
def xdg_runtime_dir() -> Optional[Path]:
65-
"""Path corresponding to XDG_RUNTIME_DIR. """
49+
# %% ../nbs/09_xdg.ipynb 23
50+
def xdg_runtime_dir():
51+
"Path corresponding to `XDG_RUNTIME_DIR`"
6652
value = os.getenv("XDG_RUNTIME_DIR")
6753
return Path(value) if value and os.path.isabs(value) else None
6854

69-
def xdg_state_home() -> Path:
70-
"""Path corresponding to XDG_STATE_HOME."""
55+
# %% ../nbs/09_xdg.ipynb 25
56+
def xdg_state_home():
57+
"Path corresponding to `XDG_STATE_HOME`"
7158
return _path_from_env("XDG_STATE_HOME", Path.home()/".local"/"state")
72-

nbs/.gitattributes

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
**/*.ipynb filter=clean-nbs
2-
**/*.ipynb diff=ipynb
31
*.ipynb merge=nbdev-merge

0 commit comments

Comments
 (0)