classification
Title: distutils relative path errors
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: tarek Nosy List: eric.araujo, ghazel, neXyon, steve.dower, tarek
Priority: normal Keywords:

Created on 2010-06-18 08:47 by ghazel, last changed 2021-02-03 18:04 by steve.dower. This issue is now closed.

Messages (7)
msg108085 - (view) Author: Greg Hazel (ghazel) Date: 2010-06-18 08:47
Probably applies to more versions, but I only tested on 2.5.2 and 2.6.5.

Distutils incorrectly constructs paths for the build/temp directory when relative paths are used in the "sources" list. This can result in failing to make the build/temp directory at all, and placing files in outside of the build/temp directory.

Consider the following example:

gah@duma:~$ mkdir libfoo
gah@duma:~$ cd libfoo
gah@duma:~/libfoo$ echo > foo.c
gah@duma:~/libfoo$ mkdir pyfoo
gah@duma:~/libfoo$ cd pyfoo
gah@duma:~/libfoo/pyfoo$ echo "from setuptools import setup, Library; setup(name='foo', ext_modules=[Library(name='foo',sources=['../foo.c'])])" > setup.py
gah@duma:~/libfoo/pyfoo$ python setup.py build
running build
running build_ext
building 'foo' extension
creating build
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c ../foo.c -o build/temp.linux-i686-2.5/../foo.o
Assembler messages:
Fatal error: can't create build/temp.linux-i686-2.5/../foo.o: No such file or directory
error: command 'gcc' failed with exit status 1


Using os.path.abspath('../foo.c') in the sources causes distutils to create build/temp.linux-i686-2.5/home/gah/libfoo/foo.o which is fine. However as a user, this situation is quite surprising, since distutils is responsible for managing the build and temp directories itself.
msg114509 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-21 16:43
I’m not sure how I feel about paths going to the parent directory. Your use case is not imaginary or contrived, but I’m uncomfortable with going out of the source tree.

Your setup script would work if the setup script was in the root of the source tree, right? In this case, I would requalify this as a doc bug. Can you test this solution (also with distutils-only code)? Thank you.
msg114520 - (view) Author: Greg Hazel (ghazel) Date: 2010-08-21 17:18
The python setup script is for the python module, which is in a subdirectory of the C library project. I am not going to move setup.py to the root directory just to work around a a distutils bug.

This distutils bug could cause it to overwrite files in other directories, since it blindly adds relative paths to the build directory. This is clearly broken.

I've changed my code to use os.path.abspath() while I wait for a fix.
msg114521 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-21 17:24
> I am not going to move setup.py to the root directory just to work
> around a a distutils bug.
Fair enough.

> This distutils bug could cause it to overwrite files in other
> directories, since it blindly adds relative paths to the build
> directory. This is clearly broken.
Ah, I hadn’t understood that. I agree with you.

> I've changed my code to use os.path.abspath() while I wait for a
> fix.
Does this means that your code works with paths that go to the parent directory? I don’t know if it’s right to allow that (I mean this literally: I’m not the main maintainer and I don’t have much packaging experience).
msg114528 - (view) Author: Greg Hazel (ghazel) Date: 2010-08-21 17:42
> Éric Araujo <merwok@netwok.org> added the comment:
>> I've changed my code to use os.path.abspath() while I wait for a
>> fix.
> Does this means that your code works with paths that go to the parent directory? I don’t know if it’s right to allow that (I mean this literally: I’m not the main maintainer and I don’t have much packaging experience).

Yes, my code works with the os.path.abspath() change, since it creates the entire absolute path directory structure inside the build directory. This is
msg248122 - (view) Author: Jörg Müller (neXyon) Date: 2015-08-06 10:30
This bug still exists. I am having a similar use case as ghazel. I have to use absolute paths for the setup.py to work, but the problem is that those paths then end up in the egg-info/SOURCES.txt file which is something that package maintainers of linux distributions don't like!
msg386240 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-03 18:04
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:04:28steve.dowersetstatus: open -> closed

nosy: + steve.dower
messages: + msg386240

resolution: out of date
stage: resolved
2020-11-08 19:24:01iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.1, Python 2.7, Python 3.2, Python 3.3, Python 3.4
2015-08-06 10:30:40neXyonsetnosy: + neXyon

messages: + msg248122
versions: + Python 3.3, Python 3.4
2010-08-21 17:42:46ghazelsetmessages: + msg114528
2010-08-21 17:24:41eric.araujosetmessages: + msg114521
2010-08-21 17:18:33ghazelsetmessages: + msg114520
2010-08-21 16:43:42eric.araujosetmessages: + msg114509
versions: + Python 3.1, Python 2.7
2010-06-19 05:01:50eric.araujosetnosy: + eric.araujo

versions: + Python 3.2, - Python 2.6, Python 2.5
2010-06-18 08:47:29ghazelcreate