[issue31551] test_distutils fails if current directory contains spaces

Karthikeyan Singaravelan report at bugs.python.org
Wed Sep 26 22:46:58 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

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

----------
versions: +Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31551>
_______________________________________


More information about the Python-bugs-list mailing list