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.

bobsmith76
  • 160
  • 1
  • 9
  • 26
  • maybe there is a hacky way to do this but it doesn't even matter.What you describe is the a typical docker usecase. – Ευάγγελος Γρηγορόπουλος Jun 30 '22 at 20:18
  • https://stackoverflow.com/a/36902139/7976758 Found in https://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. – phd Jun 30 '22 at 20:20
  • Please see update. Also for installing a source distribution do I just delete the .whl file? – bobsmith76 Jul 01 '22 at 01:10

0 Answers0