Skip to content

Commit

Permalink
Add config.asy and psviewer that removes trash
Browse files Browse the repository at this point in the history
To remove the useless eps.out file that is created by Asymptote
and to prevent an annoying gv popup, we create our own
config.asy, and arrange to have it run a program to remove
the out.eps (the programs file argument).
  • Loading branch information
rocky committed Aug 1, 2021
1 parent 4e076ff commit 6951ba7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ include ChangeLog
include COPYING.txt
include Makefile
include mathicsscript/autoload/settings.m
include mathicsscript/config.asy
include mathicsscript/data/inputrc-no-unicode
include mathicsscript/data/inputrc-unicode
include mathicsscript/data/mma-tables.json
include mathicsscript/fake_psviewer.py
include mathicsscript/user-settings.m
recursive-include mathicsscript *.py
recursive-include test *.py *.m
Expand Down
24 changes: 21 additions & 3 deletions mathicsscript/asymptote.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
#!/usr/bin/env python3
"""Python module to feed Asymptote with commands
(modified from gnuplot.py)
"""

import os
import os.path as osp

# Python module to feed Asymptote with commands
# (modified from gnuplot.py)
from subprocess import Popen, PIPE

asy_program = os.environ.get("ASY_PROG", "asy")


def get_srcdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
return osp.realpath(filename)


mydir = get_srcdir()
asy_config = os.path.join(mydir, "config.asy")


class Asy(object):
def __init__(self, show_help=True):
self.session = Popen(["asy", "-quiet", "-inpipe=0", "-outpipe=2"], stdin=PIPE)
self.session = Popen(
[asy_program, f"-config={asy_config}", "-quiet", "-inpipe=0", "-outpipe=2"],
stdin=PIPE,
)
if show_help:
self.help()

Expand Down
5 changes: 5 additions & 0 deletions mathicsscript/config.asy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This is an Asymptote configuration file for mathicsscript.
// We set up a fake_previewer which will remove out.eps
// that Asymptote wants to create
import settings;
psviewer="fake_psviewer.py";
23 changes: 23 additions & 0 deletions mathicsscript/fake_psviewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env Python
# -*- coding: utf-8 -*-
"""
This is a replacement for a PostScript previewer like gv
which does nothing, but remove any file argument it is
given.
Asymptote run via mathicsscript will create an embeded postscript file out.eps
which should be removed.
"""
import os
import sys


def main():
if len(sys.argv) > 1:
eps_file = sys.argv[1]
if os.path.exists(eps_file):
os.remove(eps_file)


if __name__ == "__main__":
main()
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ def read(*rnames):
"mathicsscript/data/inputrc-unicode",
"mathicsscript/user-settings.m",
"mathicsscript/autoload/settings.m",
"mathicsscript/config.asy",
]
},
install_requires=[
"Mathics_Scanner>=1.2.2",
"Mathics_Scanner>=1.2.4",
"Mathics3 >= 4.0.0,<4.1.0",
"click",
"colorama",
Expand All @@ -85,7 +86,12 @@ def read(*rnames):
"mathics_pygments>=1.0.2",
"term-background >= 1.0.1",
],
entry_points={"console_scripts": ["mathicsscript = mathicsscript.__main__:main"]},
entry_points={
"console_scripts": [
"mathicsscript = mathicsscript.__main__:main",
"fake_psviewer.py = mathicsscript.fake_psviewer:main",
]
},
extras_require=EXTRAS_REQUIRE,
long_description=long_description,
long_description_content_type="text/x-rst",
Expand Down

0 comments on commit 6951ba7

Please sign in to comment.