Skip to content

Commit

Permalink
CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Sep 6, 2020
1 parent a3d4bbb commit 46fa345
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
token
docs/
conda/
.last_checked
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion fastcore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.0.2"
2 changes: 2 additions & 0 deletions fastcore/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions fastcore/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions fastcore/imports.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

18 changes: 14 additions & 4 deletions fastcore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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]
Expand Down
26 changes: 25 additions & 1 deletion nbs/02_utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand Down Expand Up @@ -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": {},
Expand Down
36 changes: 29 additions & 7 deletions nbs/03_dispatch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -828,7 +829,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"TypeDispatch.__call__\" class=\"doc_header\"><code>TypeDispatch.__call__</code><a href=\"__main__.py#L32\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"TypeDispatch.__call__\" class=\"doc_header\"><code>TypeDispatch.__call__</code><a href=\"__main__.py#L33\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>TypeDispatch.__call__</code>(**\\*`args`**, **\\*\\*`kwargs`**)\n",
"\n",
Expand Down Expand Up @@ -916,7 +917,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"TypeDispatch.returns\" class=\"doc_header\"><code>TypeDispatch.returns</code><a href=\"__main__.py#L20\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"TypeDispatch.returns\" class=\"doc_header\"><code>TypeDispatch.returns</code><a href=\"__main__.py#L21\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>TypeDispatch.returns</code>(**`x`**)\n",
"\n",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
"<class 'UserWarning'>: 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": {},
Expand Down
3 changes: 2 additions & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,4 +24,5 @@ title = fastcore
doc_host = https://fastcore.fast.ai
doc_baseurl = /
host = github
doc_src_path = docs_src

12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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',
Expand Down

0 comments on commit 46fa345

Please sign in to comment.