diff --git a/flatland/flatland.py b/flatland/flatland.py index 7fbbae4f9c58882c3754a89675312f3c1430ffd8..6d61ba81dcba4b66584cfc43175e65a6485345e6 100644 --- a/flatland/flatland.py +++ b/flatland/flatland.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- """Main module.""" + diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py index 7fd49af8aaa4d8f95151ddc5ef4bd8c6704444da..4dd5179e50cdfb62c335edf14964c9b6118d0d81 100644 --- a/flatland/utils/graphics_layer.py +++ b/flatland/utils/graphics_layer.py @@ -2,6 +2,17 @@ import matplotlib.pyplot as plt from numpy import array +import os +if os.name=='nt': + import site + import ctypes.util + default_os_path = os.environ['PATH'] + os.environ['PATH'] = '' + for s in site.getsitepackages(): + os.environ['PATH'] = os.environ['PATH'] + ';' + s + '\\cairo' + os.environ['PATH'] = os.environ['PATH'] + ';' + default_os_path + if ctypes.util.find_library('cairo') is not None: + print("cairo installed: OK") class GraphicsLayer(object): def __init__(self): diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index b64d2e252f93e4ee4124bc9312d93898a50ee33c..96951c831e006a6a4585bcd539d0b0b01328e58a 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -6,7 +6,12 @@ import numpy as np # from flatland.utils.svg import Track, Zug import time import io + + from cairosvg import svg2png + +from IPython.display import SVG + from flatland.core.transitions import RailEnvTransitions # from copy import copy @@ -234,6 +239,8 @@ class PILSVG(PILGL): def pilFromSvgFile(self, sfPath): with open(sfPath, "r") as fIn: bytesPNG = svg2png(file_obj=fIn, output_height=self.nPixCell, output_width=self.nPixCell) + + image = SVG(url=sfPath) with io.BytesIO(bytesPNG) as fIn: pil_img = Image.open(fIn) diff --git a/requirements_dev.txt b/requirements_dev.txt index db80383febe488d4b0df2fc54407a976eb84b49b..a3558c4f29757e94acd3a5a032d4870cdb72f164 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -20,10 +20,10 @@ xarray==0.11.3 matplotlib==3.0.2 PyQt5==5.12 Pillow==5.4.1 -# CairoSVG==2.3.1 -# pycairo==1.18.1 +# see setup.py pycairo==1.18.1 +CairoSVG==2.3.1 msgpack==0.6.1 svgutils==0.3.1 -screeninfo==0.3.1 \ No newline at end of file +screeninfo==0.3.1 diff --git a/setup.py b/setup.py index d14070351559b5e59ed677751b70c20891dbc2f4..e8fe5f5e3619b58adfe48021f1ca583708a34343 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,12 @@ """The setup script.""" import os from setuptools import setup, find_packages +import sys +import os + +import platform + + with open('README.rst') as readme_file: readme = readme_file.read() @@ -11,6 +17,54 @@ with open('README.rst') as readme_file: with open('HISTORY.rst') as history_file: history = history_file.read() + + + + +# install pycairo +if os.name == 'nt': + p = platform.architecture() + is64bit = p[0] == '64bit' + if sys.version[0:3] == '3.5': + if is64bit: + url = 'https://download.lfd.uci.edu/pythonlibs/q5gtlas7/pycairo-1.18.0-cp35-cp35m-win_amd64.whl' + else: + url = 'https://download.lfd.uci.edu/pythonlibs/q5gtlas7/pycairo-1.18.0-cp35-cp35m-win32.whl' + + if sys.version[0:3] == '3.6': + if is64bit: + url = 'https://download.lfd.uci.edu/pythonlibs/q5gtlas7/pycairo-1.18.0-cp36-cp36m-win_amd64.whl' + else: + url = 'https://download.lfd.uci.edu/pythonlibs/q5gtlas7/pycairo-1.18.0-cp36-cp36m-win32.whl' + + if sys.version[0:3] == '3.7': + if is64bit: + url = 'https://download.lfd.uci.edu/pythonlibs/q5gtlas7/pycairo-1.18.0-cp37-cp37m-win_amd64.whl' + else: + url = 'https://download.lfd.uci.edu/pythonlibs/q5gtlas7/pycairo-1.18.0-cp37-cp37m-win32.whl' + + try: + import pycairo + except: + call_cmd = "pip install " + url + os.system(call_cmd) + + import site + import ctypes.util + default_os_path = os.environ['PATH'] + os.environ['PATH'] = '' + for s in site.getsitepackages(): + os.environ['PATH'] = os.environ['PATH']+';' + s+'\\cairo' + os.environ['PATH'] = os.environ['PATH']+';' + default_os_path + print(os.environ['PATH']) + if ctypes.util.find_library('cairo')is not None: + print("cairo installed: OK") +else: + try: + import pycairo + except: + os.system("pip install pycairo==1.18.1") + # Gather requirements from requirements_dev.txt # TODO : We could potentially split up the test/dev dependencies later install_reqs = []