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.