Commit afba2d89 authored by Paul Ganssle's avatar Paul Ganssle Committed by GitHub

Merge pull request #1389 from expobrain/scripts_ascii

Support for scripts with unicode content
parents 85593de6 c43d0f6f
Scripts which have unicode content are now supported
......@@ -96,7 +96,7 @@ def samefile(p1, p2):
if six.PY2:
def _to_ascii(s):
def _to_bytes(s):
return s
def isascii(s):
......@@ -107,8 +107,8 @@ if six.PY2:
return False
else:
def _to_ascii(s):
return s.encode('ascii')
def _to_bytes(s):
return s.encode('utf8')
def isascii(s):
try:
......@@ -805,7 +805,7 @@ class easy_install(Command):
if is_script:
body = self._load_template(dev_path) % locals()
script_text = ScriptWriter.get_header(script_text) + body
self.write_script(script_name, _to_ascii(script_text), 'b')
self.write_script(script_name, _to_bytes(script_text), 'b')
@staticmethod
def _load_template(dev_path):
......
......@@ -185,6 +185,58 @@ class TestEasyInstallTest:
cmd.ensure_finalized()
cmd.easy_install(sdist_unicode)
@pytest.fixture
def sdist_unicode_in_script(self, tmpdir):
files = [
(
"setup.py",
DALS("""
import setuptools
setuptools.setup(
name="setuptools-test-unicode",
version="1.0",
packages=["mypkg"],
include_package_data=True,
scripts=['mypkg/unicode_in_script'],
)
"""),
),
("mypkg/__init__.py", ""),
(
"mypkg/unicode_in_script",
DALS(
"""
#!/bin/sh
# \xc3\xa1
non_python_fn() {
}
"""),
),
]
sdist_name = "setuptools-test-unicode-script-1.0.zip"
sdist = tmpdir / sdist_name
# can't use make_sdist, because the issue only occurs
# with zip sdists.
sdist_zip = zipfile.ZipFile(str(sdist), "w")
for filename, content in files:
sdist_zip.writestr(filename, content)
sdist_zip.close()
return str(sdist)
@fail_on_ascii
def test_unicode_content_in_sdist(self, sdist_unicode_in_script, tmpdir, monkeypatch):
"""
The install command should execute correctly even if
the package has unicode in scripts.
"""
dist = Distribution({"script_args": ["easy_install"]})
target = (tmpdir / "target").ensure_dir()
cmd = ei.easy_install(dist, install_dir=str(target), args=["x"])
monkeypatch.setitem(os.environ, "PYTHONPATH", str(target))
cmd.ensure_finalized()
cmd.easy_install(sdist_unicode_in_script)
@pytest.fixture
def sdist_script(self, tmpdir):
files = [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment