Tuesday, 5 July 2022

Cannot get functions to execute in the Python setup.py in spite of following all the instructions

I have followed all the instructions outlined here for executing a function during the installation of a pip package but I still cannot get the function to execute up using `pip install <my_package>.

I have no .whl file in the dist folder. My setup file has the same format as the file mentioned in the aforementioned site as follows:

import urllib.request
import requests
## made some deletions here for simplicity sake
from setuptools.command.develop import develop
from setuptools.command.install import install

this_directory = Path(__file__).parent
long_description = ( this_directory/ "README.md").read_text()

def temp():
    print('running post installation')
    
    s = 'https://storage.googleapis.com/download/storage/etc'
    urllib.request.urlopen(s)
    if not os.path.exists(fold):
        os.mkdir(fold)
    file = f'{fold}hey.txt'  # this is got from elsewhere in the code
    r = requests.get(s, stream=True, verify=False)
    if r.status_code == 200:
        r.raw.decode_content = 1
        with open(file, 'wb') as f:
            f.write(r.content)
    else:
        p('failed to download data files')


class PostDevelopCommand(develop):
    """Post-installation for development mode."""
    def run(self):
        temp()
        develop.run(self)


class PostInstallCommand(install):
    """Post-installation for installation mode."""
    def run(self):
        temp()
        install.run(self)

setup(
    ### simplified this a bit
    install_requires=['Levenshtein',
                      'striprtf==0.0.12',
                      ],
    cmdclass={
            'develop': PostDevelopCommand,
            'install': PostInstallCommand,
        },

    classifiers=[
        'Development Status :: 1 - Planning',
        'Intended Audience :: Education',
        'License :: OSI Approved :: GNU General Public License (GPL)',
        'Operating System :: MacOS',
        'Programming Language :: Python :: 3.8',
    ],
)

On downloading the package I am not even getting the reading: print('running post installation') which leads to believe that the function temp is not being executed. What am I doing wrong?



from Cannot get functions to execute in the Python setup.py in spite of following all the instructions

No comments:

Post a Comment