Skip to content

Commit 24c3041

Browse files
author
Björn Jürgens
committed
maybe fixes #7. removed subsubheadings (which seem to break display on anaconda.com). Addded github-style code syntax
1 parent 02a588a commit 24c3041

File tree

1 file changed

+96
-64
lines changed

1 file changed

+96
-64
lines changed

README.md

Lines changed: 96 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,72 @@ This package adds `%cache` line-magic to ipython kernels in jupyter notebooks.
1212

1313
So you can run the magic by entering this into an ipython-cell:
1414

15-
!pip install ipython-cache
16-
import cache_magic
17-
%cache a = 1+1
18-
%cache
15+
```python
16+
!pip install ipython-cache
17+
import cache_magic
18+
%cache a = 1+1
19+
%cache
20+
```
1921

20-
## installation
22+
# installation
2123

22-
### install directly from notebook
24+
## install directly from notebook
2325

2426
1. open jupyter notebook
2527
2. create new cell
2628
3. enter `!pip install cache-magic`
2729
4. execute
2830

29-
### install into conda-environment
31+
## install into conda-environment
3032

31-
conda create -n test
32-
source activate test
33-
conda install -c juergens ipython-cache
34-
jupyter notebook
33+
```bash
34+
conda create -n test
35+
source activate test
36+
conda install -c juergens ipython-cache
37+
jupyter notebook
38+
```
3539

36-
## usage
40+
# usage
3741

3842
Activate the magic by loading the module like any other module. Write into a cell `import cache_magic` and excecute it.
3943

4044
When you want to apply the magic to a line, just prepend the line with `%cache`
4145

42-
### example
46+
## example
4347

44-
%cache myVar = someSlowCalculation(some, "parameters")
48+
```python
49+
%cache myVar = someSlowCalculation(some, "parameters")
50+
```
4551

4652
This will calculate `someSlowCalculation(some, "parameters")` once. And in subsequent calls it restores myVar from storage.
4753

4854
The magic turns this example into something like this (if there was no ipython-kernel and no versioning):
4955

50-
try:
51-
with open("myVar.txt", 'rb') as fp:
52-
myVar = pickle.loads(fp.read())
53-
except:
54-
myVar = someSlowCalculation(some, "parameters")
55-
with open("myVar.txt", 'wb') as fp:
56-
pickle.dump(myVar, fp)
56+
```python
57+
try:
58+
with open("myVar.txt", 'rb') as fp:
59+
myVar = pickle.loads(fp.read())
60+
except:
61+
myVar = someSlowCalculation(some, "parameters")
62+
with open("myVar.txt", 'wb') as fp:
63+
pickle.dump(myVar, fp)
64+
```
5765

58-
### general form
66+
## general form
5967

60-
%cache <variable> = <expression>
68+
```python
69+
%cache <variable> = <expression>
70+
```
6171

6272
**Variable**: This Variable's value will be fetched from cache.
6373

6474
**Expression**: This will only be excecuted once and the result will be stored to disk.
6575

66-
### full form
76+
## full form
6777

68-
%cache [--version <version>] [--reset] [--debug] variable [= <expression>]
78+
```python
79+
%cache [--version <version>] [--reset] [--debug] variable [= <expression>]
80+
```
6981

7082
**-v or --version**: either a variable name or an integer. Whenever this changes, a new value is calculated (instead of returning an old value from the cache).
7183

@@ -75,16 +87,20 @@ if version is '\*' or omitted, the hashed expression is used as version, so when
7587

7688
**-d or --debug**: additional logging
7789

78-
### show cache
90+
## show cache
7991

80-
%cache
92+
```python
93+
%cache
94+
```
8195

8296
shows all variables in cache as html-table
8397

84-
### full reset
98+
## full reset
8599

86-
%cache -r
87-
%cache --reset
100+
```python
101+
%cache -r
102+
%cache --reset
103+
```
88104

89105
deletes all cached values for all variables
90106

@@ -99,68 +115,84 @@ In the directory where the kernel was started (usually where the notebook is loc
99115

100116
prepare environment:
101117

102-
gedit ~/.pypirc
103-
chmod 600 ~/.pypirc
104-
sudo apt install pandoc
118+
```bash
119+
gedit ~/.pypirc
120+
chmod 600 ~/.pypirc
121+
sudo apt install pandoc
122+
```
105123

106124
upload changes to test and production:
107125

108-
pandoc -o README.rst README.md
109-
restview --pypi-strict README.rst
110-
# update version in setup.py
111-
rm -r dist
112-
python setup.py sdist
113-
twine upload dist/* -r testpypi
114-
firefox https://testpypi.python.org/pypi/ipython-cache
115-
twine upload dist/*
126+
```bash
127+
pandoc -o README.rst README.md
128+
restview --pypi-strict README.rst
129+
# update version in setup.py
130+
rm -r dist
131+
python setup.py sdist
132+
twine upload dist/* -r testpypi
133+
firefox https://testpypi.python.org/pypi/ipython-cache
134+
twine upload dist/*
135+
```
116136

117137
test install from testpypi
118138

119-
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ipython_cache --no-cache-dir --user
139+
```bash
140+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ipython_cache --no-cache-dir --user
141+
```
120142

121143
test installation
122144

123-
sudo pip install ipython_cache --no-cache-dir --user
124-
145+
```bash
146+
sudo pip install ipython_cache --no-cache-dir --user
147+
```
125148

126149
## editable import
127150

128151
Install into environment with `-e`:
129152

130-
!pip install -e .
153+
```python
154+
!pip install -e .
155+
```
131156

132157
reload after each change:
133158

134-
import cache_magic
135-
from imp import reload
136-
reload(cache_magic)
159+
```bash
160+
import cache_magic
161+
from imp import reload
162+
reload(cache_magic)
163+
```
137164

138165
Alternatively (if you don't want to install python, jupyter & co), you can use the docker-compose.yml for development:
139166

140-
cd ipython-cache
141-
docker-compose up
142-
167+
```bash
168+
cd ipython-cache
169+
docker-compose up
170+
```
143171

144172
## create Conda Packet
145173

146174
requires the bash with latest anaconda on path
147175

148-
bash
149-
mkdir test && cd test
150-
conda skeleton pypi ipython-cache
151-
conda-build ipython-cache -c conda-forge
152-
anaconda upload /home/juergens/anaconda3/conda-bld/linux-64/ipython-cache-*
176+
```bash
177+
bash
178+
mkdir test && cd test
179+
conda skeleton pypi ipython-cache
180+
conda-build ipython-cache -c conda-forge
181+
anaconda upload /home/juergens/anaconda3/conda-bld/linux-64/ipython-cache-*
182+
```
153183

154184
## running tests
155185

156-
bash
157-
conda remove --name test --all
158-
conda env create -f test/environment.yml
159-
source activate test
160-
conda remove ipython-cache
161-
pip uninstall ipython_cache
162-
pip install -e .
163-
./test/run_example.py
186+
```bash
187+
bash
188+
conda remove --name test --all
189+
conda env create -f test/environment.yml
190+
source activate test
191+
conda remove ipython-cache
192+
pip uninstall ipython_cache
193+
pip install -e .
194+
./test/run_example.py
195+
```
164196

165197
If there is any error, it will be printed to stderr and the script fails.
166198

0 commit comments

Comments
 (0)