Skip to content

Commit fec88fa

Browse files
committed
Handling Windows newlines.
Handling Windows newlines in regex in linters. Was working in AppVeyor but not my Win10 VM. Handling read only permissions on Windows with shutil.rmtree. Fixing pylint on Windows with __import__(). Handling Windows newlines in tests.
1 parent 351fdd3 commit fec88fa

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ def run(cls):
6060
if getattr(project, var) != expected:
6161
raise SystemExit('Mismatch: {0}'.format(var))
6262
# Check changelog.
63-
if not re.compile(r'^%s - \d{4}-\d{2}-\d{2}$' % VERSION, re.MULTILINE).search(readme()):
63+
if not re.compile(r'^%s - \d{4}-\d{2}-\d{2}[\r\n]' % VERSION, re.MULTILINE).search(readme()):
6464
raise SystemExit('Version not found in readme/changelog file.')
6565
# Check tox.
6666
if INSTALL_REQUIRES:
67-
section = re.compile(r'\ninstall_requires =\n(.+?)\n\w', re.DOTALL).findall(readme('tox.ini'))
67+
contents = readme('tox.ini')
68+
section = re.compile(r'[\r\n]+install_requires =[\r\n]+(.+?)[\r\n]+\w', re.DOTALL).findall(contents)
6869
if not section:
6970
raise SystemExit('Missing install_requires section in tox.ini.')
7071
in_tox = re.findall(r' ([^=]+)==[\w\d.-]+', section[0])

sphinxcontrib/versioning/lib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import atexit
44
import functools
55
import logging
6+
import os
67
import shutil
78
import tempfile
89
import weakref
@@ -163,4 +164,6 @@ def __exit__(self, *_):
163164

164165
def cleanup(self):
165166
"""Recursively delete directory."""
166-
shutil.rmtree(self.name)
167+
shutil.rmtree(self.name, onerror=lambda *a: os.chmod(a[1], __import__('stat').S_IWRITE) or os.unlink(a[1]))
168+
if os.path.exists(self.name):
169+
raise IOError(17, "File exists: '{}'".format(self.name))

sphinxcontrib/versioning/versions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Collect and sort version strings."""
22

3-
import posixpath
43
import re
54

65
RE_SEMVER = re.compile(r'^v?V?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?([\w.+-]*)$')
@@ -239,4 +238,4 @@ def vpathto(self, other_version):
239238
components = ['..'] * pagename.count('/')
240239
components += [other_root_dir] if is_root else ['..', other_root_dir]
241240
components += [pagename if self.vhasdoc(other_version) else other_remote['master_doc']]
242-
return '{}.html'.format(posixpath.join(*components))
241+
return '{}.html'.format(__import__('posixpath').join(*components))

tests/test__main__/test_main_build_scenarios.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pytest
77

8+
from sphinxcontrib.versioning.git import IS_WINDOWS
9+
810

911
def test_sub_page_and_tag(tmpdir, local_docs, run, urls):
1012
"""Test with sub pages and one git tag. Testing from local git repo.
@@ -282,7 +284,7 @@ def test_root_ref(tmpdir, local_docs, run, no_tags):
282284
else:
283285
assert 'No git tags with docs found in remote. Falling back to --root-ref value.' not in output
284286
# Check output.
285-
assert 'Root ref is: {}\n'.format(expected) in output
287+
assert 'Root ref is: {}'.format(expected) in output
286288

287289

288290
@pytest.mark.parametrize('parallel', [False, True])
@@ -295,6 +297,8 @@ def test_add_remove_docs(tmpdir, local_docs, run, urls, parallel):
295297
:param urls: conftest fixture.
296298
:param bool parallel: Run sphinx-build with -j option.
297299
"""
300+
if parallel and IS_WINDOWS:
301+
return pytest.skip('Sphinx parallel feature not available on Windows.')
298302
run(local_docs, ['git', 'tag', 'v1.0.0'])
299303

300304
# Move once.
@@ -544,8 +548,8 @@ def test_whitelisting(local_docs, run, urls):
544548
assert 'Traceback' not in output
545549

546550
# Check output.
547-
assert 'With docs: ignored included master v1.0 v1.0-dev\n' in output
548-
assert 'Passed whitelisting: included master v1.0\n' in output
551+
assert 'With docs: ignored included master v1.0 v1.0-dev' in output
552+
assert 'Passed whitelisting: included master v1.0' in output
549553

550554
# Check root.
551555
urls(local_docs.join('html', 'contents.html'), [
@@ -639,12 +643,12 @@ def test_error_bad_path(tmpdir, run):
639643
"""
640644
with pytest.raises(CalledProcessError) as exc:
641645
run(tmpdir, ['sphinx-versioning', '-N', '-c', 'unknown', 'build', '.', str(tmpdir)])
642-
assert 'Directory "unknown" does not exist.\n' in exc.value.output
646+
assert 'Directory "unknown" does not exist.' in exc.value.output
643647

644648
tmpdir.ensure('is_file')
645649
with pytest.raises(CalledProcessError) as exc:
646650
run(tmpdir, ['sphinx-versioning', '-N', '-c', 'is_file', 'build', '.', str(tmpdir)])
647-
assert 'Directory "is_file" is a file.\n' in exc.value.output
651+
assert 'Directory "is_file" is a file.' in exc.value.output
648652

649653
with pytest.raises(CalledProcessError) as exc:
650654
run(tmpdir, ['sphinx-versioning', '-N', 'build', '.', str(tmpdir)])
@@ -667,7 +671,7 @@ def test_error_no_docs_found(tmpdir, local, run):
667671
"""
668672
with pytest.raises(CalledProcessError) as exc:
669673
run(local, ['sphinx-versioning', '-N', '-v', 'build', '.', str(tmpdir)])
670-
assert 'No docs found in any remote branch/tag. Nothing to do.\n' in exc.value.output
674+
assert 'No docs found in any remote branch/tag. Nothing to do.' in exc.value.output
671675

672676

673677
def test_error_bad_root_ref(tmpdir, local_docs, run):
@@ -679,4 +683,4 @@ def test_error_bad_root_ref(tmpdir, local_docs, run):
679683
"""
680684
with pytest.raises(CalledProcessError) as exc:
681685
run(local_docs, ['sphinx-versioning', '-N', '-v', 'build', '.', str(tmpdir), '-r', 'unknown'])
682-
assert 'Root ref unknown not found in: master\n' in exc.value.output
686+
assert 'Root ref unknown not found in: master' in exc.value.output

tests/test__main__/test_main_push_scenarios.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_root_ref(local_docs_ghp, run):
102102
assert 'Failed to push to remote repository.' not in output
103103

104104
# Check output.
105-
assert 'Root ref is: v1.0.0\n' in output
105+
assert 'Root ref is: v1.0.0' in output
106106

107107

108108
@pytest.mark.parametrize('give_up', [False, True])
@@ -129,7 +129,7 @@ def test_race(tmpdir, local_docs_ghp, remote, run, urls, give_up):
129129
proc = Popen(command, cwd=str(local_docs_ghp), env=env, stdout=PIPE, stderr=STDOUT)
130130
for line in iter(proc.stdout.readline, b''):
131131
output_lines.append(line)
132-
if line == b'=> Building docs...\n':
132+
if line.strip() == b'=> Building docs...':
133133
if give_up or not caused:
134134
# Cause race condition.
135135
local_other.join('README').write('changed', mode='a')
@@ -307,7 +307,7 @@ def test_error_build_failure(local_docs_ghp, run):
307307
assert "name 'undefined' is not defined" in exc.value.output
308308
assert 'Building docs...' in exc.value.output
309309
assert 'sphinx-build failed for branch/tag: master' in exc.value.output
310-
assert exc.value.output.endswith('Failure.\n')
310+
assert exc.value.output.strip().endswith('Failure.')
311311

312312

313313
def test_bad_git_config(local_docs_ghp, run):

0 commit comments

Comments
 (0)