Get CWD when installing over PIP

Viewed 525

Hello I'm trying to add a custom step to my Python3 package. What I wish for, is to execute a make command in a root directory of my Python package. However, when I install my package with pip3 install ., the CWD (current working directory) changes to /tmp/pip-req-build-<something>

Here is what I have:

    from setuptools import setup, find_packages
    from setuptools.command.develop import develop
    from setuptools.command.install import install
    
    import subprocess, os
    
    
    class CustomInstall(install):
        def run(self):
            #subprocess.run(['make', '-C', 'c_library/']) # this doesn't work as c_library/ doesn't exist in the changed path
            subprocess.run('./getcwd.sh')
            install.run(self)
    
    setup(
        cmdclass={
            'install': CustomInstall
        },
        name='my-py-package',
        version='0.0.1',
        ....
    )

Now, what's interesting to me is that the getcwd.sh gets executed, and inside of it I have this. It also prints the TMP location.

    #!/bin/bash
    SCRIPT=`realpath $0`
    SCRIPTPATH=`dirname $SCRIPT`
    echo $SCRIPTPATH > ~/Desktop/my.log

Is there a way to get the path from where the pip install . was run?

Python 3.8.5, Ubuntu 20.04, Pip3 pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

0 Answers
Related