3

Is there a way to tell pip never to create a wheel cache of my package?

Background

I wrote a package for in-house use that sets up some symbolic links when installed using cmdclass in the setup.py. These post-install and post-develop triggers run fine if I install the sdist, but if I compile the package to a wheel, they do not run. To counter this, I make sure to only upload the sdist to our internal PyPI.

Problem

According to the documentation, when pip installs from an sdist it compiles it to a wheel and caches it for next time. This means that the package installs right the first time, but subsequent installs are broken.

I know I could run pip with --no-cache-dir, but I want to be sure everyone on my team can get the package correctly without having to add flags like this. There is no situation where someone would want a wheel of this package.

Question

Is there a setting or config variable I can set in my package to tell pip never to cache it as a wheel?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
jpyams
  • 4,030
  • 9
  • 41
  • 66

1 Answers1

2

There is no clean way of doing this that I know of. You can take your chances and play dirty.

Inspired by this comment, you could try with a setup.py script that looks like this (only partially tested):

#!/usr/bin/env python3

import setuptools

setuptools.setup(
    name='LookMaNoWheels',
    version='1.2.3',
    cmdclass={'bdist_wheel': None},
)

The idea is to force a failure when trying to build a wheel. When this happens, tools such as pip tend to recover from this by installing directly from whatever distribution is available instead (in your case a sdist).


Update

Something like this would help provide a more informative error message:

#!/usr/bin/env python3

import distutils.errors
import setuptools

bdist_wheel = None

try:
    import wheel.bdist_wheel
    class bdist_wheel(wheel.bdist_wheel.bdist_wheel):
        def run(self, *args, **kwargs):
            raise distutils.errors.DistutilsClassError("No!")
except ModuleNotFoundError:
    pass

setuptools.setup(
    name='LookMaNoWheels',
    version='1.2.3',
    cmdclass={'bdist_wheel': bdist_wheel},
)
sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • 1
    I like your dirty tactics and package naming scheme! I get a big `TypeError: issubclass() arg 1 must be a class`, but the sdist installs and the wheel isn't cached – jpyams Oct 08 '19 at 22:23
  • There is probably a nice way to deliver a more informative message in order to avoid scaring the users of your package. – sinoroc Oct 09 '19 at 15:22