classification
Title: test_distutils fails if current directory contains spaces
Type: behavior Stage: resolved
Components: Distutils, Tests Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: dstufft, eric.araujo, serhiy.storchaka, steve.dower, xtreak
Priority: normal Keywords:

Created on 2017-09-22 10:39 by serhiy.storchaka, last changed 2021-02-03 18:16 by steve.dower. This issue is now closed.

Messages (3)
msg302741 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-22 10:39
Running tests from the directory containing a space: '/home/serhiy/py/cpy thon'.

$ ./python -m test -vuall test_distutils
== CPython 3.7.0a1+ (heads/master:5e02c7826f, Sep 22 2017, 13:23:33) [GCC 6.3.0 20170406]
== Linux-4.10.0-35-generic-x86_64-with-debian-stretch-sid little-endian
== cwd: /home/serhiy/py/cpy thon/build/test_python_11135
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
Run tests sequentially
0:00:00 load avg: 0.09 [1/1] test_distutils
test_no_optimize_flag (distutils.tests.test_bdist_rpm.BuildRpmTestCase) ... /var/tmp/rpm-tmp.ufRiE4: 28: /var/tmp/rpm-tmp.ufRiE4: /home/serhiy/py/cpy: not found
error: Bad exit status from /var/tmp/rpm-tmp.ufRiE4 (%build)
    Bad exit status from /var/tmp/rpm-tmp.ufRiE4 (%build)
ERROR
test_quiet (distutils.tests.test_bdist_rpm.BuildRpmTestCase) ... /var/tmp/rpm-tmp.uBva85: 28: /var/tmp/rpm-tmp.uBva85: /home/serhiy/py/cpy: not found
error: Bad exit status from /var/tmp/rpm-tmp.uBva85 (%build)
    Bad exit status from /var/tmp/rpm-tmp.uBva85 (%build)
ERROR
...
======================================================================
ERROR: test_no_optimize_flag (distutils.tests.test_bdist_rpm.BuildRpmTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpy thon/Lib/distutils/tests/test_bdist_rpm.py", line 120, in test_no_optimize_flag
    cmd.run()
  File "/home/serhiy/py/cpy thon/Lib/distutils/command/bdist_rpm.py", line 366, in run
    self.spawn(rpm_cmd)
  File "/home/serhiy/py/cpy thon/Lib/distutils/cmd.py", line 365, in spawn
    spawn(cmd, search_path, dry_run=self.dry_run)
  File "/home/serhiy/py/cpy thon/Lib/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/home/serhiy/py/cpy thon/Lib/distutils/spawn.py", line 159, in _spawn_posix
    % (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'rpmbuild' failed with exit status 1

======================================================================
ERROR: test_quiet (distutils.tests.test_bdist_rpm.BuildRpmTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpy thon/Lib/distutils/tests/test_bdist_rpm.py", line 77, in test_quiet
    cmd.run()
  File "/home/serhiy/py/cpy thon/Lib/distutils/command/bdist_rpm.py", line 366, in run
    self.spawn(rpm_cmd)
  File "/home/serhiy/py/cpy thon/Lib/distutils/cmd.py", line 365, in spawn
    spawn(cmd, search_path, dry_run=self.dry_run)
  File "/home/serhiy/py/cpy thon/Lib/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/home/serhiy/py/cpy thon/Lib/distutils/spawn.py", line 159, in _spawn_posix
    % (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'rpmbuild' failed with exit status 1

----------------------------------------------------------------------

See also issue31548.
msg326518 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-27 02:46
There is a similar issue with whitespace in filenames causing failure in bdist_rpm tracked at issue809163. It has test cases but unfortunately the issue didn't move forward and has only patches. I tried the patches but none of them seem to fix the issue here. The issue seems to be in spec file generation with space in path of python executable. Did some debugging and my analysis as follows. Renamed my source directory 'cpython' as 'cpy thon' and made a clean build. It seems that sys.executable returns '/home/karthi/cpy thon/python' which is used as the python binary for the commands and hence with normal string concatenation the spec file generated [0] . I tried very basic fix of sys.executable.replace(' ', '\ ') to be used as a path. It generates the correct spec file [1] which passes and ./python -m test -vuall test_distutils also passes.

I am not sure if Python has a function to escape spaces for shell commands which would be more reliable. I tried shlex.quote but it handles only ' and ". I think having space in the directory might cause issues in places where we use string concatenation with sys.executable without taking spaces into account like the other issue with windows. I will try running the test suite sometime with space.

[0] With spaces. The commands that fail are /home/karthi/cpy thon/python setup.py build and /home/karthi/cpy thon/python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES

%define name foo
%define version 0.1
%define unmangled_version 0.1
%define release 1

Summary: UNKNOWN
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{unmangled_version}.tar.gz
License: UNKNOWN
Group: Development/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: noarch
Vendor: xxx <xxx>
Url: xxx

%description
UNKNOWN

%prep
%setup -n %{name}-%{unmangled_version}

%build
/home/karthi/cpy thon/python setup.py build

%install
/home/karthi/cpy thon/python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES

%clean
rm -rf $RPM_BUILD_ROOT

%files -f INSTALLED_FILES
%defattr(-,root,root)


[1] sys.executable.replace(' ', '\ ') and the tests pass


%define name foo
%define version 0.1
%define unmangled_version 0.1
%define release 1

Summary: UNKNOWN
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{unmangled_version}.tar.gz
License: UNKNOWN
Group: Development/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: noarch
Vendor: xxx <xxx>
Url: xxx

%description
UNKNOWN

%prep
%setup -n %{name}-%{unmangled_version}

%build
/home/karthi/cpy\ thon/python setup.py build

%install
/home/karthi/cpy\ thon/python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES

%clean
rm -rf $RPM_BUILD_ROOT

%files -f INSTALLED_FILES
%defattr(-,root,root)


I am adding 3.8 also as a target as part of triaging this issue.

Thanks
msg386321 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-03 18:16
Distutils is now deprecated (see PEP 632) and all tagged issues are being closed. From now until removal, only release blocking issues will be considered for distutils.

If this issue does not relate to distutils, please remove the component and reopen it. If you believe it still requires a fix, most likely the issue should be re-reported at https://github.com/pypa/setuptools
History
Date User Action Args
2021-02-03 18:16:31steve.dowersetstatus: open -> closed

nosy: + steve.dower
messages: + msg386321

resolution: out of date
stage: resolved
2018-09-27 02:46:58xtreaksetmessages: + msg326518
versions: + Python 3.8
2018-09-26 18:12:28xtreaksetnosy: + xtreak
2017-09-22 10:39:31serhiy.storchakacreate