wheel icon indicating copy to clipboard operation
wheel copied to clipboard

bdist_wheel should start by cleaning up its build directory

Open agronholm opened this issue 10 years ago • 11 comments

Originally reported by: Xavier Fernandez (Bitbucket: xavfernandez, GitHub: xavfernandez)


bdist_wheel does not clean up its build directory making it easy to include obsolete/unwanted files.

On python 2.7, if you run python setup.py bdist_wheel once, add a file in build/lib.linux-x86_64-2.7 and rerun python setup.py bdist_wheel you'll have the file in your wheel. I had this issue with https://github.com/Polyconseil/getconf but it concerns all packages, you can easily reproduce with the wheel package.

It can be quite unsettling, since it bypasses, all MANIFEST or find_packages rules...

It would seem cleaner and safer to simply start from a fresh directory and delete it afterwards.


  • Bitbucket: https://bitbucket.org/pypa/wheel/issue/147

agronholm avatar Aug 21 '15 10:08 agronholm

Original comment by JonathonReinhart (Bitbucket: JonathonReinhart, GitHub: JonathonReinhart):


I've opened this issue with setuptools (1064) for my problem (which may be related to this one).

agronholm avatar Jun 15 '17 12:06 agronholm

Original comment by JonathonReinhart (Bitbucket: JonathonReinhart, GitHub: JonathonReinhart):


Do you guys think this issue is the cause of my problem where bdist_wheel and sdist bdist_wheel are different? https://github.com/JonathonReinhart/staticx/issues/22#issuecomment-308439558

agronholm avatar Jun 15 '17 00:06 agronholm

Original comment by feluxe (Bitbucket: le0m, GitHub: le0m):


bdist_wheel does not clean up its build directory making it easy to include obsolete/unwanted files.

I have the same issue. It's very annoying, because you usually notice the obsolete modules/packages after publishing. So you have to bump version num again, re-build, re-publish, etc...

agronholm avatar Jun 14 '17 10:06 agronholm

Original comment by Michael Merickel (Bitbucket: mmerickel, GitHub: mmerickel):


Same problem here https://github.com/Pylons/pyramid/issues/2525

Used a stale build folder and had no idea that bdist_wheel would ignore setuptools-git. Honestly the best approach would be to just take the sdist and convert to a wheel, since the sdist does what I want.

agronholm avatar Apr 27 '16 19:04 agronholm

Original comment by Daniel Greenfeld (Bitbucket: pydanny, GitHub: pydanny):


Had the same problem at https://github.com/BradWhittington/django-mailgun/issues/28.

agronholm avatar Sep 24 '15 00:09 agronholm

Any news on this issue? I just ran into it nearly 4 years after it was first reported :-(

Also are there any workarounds?

mcarans avatar May 20 '19 11:05 mcarans

Workaround: remove the build directory before running bdist_wheel. Have you read the discussion? I've pointed out that the fault does not lie with bdist_wheel but distutils. Do you have any suggestions to give?

agronholm avatar May 20 '19 11:05 agronholm

Thanks, I have been investigating the best way to do it. I found this https://github.com/dave-shawley/setupext-janitor, but this seems like overkill. I don't know if this is a good way to do it, but in my setup.py, I have done this:

setup_requirements = ['pytest-runner']

def setup_requires():
    rmtree(script_dir_plus_file('build', setup_requires), ignore_errors=True)
    return setup_requirements

setup(
...
    setup_requires=setup_requires(),
...)

script_dir_plus_file is defined as follows:

def script_dir(pyobject, follow_symlinks=True):
    """Get current script's directory

    Args:
        pyobject (Any): Any Python object in the script
        follow_symlinks (bool): Follow symlinks or not. Defaults to True.

    Returns:
        str: Current script's directory
    """
    if getattr(sys, 'frozen', False):  # py2exe, PyInstaller, cx_Freeze
        path = abspath(sys.executable)
    else:
        path = inspect.getabsfile(pyobject)
    if follow_symlinks:
        path = realpath(path)
    return dirname(path)


def script_dir_plus_file(filename, pyobject, follow_symlinks=True):
    """Get current script's directory and then append a filename

    Args:
        filename (str): Filename to append to directory path
        pyobject (Any): Any Python object in the script
        follow_symlinks (bool): Follow symlinks or not. Defaults to True.

    Returns:
        str: Current script's directory and with filename appended
    """
    return join(script_dir(pyobject, follow_symlinks), filename)

mcarans avatar May 20 '19 11:05 mcarans

Is running self.run_command("clean") at the start of bdist_wheel, not a complete solution here?

pradyunsg avatar Jan 25 '22 18:01 pradyunsg

The name of the issue suggests that bdist_wheel leaves temporary files behind which is not true. Again, this needs to be solved in setuptools (which now CAN solve the problem due to vendoring distutils).

agronholm avatar Jan 25 '22 20:01 agronholm

Related: https://github.com/pypa/setuptools/issues/1871

mhsmith avatar Jan 23 '23 12:01 mhsmith