Skip to content

Commit 35c7644

Browse files
Animation and ColorRamp fixes (#32)
* new test for animation -- not complete yet. * added color ramp tpo test .. broken. * cleaned up the examples, and added an auto-run script * cleaned up and automated the examples page. * got a multiple color animation test to work. * fixed some lint * put the checksums in a python file, added more checks for animation files cleaned up some lint * removed duplicate file name
1 parent 0a7e816 commit 35c7644

29 files changed

Lines changed: 711 additions & 361 deletions

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ exclude =
1313
conf.py
1414
build
1515
dist
16+
./build_gd.py
17+
checksums.py

.github/workflows/conda_test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run tests with miniconda
1+
name: Run tests with miniforge
22
on: [push]
33

44
jobs:
@@ -36,6 +36,11 @@ jobs:
3636
run: |
3737
pytest --pyargs py_gd
3838
39+
- name: Test Examples
40+
shell: bash -l {0}
41+
run: |
42+
python docs/examples/run_all_examples.py
43+
3944
lint:
4045
name: Flake8 linting
4146
runs-on: "ubuntu-latest"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#specific to this repo:
22

33
py_gd/py_gd.c
4-
docs/examples/Mandelbrot.png
4+
docs/examples/*.png
5+
docs/examples/*.gif
56

67

78
# mac files

build_gd.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
look in the "if __name__" clause at the bottom:
1212
you can turn on and off different libs, and different parts of the process
1313
14-
1514
"""
1615

1716
import os
@@ -24,7 +23,7 @@
2423
# use this if you want the full install of hdf and netcdf available on your system
2524
# prefix = "/usr/local"
2625

27-
print "Installing libs to:", prefix
26+
print("Installing libs to:", prefix)
2827

2928
if not os.path.exists(prefix):
3029
os.mkdir(prefix)
@@ -37,7 +36,7 @@ def download(name):
3736

3837
# see if it's already there:
3938
if os.path.isfile(name):
40-
print "%s already there -- not downloading again"%name
39+
print("%s already there -- not downloading again"%name)
4140
return
4241

4342
## note: bitbucket does not seem t o support direct download links liek this
@@ -53,18 +52,18 @@ def download(name):
5352
cmd = 'curl -L --output {0} http://sourceforge.net/projects/libpng/files/libpng16/1.6.3/libpng-1.6.3.tar.gz'.format(name)
5453
else:
5554
raise Exception("I don't know how to download: %s"%name)
56-
print "downloading:", name
57-
print cmd
55+
print("downloading:", name)
56+
print(cmd)
5857

5958
os.system(cmd)
6059

6160
def unpack(lib):
6261
if os.path.isdir(lib):
63-
print "%s already unpacked, not unpacking again"%lib
62+
print("%s already unpacked, not unpacking again"%lib)
6463
return
6564
lib = lib +'.tar.gz'
6665
cmd = "tar -xvf "+lib
67-
print "Unpacking:", cmd
66+
print("Unpacking:", cmd)
6867
os.system( cmd )
6968

7069
def configure(lib):
@@ -83,7 +82,7 @@ def configure(lib):
8382
conf = './configure ' + ' '.join(flags)
8483

8584
os.chdir(lib)
86-
print conf
85+
print(conf)
8786
os.system("make clean")
8887
if os.system(conf):
8988
os.chdir(cwd)

conda_requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ setuptools
33
cython>=3
44
pytest
55
sphinx
6-
6+
ipython # nice to have, and used to help render the docs
77

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
extensions = ['sphinx.ext.autodoc',
2929
'sphinx.ext.todo',
3030
'sphinx.ext.coverage',
31+
'IPython.sphinxext.ipython_directive'
3132
# 'sphinx.ext.pngmath',
3233
# 'sphinx.ext.mathjax',
3334
]
34-
35+
# extensions = ['IPython.sphinxext.ipython_console_highlighting',
36+
# 'IPython.sphinxext.ipython_directive']
3537
# Add any paths that contain templates here, relative to this directory.
3638
templates_path = ['_templates']
3739

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
ultra_simple_example.py
2+
Ultra Simple Example
33
44
About the simplest example for py_gd
55
@@ -12,5 +12,5 @@
1212

1313
img.draw_line((1, 1), (400, 300), color='red', line_width=10)
1414

15-
img.save('ultra_simple.png', 'png')
15+
img.save('0-ultra_simple.png', 'png')
1616

docs/examples/Mandelbrot.png

-20.8 KB
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
from pathlib import Path
3+
4+
HERE = Path(__file__).parent
5+
6+
HEADER = """.. _sample_scripts:
7+
8+
Sample Scripts
9+
==============
10+
11+
A good way to learn to use py_gd is to check out a few example scripts.
12+
13+
"""
14+
15+
all_examples = [fn for fn in HERE.glob("*.py") if not fn.name in {"build_color_images.py",
16+
"run_all_examples.py",
17+
"build_example_page.py"}
18+
]
19+
20+
def gen_example(script_path):
21+
if "draw_dots" in str(script_path.stem):
22+
img_filename = str(script_path.stem) + ".gif"
23+
else:
24+
img_filename = str(script_path.stem) + ".png"
25+
26+
docstring = []
27+
with open(script_path) as script:
28+
# find the docstring
29+
for line in script:
30+
if line.startswith('"""'):
31+
break
32+
for line in script:
33+
line = line.strip()
34+
if line.startswith('"""'):
35+
break
36+
else:
37+
docstring.append(line)
38+
section = f"""
39+
40+
{docstring[0]}\n{"-"*len(docstring[0])}
41+
{"\n".join(docstring[1:])}
42+
43+
.. image:: examples/{img_filename}
44+
:align: center
45+
"""
46+
return section
47+
48+
with open(HERE / "../sample_scripts.rst", 'w') as rst:
49+
rst.write(HEADER)
50+
for script in all_examples:
51+
rst.write(gen_example(script))
-12 Bytes
Loading

0 commit comments

Comments
 (0)