fastcore 2.2.7__tar.gz → 2.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {fastcore-2.2.7/fastcore.egg-info → fastcore-2.2.9}/PKG-INFO +1 -1
  2. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/__init__.py +1 -1
  3. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/_modidx.py +9 -0
  4. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/basics.py +42 -22
  5. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/xtras.py +21 -5
  6. {fastcore-2.2.7 → fastcore-2.2.9/fastcore.egg-info}/PKG-INFO +1 -1
  7. {fastcore-2.2.7 → fastcore-2.2.9}/CONTRIBUTING.md +0 -0
  8. {fastcore-2.2.7 → fastcore-2.2.9}/LICENSE +0 -0
  9. {fastcore-2.2.7 → fastcore-2.2.9}/MANIFEST.in +0 -0
  10. {fastcore-2.2.7 → fastcore-2.2.9}/README.md +0 -0
  11. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/aio.py +0 -0
  12. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/all.py +0 -0
  13. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/ansi.py +0 -0
  14. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/apisurface.py +0 -0
  15. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/dispatch.py +0 -0
  16. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/docments.py +0 -0
  17. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/docscrape.py +0 -0
  18. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/editskill.py +0 -0
  19. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/foundation.py +0 -0
  20. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/funccall.py +0 -0
  21. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/imghdr.py +0 -0
  22. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/imports.py +0 -0
  23. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/meta.py +0 -0
  24. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/nb_imports.py +0 -0
  25. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/nbio.py +0 -0
  26. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/net.py +0 -0
  27. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/parallel.py +0 -0
  28. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/py2pyi.py +0 -0
  29. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/script.py +0 -0
  30. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/shutil.py +0 -0
  31. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/style.py +0 -0
  32. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/test.py +0 -0
  33. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/tools.py +0 -0
  34. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/transform.py +0 -0
  35. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/utils.py +0 -0
  36. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/xdg.py +0 -0
  37. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore/xml.py +0 -0
  38. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.7 → fastcore-2.2.9}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.7 → fastcore-2.2.9}/pyproject.toml +0 -0
  44. {fastcore-2.2.7 → fastcore-2.2.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.7
3
+ Version: 2.2.9
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License: Apache-2.0
@@ -55,4 +55,4 @@ Modules:
55
55
  - `fastcore.xml`: Concise generation of XML.
56
56
  - `fastcore.xtras`: Utility functions used in the fastai library"""
57
57
 
58
- __version__ = "2.2.7"
58
+ __version__ = "2.2.9"
@@ -207,6 +207,7 @@ d = { 'settings': { 'branch': 'main',
207
207
  'fastcore.basics.groupby': ('basics.html#groupby', 'fastcore/basics.py'),
208
208
  'fastcore.basics.hasattrs': ('basics.html#hasattrs', 'fastcore/basics.py'),
209
209
  'fastcore.basics.humanize': ('basics.html#humanize', 'fastcore/basics.py'),
210
+ 'fastcore.basics.id_words': ('basics.html#id_words', 'fastcore/basics.py'),
210
211
  'fastcore.basics.ifnone': ('basics.html#ifnone', 'fastcore/basics.py'),
211
212
  'fastcore.basics.ignore_exceptions': ('basics.html#ignore_exceptions', 'fastcore/basics.py'),
212
213
  'fastcore.basics.ignore_exceptions.__enter__': ( 'basics.html#ignore_exceptions.__enter__',
@@ -272,10 +273,14 @@ d = { 'settings': { 'branch': 'main',
272
273
  'fastcore.basics.str_enum': ('basics.html#str_enum', 'fastcore/basics.py'),
273
274
  'fastcore.basics.strcat': ('basics.html#strcat', 'fastcore/basics.py'),
274
275
  'fastcore.basics.to_bool': ('basics.html#to_bool', 'fastcore/basics.py'),
276
+ 'fastcore.basics.to_camel': ('basics.html#to_camel', 'fastcore/basics.py'),
275
277
  'fastcore.basics.to_date': ('basics.html#to_date', 'fastcore/basics.py'),
276
278
  'fastcore.basics.to_float': ('basics.html#to_float', 'fastcore/basics.py'),
277
279
  'fastcore.basics.to_int': ('basics.html#to_int', 'fastcore/basics.py'),
280
+ 'fastcore.basics.to_kebab': ('basics.html#to_kebab', 'fastcore/basics.py'),
278
281
  'fastcore.basics.to_list': ('basics.html#to_list', 'fastcore/basics.py'),
282
+ 'fastcore.basics.to_pascal': ('basics.html#to_pascal', 'fastcore/basics.py'),
283
+ 'fastcore.basics.to_snake': ('basics.html#to_snake', 'fastcore/basics.py'),
279
284
  'fastcore.basics.tonull': ('basics.html#tonull', 'fastcore/basics.py'),
280
285
  'fastcore.basics.true': ('basics.html#true', 'fastcore/basics.py'),
281
286
  'fastcore.basics.try_attrs': ('basics.html#try_attrs', 'fastcore/basics.py'),
@@ -891,6 +896,9 @@ d = { 'settings': { 'branch': 'main',
891
896
  'fastcore.xtras.SaveReturn': ('xtras.html#savereturn', 'fastcore/xtras.py'),
892
897
  'fastcore.xtras.SaveReturn.__init__': ('xtras.html#savereturn.__init__', 'fastcore/xtras.py'),
893
898
  'fastcore.xtras.SaveReturn.__iter__': ('xtras.html#savereturn.__iter__', 'fastcore/xtras.py'),
899
+ 'fastcore.xtras.TruncatedString': ('xtras.html#truncatedstring', 'fastcore/xtras.py'),
900
+ 'fastcore.xtras.TruncatedString.__new__': ('xtras.html#truncatedstring.__new__', 'fastcore/xtras.py'),
901
+ 'fastcore.xtras.TruncatedString.__repr__': ('xtras.html#truncatedstring.__repr__', 'fastcore/xtras.py'),
894
902
  'fastcore.xtras.Unset': ('xtras.html#unset', 'fastcore/xtras.py'),
895
903
  'fastcore.xtras.Unset.__bool__': ('xtras.html#unset.__bool__', 'fastcore/xtras.py'),
896
904
  'fastcore.xtras.Unset.__repr__': ('xtras.html#unset.__repr__', 'fastcore/xtras.py'),
@@ -982,6 +990,7 @@ d = { 'settings': { 'branch': 'main',
982
990
  'fastcore.xtras.timed_cache': ('xtras.html#timed_cache', 'fastcore/xtras.py'),
983
991
  'fastcore.xtras.trace': ('xtras.html#trace', 'fastcore/xtras.py'),
984
992
  'fastcore.xtras.trim_wraps': ('xtras.html#trim_wraps', 'fastcore/xtras.py'),
993
+ 'fastcore.xtras.trunc_ctr': ('xtras.html#trunc_ctr', 'fastcore/xtras.py'),
985
994
  'fastcore.xtras.truncstr': ('xtras.html#truncstr', 'fastcore/xtras.py'),
986
995
  'fastcore.xtras.type2str': ('xtras.html#type2str', 'fastcore/xtras.py'),
987
996
  'fastcore.xtras.unqid': ('xtras.html#unqid', 'fastcore/xtras.py'),
@@ -44,20 +44,20 @@ __all__ = ['defaults', 'null', 'num_methods', 'rnum_methods', 'inum_methods', 'a
44
44
  'risinstance', 'ver2tuple', 'Inf', 'in_', 'ret_true', 'ret_false', 'stop', 'gen', 'chunked', 'otherwise',
45
45
  'custom_dir', 'adict', 'AttrDict', 'AttrDictDefault', 'NS', 'get_annotations_ex', 'eval_type', 'type_hints',
46
46
  'annotations', 'anno_ret', 'signature_ex', 'union2tuple', 'argnames', 'with_cast', 'store_attr', 'attrdict',
47
- 'properties', 'camel2words', 'camel2snake', 'snake2camel', 'humanize', 'class2attr', 'getcallable',
48
- 'getattrs', 'hasattrs', 'setattrs', 'try_attrs', 'DepProp', 'GetAttrBase', 'GetAttr', 'delegate_attr',
49
- 'ShowPrint', 'Int', 'Str', 'Float', 'partition', 'partition_dict', 'flatten', 'concat', 'strcat',
50
- 'detuplify', 'replicate', 'setify', 'merge', 'range_of', 'groupby', 'last_index', 'filter_dict',
51
- 'filter_keys', 'filter_values', 'cycle', 'zip_cycle', 'sorted_ex', 'not_', 'argwhere', 'filter_ex',
52
- 'renumerate', 'first', 'last', 'only', 'nested_attr', 'nested_setdefault', 'nested_callable', 'nested_idx',
53
- 'set_nested_idx', 'val2idx', 'uniqueify', 'loop_first_last', 'loop_first', 'loop_last', 'first_match',
54
- 'last_match', 'joins', 'fastuple', 'bind', 'mapt', 'map_ex', 'compose', 'maps', 'partialler', 'instantiate',
55
- 'using_attr', 'negate', 'fail_clean', 'dstar', 'copy_func', 'patch_to', 'patch', 'extend_enum', 'compile_re',
56
- 'ImportEnum', 'StrEnum', 'str_enum', 'ValEnum', 'Stateful', 'NotStr', 'PrettyString', 'even_mults',
57
- 'num_cpus', 'add_props', 'str2bool', 'str2int', 'str2float', 'str2list', 'str2date', 'str2dt', 'to_bool',
58
- 'to_int', 'to_float', 'to_list', 'to_date', 'typed', 'exec_new', 'exec_import', 'kindsort',
59
- 'sig_with_params', 'fdelegates', 'xdumps', 'revive_dates', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub',
60
- 'mul', 'truediv', 'is_', 'is_not', 'mod']
47
+ 'properties', 'id_words', 'to_camel', 'to_pascal', 'to_kebab', 'to_snake', 'camel2words', 'camel2snake',
48
+ 'snake2camel', 'humanize', 'class2attr', 'getcallable', 'getattrs', 'hasattrs', 'setattrs', 'try_attrs',
49
+ 'DepProp', 'GetAttrBase', 'GetAttr', 'delegate_attr', 'ShowPrint', 'Int', 'Str', 'Float', 'partition',
50
+ 'partition_dict', 'flatten', 'concat', 'strcat', 'detuplify', 'replicate', 'setify', 'merge', 'range_of',
51
+ 'groupby', 'last_index', 'filter_dict', 'filter_keys', 'filter_values', 'cycle', 'zip_cycle', 'sorted_ex',
52
+ 'not_', 'argwhere', 'filter_ex', 'renumerate', 'first', 'last', 'only', 'nested_attr', 'nested_setdefault',
53
+ 'nested_callable', 'nested_idx', 'set_nested_idx', 'val2idx', 'uniqueify', 'loop_first_last', 'loop_first',
54
+ 'loop_last', 'first_match', 'last_match', 'joins', 'fastuple', 'bind', 'mapt', 'map_ex', 'compose', 'maps',
55
+ 'partialler', 'instantiate', 'using_attr', 'negate', 'fail_clean', 'dstar', 'copy_func', 'patch_to', 'patch',
56
+ 'extend_enum', 'compile_re', 'ImportEnum', 'StrEnum', 'str_enum', 'ValEnum', 'Stateful', 'NotStr',
57
+ 'PrettyString', 'even_mults', 'num_cpus', 'add_props', 'str2bool', 'str2int', 'str2float', 'str2list',
58
+ 'str2date', 'str2dt', 'to_bool', 'to_int', 'to_float', 'to_list', 'to_date', 'typed', 'exec_new',
59
+ 'exec_import', 'kindsort', 'sig_with_params', 'fdelegates', 'xdumps', 'revive_dates', 'lt', 'gt', 'le', 'ge',
60
+ 'eq', 'ne', 'add', 'sub', 'mul', 'truediv', 'is_', 'is_not', 'mod']
61
61
 
62
62
  # %% ../nbs/01_basics.ipynb #0e91ed82
63
63
  from .imports import *
@@ -516,26 +516,46 @@ def properties(cls, *ps):
516
516
  "Change attrs in `cls` with names in `ps` to properties"
517
517
  for p in ps: setattr(cls,p,property(getattr(cls,p)))
518
518
 
519
- # %% ../nbs/01_basics.ipynb #d02e464d
520
- _c2w_re = re.compile(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))')
521
- _camel_re1 = re.compile('(.)([A-Z][a-z]+)')
522
- _camel_re2 = re.compile('([a-z0-9])([A-Z])')
519
+ # %% ../nbs/01_basics.ipynb #ff5313ae
520
+ def id_words(s:str, splits:str='-_ :c')->list:
521
+ "Split identifier `s` into words: punctuation chars in `splits` are separators (runs kept as empty words, so they survive a round trip), 'c' splits case boundaries"
522
+ seps = ''.join(c for c in splits if not c.isalnum())
523
+ parts = re.split(f'[{re.escape(seps)}]', s) if seps else [s]
524
+ if 'c' in splits: parts = [w for p in parts for w in re.split(r'(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])', p)]
525
+ return parts
526
+
527
+ # %% ../nbs/01_basics.ipynb #8918dc5c
528
+ def to_camel(s:str, splits:str='-_ :c')->str:
529
+ "camelCase form of `s`; acronym words after the first keep their casing"
530
+ ws = id_words(s, splits)
531
+ return ws[0].lower() + ''.join(w if w.isupper() else w.title() for w in ws[1:]) if ws else s
532
+
533
+ def to_pascal(s:str, splits:str='-_ :c')->str:
534
+ "PascalCase form of `s`; every word Title-cased (acronyms flatten)"
535
+ return ''.join(w.title() for w in id_words(s, splits))
536
+
537
+ def to_kebab(s:str, splits:str='-_ :c')->str:
538
+ "kebab-case form of `s`"
539
+ return '-'.join(w.lower() for w in id_words(s, splits))
540
+
541
+ def to_snake(s:str, splits:str='-_ :c')->str:
542
+ "snake_case form of `s`"
543
+ return '_'.join(w.lower() for w in id_words(s, splits))
523
544
 
524
545
  # %% ../nbs/01_basics.ipynb #dd737e81
525
546
  def camel2words(s, space=' '):
526
547
  "Convert CamelCase to 'spaced words'"
527
- return _c2w_re.sub(rf'{space}\1', s)
548
+ return space.join(id_words(s, 'c'))
528
549
 
529
550
  # %% ../nbs/01_basics.ipynb #a588a317
530
551
  def camel2snake(name):
531
552
  "Convert CamelCase to snake_case"
532
- s1 = _camel_re1.sub(r'\1_\2', name)
533
- return _camel_re2.sub(r'\1_\2', s1).lower()
553
+ return to_snake(name, 'c')
534
554
 
535
555
  # %% ../nbs/01_basics.ipynb #bbd632b4
536
556
  def snake2camel(s):
537
557
  "Convert snake_case to CamelCase"
538
- return ''.join(s.title().split('_'))
558
+ return to_pascal(s, '_')
539
559
 
540
560
  # %% ../nbs/01_basics.ipynb #9f4a540a
541
561
  def humanize(x):
@@ -29,11 +29,11 @@ __all__ = ['UNSET', 'spark_chars', 'walk_join', 'walk', 'exttypes', 'globtastic'
29
29
  'ReindexCollection', 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', 'strloader', 'frontmatter',
30
30
  'clean_cli_output', 'unqid', 'rtoken_hex', 'friendly_name', 'n_friendly_names', 'exec_eval',
31
31
  'get_source_link', 'sparkline', 'modify_exception', 'round_multiple', 'set_num_threads', 'join_path_file',
32
- 'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format', 'truncstr', 'fenced',
33
- 'fenced_blocks', 'str_diff', 'utc2local', 'local2utc', 'trace', 'modified_env', 'ContextManagers',
34
- 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'nullable_dc', 'make_nullable',
35
- 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter', 'flexicache',
36
- 'time_policy', 'mtime_policy', 'timed_cache']
32
+ 'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format', 'truncstr', 'trunc_ctr',
33
+ 'TruncatedString', 'fenced', 'fenced_blocks', 'str_diff', 'utc2local', 'local2utc', 'trace', 'modified_env',
34
+ 'ContextManagers', 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'nullable_dc',
35
+ 'make_nullable', 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter',
36
+ 'flexicache', 'time_policy', 'mtime_policy', 'timed_cache']
37
37
 
38
38
  # %% ../nbs/03_xtras.ipynb #3401d507
39
39
  from .imports import *
@@ -983,6 +983,22 @@ def truncstr(s:str, maxlen:int, suf:str='…', space='', sizevar:str=None)->str:
983
983
  if sizevar: suf = suf.format_map({sizevar: len(s)})
984
984
  return s[:maxlen-len(suf)]+suf if len(s)+len(space)>maxlen else s+space
985
985
 
986
+ # %% ../nbs/03_xtras.ipynb #a67b3fca
987
+ def trunc_ctr(s:str, mx:int=1000)->str:
988
+ "Truncate the middle of `s` so ~`mx` chars remain, marking the elision with its `humanize`d size"
989
+ if mx is None or len(s)<=mx: return s
990
+ h = mx//2
991
+ return f'{s[:h]}…[{humanize(len(s)-mx)} chars]…{s[len(s)-(mx-h):]}'
992
+
993
+ # %% ../nbs/03_xtras.ipynb #8d120ca6
994
+ class TruncatedString(str):
995
+ "A `str` whose repr shows contents verbatim, middle-truncated to ~`mx` chars"
996
+ def __new__(cls, s='', mx:int=1000):
997
+ res = super().__new__(cls, s)
998
+ res.mx = mx
999
+ return res
1000
+ def __repr__(self): return trunc_ctr(self, self.mx)
1001
+
986
1002
  # %% ../nbs/03_xtras.ipynb #2f5e6b12
987
1003
  def fenced(text:str, info:str='', ch:str='`')->str:
988
1004
  "Wrap `text` in a fence of `ch`, one char longer than any run of `ch` inside it (min 3)"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.7
3
+ Version: 2.2.9
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License: Apache-2.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes