2

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?

bobsmith76
  • 160
  • 1
  • 9
  • 26
  • You wrote that you installed via `pip install `, so you uploaded that project to PyPI and installed from there? What did you upload? How did you build the project? Can you share the name of the project? – a_guest Jul 11 '22 at 08:39

1 Answers1

0

You cannot change the pip logs

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>.

Running pip install <my_package>, you will see only pip logs, and you cannot change it or call some function during pip install. Just imagine, if we can run any script during pip install, we could steal any information that does not require permissions.

Complete the arguments of the setup function

I have no .whl file in the dist folder.

The setup.py is only missing some arguments for the setup function. Follow the instructions of my answer. Also, I am not sure you're running the build properly, so please use the build command that has been provided in the answer.

Do not confuse downloading the package with post-installing the egg

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?

It is printed on post-installation of the .egg. So if you run python3 setup.py sdist bdist_wheel it will start to build the package and the text you print you will see in that logs. For me, it was the follofing.

running sdist
running egg_info
creating my_package.egg-info
writing my_package.egg-info/PKG-INFO
writing dependency_links to my_package.egg-info/dependency_links.txt
writing requirements to my_package.egg-info/requires.txt
writing top-level names to my_package.egg-info/top_level.txt
writing manifest file 'my_package.egg-info/SOURCES.txt'
reading manifest file 'my_package.egg-info/SOURCES.txt'
writing manifest file 'my_package.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md

running check
warning: Check: missing required meta-data: url

creating my_package-0.0.1
creating my_package-0.0.1/my_package
creating my_package-0.0.1/my_package.egg-info
copying files to my_package-0.0.1...
copying setup.py -> my_package-0.0.1
copying my_package/__init__.py -> my_package-0.0.1/my_package
copying my_package/demo.py -> my_package-0.0.1/my_package
copying my_package.egg-info/PKG-INFO -> my_package-0.0.1/my_package.egg-info
copying my_package.egg-info/SOURCES.txt -> my_package-0.0.1/my_package.egg-info
copying my_package.egg-info/dependency_links.txt -> my_package-0.0.1/my_package.egg-info
copying my_package.egg-info/requires.txt -> my_package-0.0.1/my_package.egg-info
copying my_package.egg-info/top_level.txt -> my_package-0.0.1/my_package.egg-info
Writing my_package-0.0.1/setup.cfg
creating dist
Creating tar archive
removing 'my_package-0.0.1' (and everything under it)
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/my_package
copying my_package/demo.py -> build/lib/my_package
copying my_package/__init__.py -> build/lib/my_package
installing to build/bdist.linux-x86_64/wheel
running install
running post installation
/home/artyom/.local/lib/python3.9/site-packages/urllib3/connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host 'storage.googleapis.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
failed to download data files
running install_lib
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/my_package
copying build/lib/my_package/demo.py -> build/bdist.linux-x86_64/wheel/my_package
copying build/lib/my_package/__init__.py -> build/bdist.linux-x86_64/wheel/my_package
running install_egg_info
Copying my_package.egg-info to build/bdist.linux-x86_64/wheel/my_package-0.0.1-py3.9.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/my_package-0.0.1.dist-info/WHEEL
creating 'dist/my_package-0.0.1-py3-none-any.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'my_package/__init__.py'
adding 'my_package/demo.py'
adding 'my_package-0.0.1.dist-info/METADATA'
adding 'my_package-0.0.1.dist-info/WHEEL'
adding 'my_package-0.0.1.dist-info/top_level.txt'
adding 'my_package-0.0.1.dist-info/RECORD'
removing build/bdist.linux-x86_64/wheel
Artyom Vancyan
  • 5,029
  • 3
  • 12
  • 34
  • I've followed all the instructions, I don't understand what I'm doing wrong. Could you tell me what syntax needs to be altered? – bobsmith76 Jul 10 '22 at 09:04
  • Just add your package meta-data such as `name`, `version`, `author`, `author_email`, `url`, `description` and `packages` to `setup` function. Execute `python3 setup.py sdist bdist_wheel` command to build the package and `python3 -m twine upload dist/*` to publish the package to PyPI. – Artyom Vancyan Jul 10 '22 at 09:31
  • But I'vd done that and when I hit pip install nothing downloads. What I'm trying to do is that when I run pip install extra files should be downloaded. If you're interested you can take a look at `https://pypi.org/project/latin-databases/` – bobsmith76 Jul 18 '22 at 07:49