From 46fa3450f70d41f9cb320eaf02b9fdce3026b314 Mon Sep 17 00:00:00 2001 From: Jeremy Howard Date: Sun, 6 Sep 2020 09:13:56 -0700 Subject: [PATCH] CHANGELOG --- .gitignore | 1 + Makefile | 2 ++ fastcore/__init__.py | 2 +- fastcore/_nbdev.py | 2 ++ fastcore/dispatch.py | 1 + fastcore/imports.py | 4 ++++ fastcore/utils.py | 18 ++++++++++++++---- nbs/02_utils.ipynb | 26 +++++++++++++++++++++++++- nbs/03_dispatch.ipynb | 36 +++++++++++++++++++++++++++++------- settings.ini | 3 ++- setup.py | 12 ++++++++---- 11 files changed, 89 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 32e85d53..2662ed5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +token docs/ conda/ .last_checked diff --git a/Makefile b/Makefile index 893c182a..358cf5a6 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ test: nbdev_test_nbs release: pypi + git tag "$(python setup.py version)" + git push --tags nbdev_conda_package --upload_user fastai --build_args '-c pytorch -c fastai' nbdev_bump_version diff --git a/fastcore/__init__.py b/fastcore/__init__.py index 5c4105cd..7863915f 100644 --- a/fastcore/__init__.py +++ b/fastcore/__init__.py @@ -1 +1 @@ -__version__ = "1.0.1" +__version__ = "1.0.2" diff --git a/fastcore/_nbdev.py b/fastcore/_nbdev.py index 01180ef6..94b17258 100644 --- a/fastcore/_nbdev.py +++ b/fastcore/_nbdev.py @@ -114,6 +114,8 @@ "remove_patches_path": "02_utils.ipynb", "bunzip": "02_utils.ipynb", "join_path_file": "02_utils.ipynb", + "urlread": "02_utils.ipynb", + "urljson": "02_utils.ipynb", "sort_by_run": "02_utils.ipynb", "PrettyString": "02_utils.ipynb", "round_multiple": "02_utils.ipynb", diff --git a/fastcore/dispatch.py b/fastcore/dispatch.py index 98601606..4592d016 100644 --- a/fastcore/dispatch.py +++ b/fastcore/dispatch.py @@ -72,6 +72,7 @@ def __init__(self, funcs=(), bases=()): def add(self, f): "Add type `t` and function `f`" + if f and getattr(f,'__defaults__',None): warn(f"{f.__name__} has default params. These will be ignored.") a0,a1 = _p2_anno(f) t = self.funcs.d.get(a0) if t is None: diff --git a/fastcore/imports.py b/fastcore/imports.py index a7108e87..2032b284 100644 --- a/fastcore/imports.py +++ b/fastcore/imports.py @@ -1,7 +1,9 @@ import numpy as np import io,operator,sys,os,re,mimetypes,itertools,shutil,pickle,tempfile,subprocess import itertools,random,inspect,functools,math,bz2,typing,numbers,warnings,threading +import json,urllib.request +from warnings import warn from dataclasses import dataclass from functools import partial,reduce from threading import Thread @@ -14,6 +16,7 @@ from collections import defaultdict,Counter from operator import itemgetter,attrgetter from uuid import uuid4 +from urllib.request import HTTPError # External modules from numpy import array,ndarray @@ -70,3 +73,4 @@ def equals(a,b): all_equal if is_iter(a) or is_iter(b) else operator.eq) return cmp(a,b) + diff --git a/fastcore/utils.py b/fastcore/utils.py index 49ed5311..2da24529 100644 --- a/fastcore/utils.py +++ b/fastcore/utils.py @@ -7,10 +7,10 @@ 'rnum_methods', 'inum_methods', 'fastuple', 'Inf', 'in_', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub', 'mul', 'truediv', 'is_', 'is_not', 'in_', 'true', 'stop', 'gen', 'chunked', 'trace', 'compose', 'maps', 'partialler', 'mapped', 'instantiate', 'using_attr', 'log_args', 'Self', 'Self', 'remove_patches_path', - 'bunzip', 'join_path_file', 'sort_by_run', 'PrettyString', 'round_multiple', 'even_mults', 'num_cpus', - 'add_props', 'ContextManagers', 'set_num_threads', 'ProcessPoolExecutor', 'parallel', 'parallel_chunks', - 'run_procs', 'parallel_gen', 'ipython_shell', 'in_ipython', 'in_colab', 'in_jupyter', 'in_notebook', - 'IN_NOTEBOOK', 'IN_JUPYTER', 'IN_COLAB', 'IN_IPYTHON'] + 'bunzip', 'join_path_file', 'urlread', 'urljson', 'sort_by_run', 'PrettyString', 'round_multiple', + 'even_mults', 'num_cpus', 'add_props', 'ContextManagers', 'set_num_threads', 'ProcessPoolExecutor', + 'parallel', 'parallel_chunks', 'run_procs', 'parallel_gen', 'ipython_shell', 'in_ipython', 'in_colab', + 'in_jupyter', 'in_notebook', 'IN_NOTEBOOK', 'IN_JUPYTER', 'IN_COLAB', 'IN_IPYTHON'] # Cell from .imports import * @@ -594,6 +594,16 @@ def join_path_file(file, path, ext=''): path.mkdir(parents=True, exist_ok=True) return path/f'{file}{ext}' +# Cell +def urlread(url): + "Retrieve `url`" + return urllib.request.urlopen(url).read() + +# Cell +def urljson(url): + "Retrieve `url` and decode json" + return json.loads(urlread(url)) + # Cell def _is_instance(f, gs): tst = [g if type(g) in [type, 'function'] else g.__class__ for g in gs] diff --git a/nbs/02_utils.ipynb b/nbs/02_utils.ipynb index fb911623..1758a387 100644 --- a/nbs/02_utils.ipynb +++ b/nbs/02_utils.ipynb @@ -3100,7 +3100,7 @@ "source": [ "## File Functions\n", "\n", - "Utilities (other than extensions to Pathlib.Path) for dealing with files." + "Utilities (other than extensions to Pathlib.Path) for dealing with IO." ] }, { @@ -3163,6 +3163,30 @@ "shutil.rmtree(Path.cwd()/'_tmp')" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#export\n", + "def urlread(url):\n", + " \"Retrieve `url`\"\n", + " return urllib.request.urlopen(url).read()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#export\n", + "def urljson(url):\n", + " \"Retrieve `url` and decode json\"\n", + " return json.loads(urlread(url))" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/nbs/03_dispatch.ipynb b/nbs/03_dispatch.ipynb index ca079ec3..2f1bf26c 100644 --- a/nbs/03_dispatch.ipynb +++ b/nbs/03_dispatch.ipynb @@ -336,6 +336,7 @@ "\n", " def add(self, f):\n", " \"Add type `t` and function `f`\"\n", + " if f and getattr(f,'__defaults__',None): warn(f\"{f.__name__} has default params. These will be ignored.\")\n", " a0,a1 = _p2_anno(f)\n", " t = self.funcs.d.get(a0)\n", " if t is None:\n", @@ -828,7 +829,7 @@ { "data": { "text/markdown": [ - "

TypeDispatch.__call__[source]

\n", + "

TypeDispatch.__call__[source]

\n", "\n", "> TypeDispatch.__call__(**\\*`args`**, **\\*\\*`kwargs`**)\n", "\n", @@ -916,7 +917,7 @@ { "data": { "text/markdown": [ - "

TypeDispatch.returns[source]

\n", + "

TypeDispatch.returns[source]

\n", "\n", "> TypeDispatch.returns(**`x`**)\n", "\n", @@ -979,14 +980,14 @@ "source": [ "def m_nin(self, x:(str,numbers.Integral)): return str(x)+'1'\n", "def m_bll(self, x:bool): self.foo='a'\n", - "def m_num(self, x:numbers.Number): return x\n", + "def m_num(self, x:numbers.Number): return x*2\n", "\n", "t = TypeDispatch([m_nin,m_num,m_bll])\n", "class A: f = t # set class attribute `f` equal to a TypeDispatch instance\n", " \n", "a = A()\n", "test_eq(a.f(1), '11') #dispatch to m_nin\n", - "test_eq(a.f(1.), 1.) #dispatch to m_num\n", + "test_eq(a.f(1.), 2.) #dispatch to m_num\n", "test_is(a.f.inst, a)\n", "\n", "a.f(False) # this triggers t.m_bll to run, which sets self.foo to 'a'\n", @@ -1028,7 +1029,7 @@ "class A2: f = t2\n", "a2 = A2()\n", "test_eq(a2.f(1), '11')\n", - "test_eq(a2.f(1.), 1.)\n", + "test_eq(a2.f(1.), 2.)\n", "test_is(a2.f.inst, a2)\n", "a2.f(False)\n", "test_eq(a2.foo, 'a')\n", @@ -1072,15 +1073,36 @@ "def f_td_test(x:numbers.Integral, y): return x+1\n", "@typedispatch\n", "def f_td_test(x:int, y:float): return x+y\n", + "@typedispatch\n", + "def f_td_test(x:int, y:int): return x*y\n", "\n", "test_eq(f_td_test(3,2.0), 5)\n", - "\n", "assert issubclass(int, numbers.Integral)\n", - "test_eq(f_td_test(3,2), 4)\n", + "test_eq(f_td_test(3,2), 6)\n", "\n", "test_eq(f_td_test('a','b'), 'ab')" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ": f_td_test has default params. These will be ignored.\n" + ] + } + ], + "source": [ + "def outer():\n", + " @typedispatch\n", + " def f_td_test(x:int,y:int=10): return x*y\n", + "test_warns(outer,True)" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/settings.ini b/settings.ini index 27fe3d47..3e7585d0 100644 --- a/settings.ini +++ b/settings.ini @@ -7,7 +7,7 @@ author = Jeremy Howard and Sylvain Gugger author_email = infos@fast.ai copyright = fast.ai branch = master -version = 1.0.1 +version = 1.0.2 min_python = 3.6 audience = Developers language = English @@ -24,4 +24,5 @@ title = fastcore doc_host = https://fastcore.fast.ai doc_baseurl = / host = github +doc_src_path = docs_src diff --git a/setup.py b/setup.py index a24dbef3..1dd6b865 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ +import setuptools,sys from pkg_resources import parse_version from configparser import ConfigParser -import setuptools +from distutils.cmd import Command + assert parse_version(setuptools.__version__)>=parse_version('36.2') # note: all settings are in settings.ini; edit there, not here @@ -28,6 +30,10 @@ lic = licenses[cfg['license']] min_python = cfg['min_python'] +if len(sys.argv)>1 and sys.argv[1]=='version': + print(setup_cfg['version']) + exit() + setuptools.setup( name = cfg['lib_name'], license = lic[0], @@ -41,9 +47,7 @@ packages = setuptools.find_packages(), include_package_data = True, install_requires = requirements, - extras_require = { - 'dev': dev_requirements - }, + extras_require = { 'dev': dev_requirements }, python_requires = '>=' + cfg['min_python'], long_description = open('README.md').read(), long_description_content_type = 'text/markdown',