0

I'm trying to execute a function after the installation of my pip package is complete. I realize you cannot have a .whl file in the dist folder so I used python3 setup.py sdist. I changed the setup.py file to:

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.

3
  • maybe there is a hacky way to do this but it doesn't even matter.What you describe is the a typical docker usecase. Commented Jun 30, 2022 at 20:18
  • stackoverflow.com/a/36902139/7976758 Found in stackoverflow.com/search?q=%5Bsetuptools%5D+post-install+script Please note: "The solution … only works when installing a source distribution … It will not work when installing from a binary wheel (.whl)" Emphasize mine. Commented Jun 30, 2022 at 20:20
  • Please see update. Also for installing a source distribution do I just delete the .whl file? Commented Jul 1, 2022 at 1:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.