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

fix windows path problem #24

Merged
merged 11 commits into from
May 31, 2018
Merged
2 changes: 2 additions & 0 deletions .moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ configuration:
- "setupmobans/templates"
- ".moban.d"
configuration: pyecharts-snapshot.yml
plugin_dir:
- "setupmobans/plugins"
targets:
- setup.py: setup.py
- requirements.txt: requirements.txt.jj2
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change log
================================================================================

0.1.7 - 31.05.2018
--------------------------------------------------------------------------------

Fixed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. `#23 <https://github.com/pyecharts/pyecharts-snapshot/issues/23>`_: phantomjs
on windows does not like absolute path but file uri formatted ones

0.1.6 - 16.05.2018
--------------------------------------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: pyecharts-snapshot
organisation: pyecharts
releases:
- changes:
- action: Fixed
details:
- '`#23`: phantomjs on windows does not like absolute path but file uri formatted ones'
date: 31.05.2018
version: 0.1.7
- changes:
- action: Updated
details:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

project = u'pyecharts-snapshot'
copyright = u'2017-2018 Onni Software Ltd.'
version = '0.1.6'
release = '0.1.6'
version = '0.1.7'
release = '0.1.7'
exclude_patterns = []
pygments_style = 'sphinx'
html_theme = 'default'
Expand Down
6 changes: 3 additions & 3 deletions pyecharts-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ organisation: "pyecharts"
author: "C.W."
contact: "[email protected]"
company: "Onni Software Ltd."
version: "0.1.6"
current_version: "0.1.6"
release: "0.1.6"
version: "0.1.7"
current_version: "0.1.7"
release: "0.1.7"
copyright_year: 2017-2018
command_line_interface: "snapshot"
entry_point: "pyecharts_snapshot.main:main"
Expand Down
10 changes: 8 additions & 2 deletions pyecharts_snapshot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ def make_a_snapshot(file_name, output_name, delay=DEFAULT_DELAY, verbose=True):
file_type = output_name.split('.')[-1]
pixel_ratio = 2
__actual_delay_in_ms = int(delay * 1000)

# add shell=True and it works on Windows now.
proc_params = [
PHANTOMJS_EXEC,
os.path.join(get_resource_dir('phantomjs'), 'snapshot.js'),
file_name.replace('\\', '/'),
to_file_uri(file_name),
file_type,
str(__actual_delay_in_ms),
str(pixel_ratio)
Expand Down Expand Up @@ -163,3 +162,10 @@ def chk_phantomjs():

def get_shell_flag():
return sys.platform == 'win32'


def to_file_uri(a_file_name):
__universal_file_name = a_file_name.replace('\\', '/')
if ':' not in a_file_name:
__universal_file_name = os.path.abspath(__universal_file_name)
return 'file:///{0}'.format(__universal_file_name)
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@

NAME = 'pyecharts-snapshot'
AUTHOR = 'C.W.'
VERSION = '0.1.6'
VERSION = '0.1.7'
EMAIL = '[email protected]'
LICENSE = 'MIT'
ENTRY_POINTS = {
'console_scripts': [
'snapshot = pyecharts_snapshot.main:main'
]
],
}
DESCRIPTION = (
'renders pyecharts output as image'
)

URL = 'https://github.com/pyecharts/pyecharts-snapshot'
DOWNLOAD_URL = '%s/archive/0.1.7.tar.gz' % URL

DOWNLOAD_URL = '%s/archive/0.1.6.tar.gz' % URL
FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst']
KEYWORDS = [
'echarts',
Expand Down Expand Up @@ -64,8 +64,8 @@
# You do not need to read beyond this line
PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format(
sys.executable)
GS_COMMAND = ('gs pyecharts-snapshot v0.1.6 ' +
"Find 0.1.6 in changelog for more details")
GS_COMMAND = ('gs pyecharts-snapshot v0.1.7 ' +
"Find 0.1.7 in changelog for more details")
NO_GS_MESSAGE = ('Automatic github release is disabled. ' +
'Please install gease to enable it.')
UPLOAD_FAILED_MSG = (
Expand Down
15 changes: 13 additions & 2 deletions tests/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from platform import python_implementation

from pyecharts_snapshot.main import main, make_a_snapshot, PY2
from pyecharts_snapshot.main import save_as_svg
from pyecharts_snapshot.main import save_as_svg, to_file_uri

PY27 = sys.version_info[1] == 7 and PY2 and python_implementation() != "PyPy"
HTML_FILE = os.path.join("tests", "fixtures", "render.html")
Expand Down Expand Up @@ -96,7 +96,8 @@ def test_windows_file_name(self):
main()
except Exception:
print(self.fake_popen.call_args)
eq_(self.fake_popen.call_args[0][0][2],
assert self.fake_popen.call_args[0][0][2].startswith('file:////')
assert self.fake_popen.call_args[0][0][2].endswith(
'tests/fixtures/render.html')

def test_default_delay_value(self):
Expand Down Expand Up @@ -213,6 +214,16 @@ def test_unsupported_file_type():
test_output)


def test_to_file_uri():
windows_file = 'C:\\user\\tmp.html'
uri = to_file_uri(windows_file)
eq_(uri, 'file:///C:/user/tmp.html')
linux_file = 'tests/fixtures/tmp.html'
uri2 = to_file_uri(linux_file)
assert uri2.startswith('file:////')
assert uri2.endswith(linux_file)


def get_base64_image():
with open(get_fixture('base64.txt'), 'r') as f:
content = f.read().replace('\r\n', '')
Expand Down