Skip to content

Support for scripts with unicode content #1389

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

Merged
merged 3 commits into from
Aug 17, 2018
Merged
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
1 change: 1 addition & 0 deletions changelog.d/1389.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scripts which have unicode content are now supported
8 changes: 4 additions & 4 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def samefile(p1, p2):

if six.PY2:

def _to_ascii(s):
def _to_bytes(s):
return s

def isascii(s):
Expand All @@ -107,8 +107,8 @@ def isascii(s):
return False
else:

def _to_ascii(s):
return s.encode('ascii')
def _to_bytes(s):
return s.encode('utf8')

def isascii(s):
try:
Expand Down Expand Up @@ -805,7 +805,7 @@ def install_script(self, dist, script_name, script_text, dev_path=None):
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):
Expand Down
52 changes: 52 additions & 0 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,58 @@ def test_unicode_filename_in_sdist(self, sdist_unicode, tmpdir, monkeypatch):
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 = [
Expand Down