Skip to content

Commit 76603b8

Browse files
authored
Merge pull request #454 from seeM/nbify-xdg
convert `xdg` to a notebook
2 parents 6c726a0 + 80640e3 commit 76603b8

File tree

5 files changed

+427
-52
lines changed

5 files changed

+427
-52
lines changed

fastcore/_modidx.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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]',
68
'black_formatting': 'False',
@@ -27,7 +29,7 @@
2729
'title': 'fastcore',
2830
'tst_flags': '',
2931
'user': 'fastai',
30-
'version': '1.5.14'},
32+
'version': '1.5.15'},
3133
'syms': { 'fastcore.all': {},
3234
'fastcore.basics': { 'fastcore.basics.AttrDict': 'https://fastcore.fast.ai/basics.html#attrdict',
3335
'fastcore.basics.Float': 'https://fastcore.fast.ai/basics.html#float',
@@ -395,6 +397,13 @@
395397
'fastcore.transform.get_func': 'https://fastcore.fast.ai/transform.html#get_func',
396398
'fastcore.transform.mk_transform': 'https://fastcore.fast.ai/transform.html#mk_transform'},
397399
'fastcore.utils': {},
400+
'fastcore.xdg': { 'fastcore.xdg.xdg_cache_home': 'https://fastcore.fast.ai/xdg.html#xdg_cache_home',
401+
'fastcore.xdg.xdg_config_dirs': 'https://fastcore.fast.ai/xdg.html#xdg_config_dirs',
402+
'fastcore.xdg.xdg_config_home': 'https://fastcore.fast.ai/xdg.html#xdg_config_home',
403+
'fastcore.xdg.xdg_data_dirs': 'https://fastcore.fast.ai/xdg.html#xdg_data_dirs',
404+
'fastcore.xdg.xdg_data_home': 'https://fastcore.fast.ai/xdg.html#xdg_data_home',
405+
'fastcore.xdg.xdg_runtime_dir': 'https://fastcore.fast.ai/xdg.html#xdg_runtime_dir',
406+
'fastcore.xdg.xdg_state_home': 'https://fastcore.fast.ai/xdg.html#xdg_state_home'},
398407
'fastcore.xtras': { 'fastcore.xtras.ContextManagers': 'https://fastcore.fast.ai/xtras.html#contextmanagers',
399408
'fastcore.xtras.EventTimer': 'https://fastcore.fast.ai/xtras.html#eventtimer',
400409
'fastcore.xtras.EventTimer.add': 'https://fastcore.fast.ai/xtras.html#eventtimer.add',

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-

0 commit comments

Comments
 (0)