Skip to content

Commit a2ca8e4

Browse files
committed
remove some xdg tests
1 parent 101c4f6 commit a2ca8e4

File tree

7 files changed

+56
-50
lines changed

7 files changed

+56
-50
lines changed

fastcore/_modidx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'branch': 'master',
1010
'clean_ids': 'True',
1111
'copyright': 'fast.ai',
12+
'custom_quarto_yml': 'False',
1213
'custom_sidebar': 'False',
1314
'description': 'Python supercharged for fastai development',
1415
'dev_requirements': 'numpy nbdev>=0.2.39 matplotlib pillow torch pandas jupyterlab',

fastcore/docments.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ def isdataclass(s):
3939
"Check if `s` is a dataclass but not a dataclass' instance"
4040
return is_dataclass(s) and isclass(s)
4141

42+
# %% ../nbs/06_docments.ipynb 19
4243
def get_dataclass_source(s):
4344
"Get source code for dataclass `s`"
4445
return getsource(s) if not getattr(s, "__module__") == '__main__' else ""
4546

47+
# %% ../nbs/06_docments.ipynb 20
4648
def get_source(s):
4749
"Get source code for string, function object or dataclass `s`"
4850
return getsource(s) if isfunction(s) or ismethod(s) else get_dataclass_source(s) if isdataclass(s) else s
4951

52+
# %% ../nbs/06_docments.ipynb 21
5053
def _parses(s):
5154
"Parse Python code in string, function object or dataclass `s`"
5255
return parse(dedent(get_source(s)))
@@ -75,10 +78,10 @@ def _param_locs(s, returns=True):
7578
return res
7679
return None
7780

78-
# %% ../nbs/06_docments.ipynb 19
81+
# %% ../nbs/06_docments.ipynb 22
7982
empty = Parameter.empty
8083

81-
# %% ../nbs/06_docments.ipynb 20
84+
# %% ../nbs/06_docments.ipynb 23
8285
def _get_comment(line, arg, comments, parms):
8386
if line in comments: return comments[line].strip()
8487
line -= 1
@@ -92,7 +95,7 @@ def _get_full(anno, name, default, docs):
9295
if anno==empty and default!=empty: anno = type(default)
9396
return AttrDict(docment=docs.get(name), anno=anno, default=default)
9497

95-
# %% ../nbs/06_docments.ipynb 21
98+
# %% ../nbs/06_docments.ipynb 24
9699
def _merge_doc(dm, npdoc):
97100
if not npdoc: return dm
98101
if not dm.anno or dm.anno==empty: dm.anno = npdoc.type
@@ -105,14 +108,14 @@ def _merge_docs(dms, npdocs):
105108
if 'return' in dms: params['return'] = _merge_doc(dms['return'], npdocs['Returns'])
106109
return params
107110

108-
# %% ../nbs/06_docments.ipynb 22
111+
# %% ../nbs/06_docments.ipynb 25
109112
def _get_property_name(p):
110113
"Get the name of property `p`"
111114
if hasattr(p, 'fget'):
112115
return p.fget.func.__qualname__ if hasattr(p.fget, 'func') else p.fget.__qualname__
113116
else: return next(iter(re.findall(r'\'(.*)\'', str(p)))).split('.')[-1]
114117

115-
# %% ../nbs/06_docments.ipynb 23
118+
# %% ../nbs/06_docments.ipynb 26
116119
def get_name(obj):
117120
"Get the name of `obj`"
118121
if hasattr(obj, '__name__'): return obj.__name__
@@ -121,14 +124,14 @@ def get_name(obj):
121124
elif type(obj)==property: return _get_property_name(obj)
122125
else: return str(obj).split('.')[-1]
123126

124-
# %% ../nbs/06_docments.ipynb 25
127+
# %% ../nbs/06_docments.ipynb 28
125128
def qual_name(obj):
126129
"Get the qualified name of `obj`"
127130
if hasattr(obj,'__qualname__'): return obj.__qualname__
128131
if ismethod(obj): return f"{get_name(obj.__self__)}.{get_name(fn)}"
129132
return get_name(obj)
130133

131-
# %% ../nbs/06_docments.ipynb 27
134+
# %% ../nbs/06_docments.ipynb 30
132135
def _docments(s, returns=True, eval_str=False):
133136
"`dict` of parameter names to 'docment-style' comments in function or string `s`"
134137
nps = parse_docstring(s)
@@ -148,12 +151,12 @@ def _docments(s, returns=True, eval_str=False):
148151
if k in hints: v['anno'] = hints.get(k)
149152
return res
150153

151-
# %% ../nbs/06_docments.ipynb 28
154+
# %% ../nbs/06_docments.ipynb 31
152155
@delegates(_docments)
153156
def docments(elt, full=False, **kwargs):
154157
"Generates a `docment`"
155158
res = _docments(elt, **kwargs)
156-
if hasattr(elt, "__delwrap__"): #for delegates
159+
if hasattr(elt, "__delwrap__"): # for delegates
157160
delwrap_dict = _docments(elt.__delwrap__, **kwargs)
158161
verbose = getattr(elt,'__delopts__',{}).get('verbose',True)
159162
for k,v in res.items():

fastcore/xdg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ def xdg_data_dirs():
4141
"Paths corresponding to XDG_DATA_DIRS`"
4242
return _paths_from_env( "XDG_DATA_DIRS", [Path(o) for o in "/usr/local/share/:/usr/share/".split(":")])
4343

44-
# %% ../nbs/09_xdg.ipynb 21
44+
# %% ../nbs/09_xdg.ipynb 20
4545
def xdg_data_home():
4646
"Path corresponding to `XDG_DATA_HOME`"
4747
return _path_from_env("XDG_DATA_HOME", Path.home()/".local"/"share")
4848

49-
# %% ../nbs/09_xdg.ipynb 23
49+
# %% ../nbs/09_xdg.ipynb 22
5050
def xdg_runtime_dir():
5151
"Path corresponding to `XDG_RUNTIME_DIR`"
5252
value = os.getenv("XDG_RUNTIME_DIR")
5353
return Path(value) if value and os.path.isabs(value) else None
5454

55-
# %% ../nbs/09_xdg.ipynb 25
55+
# %% ../nbs/09_xdg.ipynb 23
5656
def xdg_state_home():
5757
"Path corresponding to `XDG_STATE_HOME`"
5858
return _path_from_env("XDG_STATE_HOME", Path.home()/".local"/"state")

nbs/06_docments.ipynb

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,40 @@
221221
"#|export\n",
222222
"def isdataclass(s):\n",
223223
" \"Check if `s` is a dataclass but not a dataclass' instance\"\n",
224-
" return is_dataclass(s) and isclass(s)\n",
225-
"\n",
224+
" return is_dataclass(s) and isclass(s)"
225+
]
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": null,
230+
"metadata": {},
231+
"outputs": [],
232+
"source": [
233+
"#|export\n",
226234
"def get_dataclass_source(s):\n",
227235
" \"Get source code for dataclass `s`\"\n",
228-
" return getsource(s) if not getattr(s, \"__module__\") == '__main__' else \"\"\n",
229-
"\n",
236+
" return getsource(s) if not getattr(s, \"__module__\") == '__main__' else \"\""
237+
]
238+
},
239+
{
240+
"cell_type": "code",
241+
"execution_count": null,
242+
"metadata": {},
243+
"outputs": [],
244+
"source": [
245+
"#|export\n",
230246
"def get_source(s):\n",
231247
" \"Get source code for string, function object or dataclass `s`\"\n",
232-
" return getsource(s) if isfunction(s) or ismethod(s) else get_dataclass_source(s) if isdataclass(s) else s\n",
233-
"\n",
248+
" return getsource(s) if isfunction(s) or ismethod(s) else get_dataclass_source(s) if isdataclass(s) else s"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": null,
254+
"metadata": {},
255+
"outputs": [],
256+
"source": [
257+
"#|export\n",
234258
"def _parses(s):\n",
235259
" \"Parse Python code in string, function object or dataclass `s`\"\n",
236260
" return parse(dedent(get_source(s)))\n",
@@ -412,7 +436,7 @@
412436
"def docments(elt, full=False, **kwargs):\n",
413437
" \"Generates a `docment`\"\n",
414438
" res = _docments(elt, **kwargs)\n",
415-
" if hasattr(elt, \"__delwrap__\"): #for delegates\n",
439+
" if hasattr(elt, \"__delwrap__\"): # for delegates\n",
416440
" delwrap_dict = _docments(elt.__delwrap__, **kwargs)\n",
417441
" verbose = getattr(elt,'__delopts__',{}).get('verbose',True)\n",
418442
" for k,v in res.items():\n",

nbs/08_script.ipynb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"metadata": {},
161161
"outputs": [],
162162
"source": [
163+
"#|hide\n",
163164
"from fastcore.test import *"
164165
]
165166
},
@@ -561,9 +562,11 @@
561562
"source": [
562563
"@call_parse\n",
563564
"def test_add(\n",
564-
" a:int, # param a\n",
565-
" b:int # param 1\n",
566-
"): return a + b"
565+
" a:int=0, # param a\n",
566+
" b:int=0 # param 1\n",
567+
"):\n",
568+
" \"Add up `a` and `b`\"\n",
569+
" return a + b"
567570
]
568571
},
569572
{
@@ -622,9 +625,7 @@
622625
"outputs": [],
623626
"source": [
624627
"#|hide\n",
625-
"#|eval: false\n",
626-
"from nbdev import nbdev_export\n",
627-
"nbdev_export()"
628+
"import nbdev; nbdev.nbdev_export()"
628629
]
629630
},
630631
{

nbs/09_xdg.ipynb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -243,18 +243,6 @@
243243
" return _paths_from_env( \"XDG_DATA_DIRS\", [Path(o) for o in \"/usr/local/share/:/usr/share/\".split(\":\")])"
244244
]
245245
},
246-
{
247-
"cell_type": "code",
248-
"execution_count": null,
249-
"id": "a87fd3a8",
250-
"metadata": {},
251-
"outputs": [],
252-
"source": [
253-
"test_eq(xdg_data_dirs(), [Path('/usr/local/share'), Path('/usr/share')])\n",
254-
"with env('XDG_DATA_DIRS', '/home/fastai/.xdg:/home/fastai/.data'):\n",
255-
" test_eq(xdg_data_dirs(), [Path('/home/fastai/.xdg'), Path('/home/fastai/.data')])"
256-
]
257-
},
258246
{
259247
"cell_type": "code",
260248
"execution_count": null,
@@ -294,19 +282,6 @@
294282
" return Path(value) if value and os.path.isabs(value) else None"
295283
]
296284
},
297-
{
298-
"cell_type": "code",
299-
"execution_count": null,
300-
"id": "fb098eba",
301-
"metadata": {},
302-
"outputs": [],
303-
"source": [
304-
"assert (xdg_runtime_dir() is None # macos\n",
305-
" or xdg_runtime_dir().parent == Path('/run/user/')) # ubuntu\n",
306-
"with env('XDG_RUNTIME_DIR', '/home/fastai/.data'):\n",
307-
" test_eq(xdg_runtime_dir(), Path('/home/fastai/.data'))"
308-
]
309-
},
310285
{
311286
"cell_type": "code",
312287
"execution_count": null,

settings.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ allowed_cell_metadata_keys =
3232
jupyter_hooks = True
3333
clean_ids = True
3434

35+
#console_scripts = fc1=fastcore.script:test_add
36+

0 commit comments

Comments
 (0)