Skip to content

Commit

Permalink
Fixed bdist_wheel failing on a read-only source tree
Browse files Browse the repository at this point in the history
Fixes #327.
  • Loading branch information
agronholm committed Jan 22, 2020
1 parent 9aa8480 commit 41fcf34
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Release Notes
- Updated project packaging and testing configuration for :pep:`517`
- Moved the contents of setup.py to setup.cfg
- Fixed duplicate RECORD file when using "wheel pack" on Windows
- Fixed bdist_wheel failing at cleanup on Windows with a read-only source tree
- Switched the project to use the "src" layout
. Switched to setuptools_scm_ for versioning
- Switched to setuptools_scm_ for versioning

.. _setuptools_scm: https://github.com/pypa/setuptools_scm/

Expand Down
9 changes: 8 additions & 1 deletion src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import shutil
import stat
import sys
import re
from email.generator import Generator
Expand Down Expand Up @@ -40,6 +41,12 @@ def safer_version(version):
return safe_version(version).replace('-', '_')


def remove_readonly(func, path, excinfo):
print(str(excinfo[1]))
os.chmod(path, stat.S_IWRITE)
func(path)


class bdist_wheel(Command):

description = 'create a wheel distribution'
Expand Down Expand Up @@ -267,7 +274,7 @@ def run(self):
if not self.keep_temp:
logger.info('removing %s', self.bdist_dir)
if not self.dry_run:
rmtree(self.bdist_dir)
rmtree(self.bdist_dir, onerror=remove_readonly)

def write_wheelfile(self, wheelfile_base, generator='bdist_wheel (' + wheel_version + ')'):
from email.message import Message
Expand Down
19 changes: 17 additions & 2 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding: utf-8
import os
import os.path
import shutil
import stat
import subprocess
import sys
from zipfile import ZipFile
Expand All @@ -20,7 +22,7 @@
}


@pytest.fixture(scope='module')
@pytest.fixture
def dummy_dist(tmpdir_factory):
basedir = tmpdir_factory.mktemp('dummy_dist')
basedir.join('setup.py').write("""\
Expand Down Expand Up @@ -113,3 +115,16 @@ def test_limited_abi(monkeypatch, tmpdir):
monkeypatch.chdir(source_dir)
subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel', '-b', str(build_dir),
'-d', str(dist_dir)])


def test_build_from_readonly_tree(dummy_dist, monkeypatch, tmpdir):
basedir = str(tmpdir.join('dummy'))
shutil.copytree(str(dummy_dist), basedir)
monkeypatch.chdir(basedir)

# Make the tree read-only
for root, dirs, files in os.walk(basedir):
for fname in files:
os.chmod(os.path.join(root, fname), stat.S_IREAD)

subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel'])

0 comments on commit 41fcf34

Please sign in to comment.