Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few fixes #68

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "mplexporter"]
path = mplexporter
url = git@github.com:jwass/mplexporter.git
url = https://github.com/mpld3/mplexporter.git
Binary file added __pycache__/_mplleaflet_setup.cpython-39.pyc
Binary file not shown.
162 changes: 162 additions & 0 deletions _mplleaflet_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""
Tools to help with setup.py
Much of this is based on tools in the IPython project:
http://github.com/ipython/ipython
"""

import os
import subprocess
import sys
import warnings
import shutil

try:
from setuptools import Command
except:
from distutils.cmd import Command


SUBMODULES = ['mplexporter']
SUBMODULE_SYNC_PATHS = [('mplexporter/mplexporter', 'mplleaflet/mplexporter')]


def is_repo(d):
"""is d a git repo?"""
return os.path.exists(os.path.join(d, '.git'))


def check_submodule_status(root=None):
"""check submodule status
Has three return values:
'missing' - submodules are absent
'unclean' - submodules have unstaged changes
'clean' - all submodules are up to date
"""
if root is None:
root = os.path.dirname(os.path.abspath(__file__))

if hasattr(sys, "frozen"):
# frozen via py2exe or similar, don't bother
return 'clean'

if not is_repo(root):
# not in git, assume clean
return 'clean'

for submodule in SUBMODULES:
if not os.path.exists(submodule):
return 'missing'

# Popen can't handle unicode cwd on Windows Python 2
if sys.platform == 'win32' and sys.version_info[0] < 3 \
and not isinstance(root, bytes):
root = root.encode(sys.getfilesystemencoding() or 'ascii')
# check with git submodule status
proc = subprocess.Popen('git submodule status',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
cwd=root,
)
status, _ = proc.communicate()
status = status.decode("ascii", "replace")

for line in status.splitlines():
if line.startswith('-'):
return 'missing'
elif line.startswith('+'):
return 'unclean'

return 'clean'


def update_submodules(repo_dir):
"""update submodules in a repo"""
subprocess.check_call("git submodule init", cwd=repo_dir, shell=True)
subprocess.check_call("git submodule update --recursive",
cwd=repo_dir, shell=True)


def sync_files(source, dest):
"""Syncs files copies files from `source` directory to the
`dest` directory. A check is first done to see if the `dest`
directory exists, if so, the directory is removed to provide
a clean install.
"""
if os.path.isdir(source) and os.path.isdir(dest):
try:
print("Remove {0}".format(dest))
shutil.rmtree(dest)
except OSError as e:
# An error occured tyring to remove directory
print(e.errno)
print(e.filename)
print(e.strerror)

print("Copying {0} to {1}".format(source, dest))
shutil.copytree(source, dest)


def sync_submodules(repo_dir):
for source, dest in SUBMODULE_SYNC_PATHS:
source = os.path.join(repo_dir, source)
dest = os.path.join(repo_dir, dest)
sync_files(source, dest)


def require_clean_submodules(repo_dir, argv):
"""Check on git submodules before distutils can do anything
Since distutils cannot be trusted to update the tree
after everything has been set in motion,
this is not a distutils command.
"""
# Only do this if we are in the git source repository.
if not is_repo(repo_dir):
return

# don't do anything if nothing is actually supposed to happen
for do_nothing in ('-h', '--help', '--help-commands',
'clean', 'submodule', 'buildjs'):
if do_nothing in argv:
return

status = check_submodule_status(repo_dir)

if status == "missing":
print("checking out submodules for the first time")
update_submodules(repo_dir)
elif status == "unclean":
print('\n'.join([
"Cannot build / install mpld3 with unclean submodules",
"Please update submodules with",
" python setup.py submodule",
"or commit any submodule changes you have made."
]))
sys.exit(1)

sync_submodules(repo_dir)


class UpdateSubmodules(Command):
"""Update git submodules"""
description = "Update git submodules"
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
failure = False
try:
self.spawn('git submodule init'.split())
self.spawn('git submodule update --recursive'.split())
except Exception as e:
failure = e
print(e)

if not check_submodule_status() == 'clean':
print("submodules could not be checked out")
sys.exit(1)
10 changes: 4 additions & 6 deletions mplleaflet/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .links import JavascriptLink, CssLink
from .utils import FloatEncoder
from . import maptiles
from IPython.display import IFrame

# We download explicitly the CSS and the JS.
_leaflet_js = JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js')
Expand Down Expand Up @@ -157,12 +158,9 @@ def display(fig=None, closefig=True, **kwargs):
html = fig_to_html(fig, **kwargs)

# We embed everything in an iframe.
iframe_html = '<iframe src="data:text/html;base64,{html}" width="{width}" height="{height}"></iframe>'\
.format(html = base64.b64encode(html.encode('utf8')).decode('utf8'),
width = '100%',
height= int(60.*fig.get_figheight()),
)
return HTML(iframe_html)
src = "data:text/html;base64,{html}".format(html = base64.b64encode(html.encode('utf8')).decode('utf8'))
return IFrame(src=src, width='100%', height=int(60.*fig.get_figheight()))


def show(fig=None, path='_map.html', **kwargs):
"""
Expand Down
13 changes: 12 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import sys

try:
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup, find_packages

from _mplleaflet_setup import (require_clean_submodules, UpdateSubmodules)

with open('AUTHORS.md') as f:
authors = f.read()

Expand All @@ -17,6 +22,10 @@
LICENSE = 'BSD 3-clause'
VERSION = '0.0.5'

# Make sure submodules are updated and synced
root_dir = os.path.abspath(os.path.dirname(__file__))
require_clean_submodules(root_dir, sys.argv)

setup(
name=NAME,
version=VERSION,
Expand All @@ -29,10 +38,12 @@
url=DOWNLOAD_URL,
download_url=DOWNLOAD_URL,
license=LICENSE,
packages=find_packages(),
cmdclass={'submodule': UpdateSubmodules},
packages=list(set(find_packages() + ["mplleaflet","mplleaflet/mplexporter","mplleaflet/mplexporter/renderers"])),
package_data={'': ['*.html']}, # Include the templates
install_requires=[
"jinja2",
"six",
"ipython",
],
)