Skip to content

Commit baa1d6e

Browse files
authored
Merge pull request #63 from mfisher87/modernize
Modernize packaging config
2 parents 65b657f + 019945d commit baa1d6e

File tree

10 files changed

+198
-151
lines changed

10 files changed

+198
-151
lines changed

README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ resulting visualizations and use the editor tool `on this website
1414
<https://bids.github.io/colormap/>`_.
1515

1616
Downloads:
17-
https://pypi.python.org/pypi/viscm/
17+
* https://pypi.python.org/pypi/viscm/
18+
* https://anaconda.org/conda-forge/viscm/
1819

1920
Code and bug tracker:
2021
https://github.com/matplotlib/viscm
@@ -23,10 +24,10 @@ Contact:
2324
Nathaniel J. Smith <njs@pobox.com> and Stéfan van der Walt <stefanv@berkeley.edu>
2425

2526
Dependencies:
26-
* Python 2.6+, or 3.3+
27+
* Python 3.7+
2728
* `colorspacious <https://pypi.python.org/pypi/colorspacious>`_
2829
* Matplotlib
2930
* NumPy
3031

3132
License:
32-
MIT, see LICENSE.txt for details.
33+
MIT, see `LICENSE <LICENSE>`__ for details.

doc/contributing.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing
2+
3+
Install development dependencies:
4+
5+
```
6+
conda env create # or `mamba env create`
7+
```
8+
9+
10+
## Development install
11+
12+
```
13+
pip install -e .
14+
```
15+
16+
17+
## Testing the build
18+
19+
```
20+
rm -rf dist
21+
python -m build
22+
pip install dist/*.whl # or `dist/*.tar.gz`
23+
```

environment.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "viscm"
2+
channels:
3+
- "conda-forge"
4+
- "nodefaults"
5+
dependencies:
6+
- "python ~=3.11"
7+
- "numpy ~=1.24"
8+
- "matplotlib ~=3.7"
9+
- "colorspacious ~=1.1"
10+
- "scipy ~=1.10"
11+
- pip:
12+
- "build ~=0.10"

pyproject.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[project]
2+
name = "viscm"
3+
dynamic = ["version"]
4+
description = "A colormap tool"
5+
readme = "README.rst"
6+
authors = [
7+
{name = "Nathaniel J. Smith", email = "njs@pobox.com"},
8+
{name = "Stefan van der Walt", email = "stefanv@berkeley.edu"},
9+
]
10+
classifiers = [
11+
"Development Status :: 3 - Alpha",
12+
"Intended Audience :: Developers",
13+
"Intended Audience :: Science/Research",
14+
"License :: OSI Approved :: MIT License",
15+
"Programming Language :: Python :: 3",
16+
]
17+
18+
requires-python = "~=3.7"
19+
dependencies = [
20+
"numpy",
21+
"matplotlib",
22+
"colorspacious",
23+
"scipy",
24+
]
25+
26+
[project.urls]
27+
repository = "https://github.com/matplotlib/viscm"
28+
# documentation = "https://viscm.readthedocs.io"
29+
30+
[project.license]
31+
text = "MIT"
32+
files = ["LICENSE"]
33+
34+
[project.scripts]
35+
viscm = "viscm.cli:cli"
36+
37+
38+
[build-system]
39+
requires = ["setuptools", "setuptools_scm"]
40+
build-backend = "setuptools.build_meta"
41+
42+
[tool.setuptools]
43+
zip-safe = false
44+
packages = {find = {}}
45+
package-data = {viscm = ["examples/*"]}
46+
47+
48+
# [tool.black]

setup.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
from setuptools import setup, find_packages
2-
import sys
3-
import os.path
1+
from setuptools import setup
42

5-
import numpy as np
6-
7-
# Must be one line or PyPI will cut it off
8-
DESC = ("A colormap tool")
9-
10-
LONG_DESC = open("README.rst").read()
11-
12-
setup(
13-
name="viscm",
14-
version="0.9",
15-
description=DESC,
16-
long_description=LONG_DESC,
17-
author="Nathaniel J. Smith, Stefan van der Walt",
18-
author_email="njs@pobox.com, stefanv@berkeley.edu",
19-
url="https://github.com/bids/viscm",
20-
license="MIT",
21-
classifiers =
22-
[ "Development Status :: 3 - Alpha",
23-
"Intended Audience :: Developers",
24-
"Intended Audience :: Science/Research",
25-
"License :: OSI Approved :: MIT License",
26-
"Programming Language :: Python :: 2",
27-
"Programming Language :: Python :: 3",
28-
],
29-
packages=find_packages(),
30-
install_requires=["numpy", "matplotlib", "colorspacious", "scipy"],
31-
package_data={'viscm': ['examples/*']},
32-
)
3+
setup(use_scm_version=True)

viscm/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# This file is part of pycam02ucs
21
# Copyright (C) 2014 Nathaniel Smith <njs@pobox.com>
32
# See file LICENSE.txt for license information.
43

viscm/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
# Copyright (C) 2015 Stefan van der Walt <stefanv@berkeley.edu>
44
# See file LICENSE.txt for license information.
55

6-
import sys
7-
from .gui import main
8-
main(sys.argv[1:])
6+
from .cli import cli
7+
cli()

viscm/cli.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import sys
2+
3+
import matplotlib.pyplot as plt
4+
5+
from viscm import gui
6+
7+
8+
def cli():
9+
import argparse
10+
argv = sys.argv[1:]
11+
12+
parser = argparse.ArgumentParser(
13+
prog="python -m viscm",
14+
description="A colormap tool.",
15+
)
16+
parser.add_argument("action", metavar="ACTION",
17+
help="'edit' or 'view' (or 'show', same as 'view')",
18+
choices=["edit", "view", "show"],
19+
default="edit",
20+
nargs="?")
21+
parser.add_argument("colormap", metavar="COLORMAP",
22+
default=None,
23+
help="A .json file saved from the editor, a .py file containing"
24+
" a global named `test_cm`, or the name of a matplotlib"
25+
" builtin colormap",
26+
nargs="?")
27+
parser.add_argument("--uniform-space", metavar="SPACE",
28+
default="CAM02-UCS",
29+
dest="uniform_space",
30+
help="The perceptually uniform space to use. Usually "
31+
"you should leave this alone. You can pass 'CIELab' "
32+
"if you're curious how uniform some colormap is in "
33+
"CIELab space. You can pass 'buggy-CAM02-UCS' if "
34+
"you're trying to reproduce the matplotlib colormaps "
35+
"(which turn out to have had a small bug in the "
36+
"assumed sRGB viewing conditions) from their bezier "
37+
"curves.")
38+
parser.add_argument("-t", "--type", type=str,
39+
default="linear", choices=["linear", "diverging", "diverging-continuous"],
40+
help="Choose a colormap type. Supported options are 'linear', 'diverging', and 'diverging-continuous")
41+
parser.add_argument("-m", "--method", type=str,
42+
default="CatmulClark", choices=["Bezier", "CatmulClark"],
43+
help="Choose a spline construction method. 'CatmulClark' is the default, but you may choose the legacy option 'Bezier'")
44+
parser.add_argument("--save", metavar="FILE",
45+
default=None,
46+
help="Immediately save visualization to a file "
47+
"(view-mode only).")
48+
parser.add_argument("--quit", default=False, action="store_true",
49+
help="Quit immediately after starting "
50+
"(useful with --save).")
51+
args = parser.parse_args(argv)
52+
53+
cm = gui.Colormap(args.type, args.method, args.uniform_space)
54+
app = gui.QtWidgets.QApplication([])
55+
56+
if args.colormap:
57+
cm.load(args.colormap)
58+
59+
60+
# Easter egg! I keep typing 'show' instead of 'view' so accept both
61+
if args.action in ("view", "show"):
62+
if cm is None:
63+
sys.exit("Please specify a colormap")
64+
fig = plt.figure()
65+
figureCanvas = gui.FigureCanvas(fig)
66+
v = gui.viscm(cm.cmap, name=cm.name, figure=fig, uniform_space=cm.uniform_space)
67+
mainwindow = gui.ViewerWindow(figureCanvas, v, cm.name)
68+
if args.save is not None:
69+
v.figure.set_size_inches(20, 12)
70+
v.figure.savefig(args.save)
71+
elif args.action == "edit":
72+
if not cm.can_edit:
73+
sys.exit("Sorry, I don't know how to edit the specified colormap")
74+
# Hold a reference so it doesn't get GC'ed
75+
fig = plt.figure()
76+
figureCanvas = gui.FigureCanvas(fig)
77+
v = gui.viscm_editor(figure=fig, uniform_space=cm.uniform_space, cmtype=cm.cmtype, method=cm.method, **cm.params)
78+
mainwindow = gui.EditorWindow(figureCanvas, v)
79+
else:
80+
raise RuntimeError("can't happen")
81+
82+
if args.quit:
83+
sys.exit()
84+
85+
figureCanvas.setSizePolicy(gui.QtWidgets.QSizePolicy.Expanding,
86+
gui.QtWidgets.QSizePolicy.Expanding)
87+
figureCanvas.updateGeometry()
88+
89+
mainwindow.resize(800, 600)
90+
mainwindow.show()
91+
92+
# PyQt messes up signal handling by default. Python signal handlers (e.g.,
93+
# the default handler for SIGINT that raises KeyboardInterrupt) can only
94+
# run when we enter the Python interpreter, which doesn't happen while
95+
# idling in the Qt mainloop. (Unless we register a timer to poll
96+
# explicitly.) So here we unregister Python's default signal handler and
97+
# replace it with... the *operating system's* default signal handler, so
98+
# instead of a KeyboardInterrupt our process just exits.
99+
import signal
100+
signal.signal(signal.SIGINT, signal.SIG_DFL)
101+
102+
app.exec_()
103+
104+
105+
if __name__ == "__main__":
106+
cli()

viscm/gui.py

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -948,116 +948,13 @@ def load(self, path):
948948
self.name = path
949949

950950

951-
def main(argv):
952-
import argparse
953-
954-
# Usage:
955-
# python -m viscm
956-
# python -m viscm edit
957-
# python -m viscm edit <file.py>
958-
# (file.py must define some appropriate globals)
959-
# python -m viscm view <file.py>
960-
# (file.py must define a global named "test_cm")
961-
# python -m viscm view "matplotlib builtin colormap"
962-
# python -m viscm view --save=foo.png ...
963-
964-
parser = argparse.ArgumentParser(
965-
prog="python -m viscm",
966-
description="A colormap tool.",
967-
)
968-
parser.add_argument("action", metavar="ACTION",
969-
help="'edit' or 'view' (or 'show', same as 'view')",
970-
choices=["edit", "view", "show"],
971-
default="edit",
972-
nargs="?")
973-
parser.add_argument("colormap", metavar="COLORMAP",
974-
default=None,
975-
help="A .json file saved from the editor, or "
976-
"the name of a matplotlib builtin colormap",
977-
nargs="?")
978-
parser.add_argument("--uniform-space", metavar="SPACE",
979-
default="CAM02-UCS",
980-
dest="uniform_space",
981-
help="The perceptually uniform space to use. Usually "
982-
"you should leave this alone. You can pass 'CIELab' "
983-
"if you're curious how uniform some colormap is in "
984-
"CIELab space. You can pass 'buggy-CAM02-UCS' if "
985-
"you're trying to reproduce the matplotlib colormaps "
986-
"(which turn out to have had a small bug in the "
987-
"assumed sRGB viewing conditions) from their bezier "
988-
"curves.")
989-
parser.add_argument("-t", "--type", type=str,
990-
default="linear", choices=["linear", "diverging", "diverging-continuous"],
991-
help="Choose a colormap type. Supported options are 'linear', 'diverging', and 'diverging-continuous")
992-
parser.add_argument("-m", "--method", type=str,
993-
default="CatmulClark", choices=["Bezier", "CatmulClark"],
994-
help="Choose a spline construction method. 'CatmulClark' is the default, but you may choose the legacy option 'Bezier'")
995-
parser.add_argument("--save", metavar="FILE",
996-
default=None,
997-
help="Immediately save visualization to a file "
998-
"(view-mode only).")
999-
parser.add_argument("--quit", default=False, action="store_true",
1000-
help="Quit immediately after starting "
1001-
"(useful with --save).")
1002-
args = parser.parse_args(argv)
1003-
1004-
cm = Colormap(args.type, args.method, args.uniform_space)
1005-
app = QtWidgets.QApplication([])
1006-
1007-
if args.colormap:
1008-
cm.load(args.colormap)
1009-
1010-
1011-
# Easter egg! I keep typing 'show' instead of 'view' so accept both
1012-
if args.action in ("view", "show"):
1013-
if cm is None:
1014-
sys.exit("Please specify a colormap")
1015-
fig = plt.figure()
1016-
figureCanvas = FigureCanvas(fig)
1017-
v = viscm(cm.cmap, name=cm.name, figure=fig, uniform_space=cm.uniform_space)
1018-
mainwindow = ViewerWindow(figureCanvas, v, cm.name)
1019-
if args.save is not None:
1020-
v.figure.set_size_inches(20, 12)
1021-
v.figure.savefig(args.save)
1022-
elif args.action == "edit":
1023-
if not cm.can_edit:
1024-
sys.exit("Sorry, I don't know how to edit the specified colormap")
1025-
# Hold a reference so it doesn't get GC'ed
1026-
fig = plt.figure()
1027-
figureCanvas = FigureCanvas(fig)
1028-
v = viscm_editor(figure=fig, uniform_space=cm.uniform_space, cmtype=cm.cmtype, method=cm.method, **cm.params)
1029-
mainwindow = EditorWindow(figureCanvas, v)
1030-
else:
1031-
raise RuntimeError("can't happen")
1032-
1033-
if args.quit:
1034-
sys.exit()
1035-
1036-
figureCanvas.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
1037-
QtWidgets.QSizePolicy.Expanding)
1038-
figureCanvas.updateGeometry()
1039-
1040-
mainwindow.resize(800, 600)
1041-
mainwindow.show()
1042-
1043-
# PyQt messes up signal handling by default. Python signal handlers (e.g.,
1044-
# the default handler for SIGINT that raises KeyboardInterrupt) can only
1045-
# run when we enter the Python interpreter, which doesn't happen while
1046-
# idling in the Qt mainloop. (Unless we register a timer to poll
1047-
# explicitly.) So here we unregister Python's default signal handler and
1048-
# replace it with... the *operating system's* default signal handler, so
1049-
# instead of a KeyboardInterrupt our process just exits.
1050-
import signal
1051-
signal.signal(signal.SIGINT, signal.SIG_DFL)
1052-
1053-
app.exec_()
1054-
1055951
def about():
1056952
QtWidgets.QMessageBox.about(None, "VISCM",
1057953
"Copyright (C) 2015-2016 Nathaniel Smith\n" +
1058954
"Copyright (C) 2015-2016 Stéfan van der Walt\n"
1059955
"Copyright (C) 2016 Hankun Zhao")
1060956

957+
1061958
class ViewerWindow(QtWidgets.QMainWindow):
1062959
def __init__(self, figurecanvas, viscm, cmapname, parent=None):
1063960
QtWidgets.QMainWindow.__init__(self, parent)
@@ -1328,7 +1225,3 @@ def loadviewer(self):
13281225
newwindow.resize(800, 600)
13291226

13301227
newwindow.show()
1331-
1332-
1333-
if __name__ == "__main__":
1334-
main(sys.argv[1:])

0 commit comments

Comments
 (0)