Skip to content

Commit 4db3c4a

Browse files
committed
Starting with small Windows fixes.
Starting working on Windows support. Git seems to behave a bit differently on Windows. Git always shows Unix paths in its output even on Windows. Handling. Fixed badge in README. Forgot to update it when switching to Codecov.
1 parent 85e409c commit 4db3c4a

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Sphinx extension that allows building versioned docs for self-hosting.
1212
:target: https://travis-ci.org/Robpol86/sphinxcontrib-versioning
1313
:alt: Build Status
1414

15-
.. image:: https://img.shields.io/coveralls/Robpol86/sphinxcontrib-versioning/master.svg?style=flat-square&label=Coveralls
16-
:target: https://coveralls.io/github/Robpol86/sphinxcontrib-versioning
15+
.. image:: https://img.shields.io/codecov/c/github/Robpol86/sphinxcontrib-versioning/master.svg?style=flat-square&label=Codecov
16+
:target: https://codecov.io/gh/Robpol86/sphinxcontrib-versioning
1717
:alt: Coverage Status
1818

1919
.. image:: https://img.shields.io/pypi/v/sphinxcontrib-versioning.svg?style=flat-square&label=Latest

sphinxcontrib/versioning/git.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import os
77
import re
88
import shutil
9+
import sys
910
from datetime import datetime
1011
from subprocess import CalledProcessError, PIPE, Popen, STDOUT
1112

1213
from sphinxcontrib.versioning.lib import TempDir
1314

14-
RE_ALL_REMOTES = re.compile(r'([\w./-]+)\t([A-Za-z0-9@:/._-]+) \((fetch|push)\)\n')
15+
IS_WINDOWS = sys.platform == 'win32'
16+
RE_ALL_REMOTES = re.compile(r'([\w./-]+)\t([A-Za-z0-9@:/\\._-]+) \((fetch|push)\)\n')
1517
RE_REMOTE = re.compile(r'^(?P<sha>[0-9a-f]{5,40})\trefs/(?P<kind>heads|tags)/(?P<name>[\w./-]+(?:\^\{})?)$',
1618
re.MULTILINE)
1719
RE_UNIX_TIME = re.compile(r'^\d{10}$', re.MULTILINE)
@@ -118,7 +120,7 @@ def run_command(local_root, command, env_var=True, piped=None):
118120
119121
:param str local_root: Local path to git root directory.
120122
:param iter command: Command to run.
121-
:param bool env_var: Define GIT_DIR environment variable.
123+
:param bool env_var: Define GIT_DIR environment variable (on non-Windows).
122124
:param iter piped: Second command to pipe its stdout to `command`'s stdin.
123125
124126
:return: Command output.
@@ -128,7 +130,7 @@ def run_command(local_root, command, env_var=True, piped=None):
128130

129131
# Setup env.
130132
env = os.environ.copy()
131-
if env_var:
133+
if env_var and not IS_WINDOWS:
132134
env['GIT_DIR'] = os.path.join(local_root, '.git')
133135
else:
134136
env.pop('GIT_DIR', None)
@@ -174,6 +176,8 @@ def get_root(directory):
174176
output = run_command(directory, command, env_var=False)
175177
except CalledProcessError as exc:
176178
raise GitError('Failed to find local git repository root in {}.'.format(repr(directory)), exc.output)
179+
if IS_WINDOWS:
180+
output = output.replace('/', '\\')
177181
return output.strip()
178182

179183

@@ -395,7 +399,7 @@ def commit_and_push(local_root, remote, versions):
395399
for status, name in (l.split('\t', 1) for l in output.splitlines()):
396400
if status != 'M':
397401
break # Only looking for modified files.
398-
components = name.split(os.sep)
402+
components = name.split('/')
399403
if '.doctrees' not in components and components[-1] != 'searchindex.js':
400404
break # Something other than those two dirs/files has changed.
401405
else:

tests/test_git/test_clone.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Test function in module."""
22

3+
from os.path import join
34
from subprocess import CalledProcessError
45

56
import pytest
67

7-
from sphinxcontrib.versioning.git import clone, GitError
8+
from sphinxcontrib.versioning.git import clone, GitError, IS_WINDOWS
89

910

1011
def test_no_exclude(tmpdir, local_docs, run):
@@ -45,7 +46,7 @@ def test_exclude(tmpdir, local, run):
4546
# Run.
4647
exclude = [
4748
'.travis.yml', 'appveyor.yml', # Ignored (nonexistent), show warnings.
48-
'README', 'two.txt', 'sub/four.txt', # Only leave these.
49+
'README', 'two.txt', join('sub', 'four.txt'), # Only leave these.
4950
]
5051
new_root = tmpdir.ensure_dir('new_root')
5152
clone(str(local), str(new_root), 'origin', 'feature', '.', exclude)
@@ -56,7 +57,7 @@ def test_exclude(tmpdir, local, run):
5657
assert new_root.join('sub', 'four.txt').read() == 'four'
5758
assert new_root.join('two.txt').read() == 'two'
5859
paths = sorted(f.relto(new_root) for f in new_root.visit() if new_root.join('.git') not in f.parts())
59-
assert paths == ['README', 'sub', 'sub/four.txt', 'two.txt']
60+
assert paths == ['README', 'sub', join('sub', 'four.txt'), 'two.txt']
6061

6162
# Verify original repo state.
6263
run(local, ['git', 'diff-index', '--quiet', 'HEAD', '--']) # Verify unchanged.
@@ -88,7 +89,7 @@ def test_exclude_subdir(tmpdir, local, run):
8889
new_root = tmpdir.ensure_dir('new_root')
8990
clone(str(local), str(new_root), 'origin', 'master', 'sub', ['three.txt'])
9091
paths = sorted(f.relto(new_root) for f in new_root.visit() if new_root.join('.git') not in f.parts())
91-
assert paths == ['README', 'sub', 'sub/three.txt']
92+
assert paths == ['README', 'sub', join('sub', 'three.txt')]
9293

9394
status = run(new_root, ['git', 'status', '--porcelain'])
9495
assert status == 'D sub/four.txt\n'
@@ -112,9 +113,9 @@ def test_exclude_patterns(tmpdir, local, run):
112113
run(local, ['git', 'push', 'origin', 'master'])
113114

114115
new_root = tmpdir.ensure_dir('new_root')
115-
clone(str(local), str(new_root), 'origin', 'master', '.', ['*.md', '*/*.md'])
116+
clone(str(local), str(new_root), 'origin', 'master', '.', ['*.md', join('*', '*.md')])
116117
paths = sorted(f.relto(new_root) for f in new_root.visit() if new_root.join('.git') not in f.parts())
117-
assert paths == ['one.md', 'six.md', 'sub', 'sub/five.md', 'sub/four.md']
118+
assert paths == ['one.md', 'six.md', 'sub', join('sub', 'five.md'), join('sub', 'four.md')]
118119

119120
status = run(new_root, ['git', 'status', '--porcelain'])
120121
assert status == 'D README\nD sub/three.txt\nD two.txt\n'
@@ -165,8 +166,11 @@ def test_bad_branch_rel_dest_exclude(tmpdir, local, run):
165166
# Bad remote.
166167
run(local, ['git', 'remote', 'add', 'origin', local.join('does_not_exist')])
167168
with pytest.raises(GitError) as exc:
168-
clone(str(local), str(tmpdir.ensure_dir('new_root3')), 'origin', 'master', '.', None)
169-
assert "repository '{}' does not exist".format(local.join('does_not_exist')) in exc.value.output
169+
clone(str(local), str(tmpdir.ensure_dir('new_root4')), 'origin', 'master', '.', None)
170+
if IS_WINDOWS:
171+
assert "'{}' does not appear to be a git repository".format(local.join('does_not_exist')) in exc.value.output
172+
else:
173+
assert "repository '{}' does not exist".format(local.join('does_not_exist')) in exc.value.output
170174

171175

172176
def test_multiple_remotes(tmpdir, local, remote, run):

tests/test_git/test_commit_and_push.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def test_changes(monkeypatch, local, run):
9898
:param local: conftest fixture.
9999
:param run: conftest fixture.
100100
"""
101+
monkeypatch.setenv('LANG', 'en_US.UTF-8')
101102
monkeypatch.setenv('TRAVIS_BUILD_ID', '12345')
102103
monkeypatch.setenv('TRAVIS_BRANCH', 'master')
103104
old_sha = run(local, ['git', 'rev-parse', 'HEAD']).strip()

0 commit comments

Comments
 (0)