summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaveen M K <naveen@syrusdark.website>2021-02-09 14:08:20 +0530
committerGitHub <noreply@github.com>2021-02-09 09:38:20 +0100
commitb8451688b9cb295136c0154c7c59c25a9d88f844 (patch)
tree76529b80be291f6bff52bf7d0ddf4024075e0a9f
parent74b17470912c83e658cfd18e66eec654be87fcd7 (diff)
downloadsetuptools-scm-b8451688b9cb295136c0154c7c59c25a9d88f844.tar.gz
Use show prefix instead of show toplevel for finding (#520)
this takes the idea from https://github.com/msys2/MINGW-packages/blob/bf4d6f85053b66db09977ecffac0c1b3db735a0f/mingw-w64-python-setuptools-scm/0001-git-Use-show-prefix-instead-of-show-toplevel-for-fin.patch and simplified the logic additionally msys2 testing is added Fixes https://github.com/pypa/setuptools_scm/issues/415
-rw-r--r--.github/workflows/python-tests.yml12
-rw-r--r--src/setuptools_scm/file_finder_git.py18
-rw-r--r--src/setuptools_scm/git.py13
3 files changed, 39 insertions, 4 deletions
diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml
index ec2390b..4963733 100644
--- a/.github/workflows/python-tests.yml
+++ b/.github/workflows/python-tests.yml
@@ -23,13 +23,15 @@ jobs:
include:
- os: ubuntu-latest
python_version: '3.9-dev'
+ - os: windows-latest
+ python_version: 'msys2'
name: ${{ matrix.os }} - Python ${{ matrix.python_version }}
steps:
- uses: actions/checkout@v1
- name: Setup python
uses: actions/setup-python@v2
- if: matrix.python_version != '3.9-dev'
+ if: matrix.python_version != '3.9-dev' && matrix.python_version != 'msys2'
with:
python-version: ${{ matrix.python_version }}
architecture: x64
@@ -39,7 +41,15 @@ jobs:
with:
python-version: ${{ matrix.python_version }}
architecture: x64
+ - name: Setup MSYS2
+ uses: msys2/setup-msys2@v2
+ if: matrix.python_version == 'msys2'
+ with:
+ msystem: MINGW64
+ install: git mingw-w64-x86_64-python mingw-w64-x86_64-python-setuptools
+ update: true
- run: pip install -U setuptools
+ if: matrix.python_version != 'msys2'
- run: pip install -e .[toml] pytest
- run: pytest
diff --git a/src/setuptools_scm/file_finder_git.py b/src/setuptools_scm/file_finder_git.py
index 1d3e69b..fbaf07c 100644
--- a/src/setuptools_scm/file_finder_git.py
+++ b/src/setuptools_scm/file_finder_git.py
@@ -11,13 +11,27 @@ log = logging.getLogger(__name__)
def _git_toplevel(path):
try:
+ cwd = os.path.abspath(path or ".")
with open(os.devnull, "wb") as devnull:
out = subprocess.check_output(
- ["git", "rev-parse", "--show-toplevel"],
- cwd=(path or "."),
+ ["git", "rev-parse", "--show-prefix"],
+ cwd=cwd,
universal_newlines=True,
stderr=devnull,
)
+ out = out.strip()[:-1] # remove the trailing pathsep
+ if not out:
+ out = cwd
+ else:
+ # Here, ``out`` is a relative path to root of git.
+ # ``cwd`` is absolute path to current working directory.
+ # the below method removes the length of ``out`` from
+ # ``cwd``, which gives the git toplevel
+ assert cwd.replace("\\", "/").endswith(out)
+ # In windows cwd contains ``\`` which should be replaced by ``/``
+ # for this assertion to work. Length of string isn't changed by replace
+ # ``\\`` is just and escape for `\`
+ out = cwd[: -len(out)]
trace("find files toplevel", out)
return os.path.normcase(os.path.realpath(out.strip()))
except subprocess.CalledProcessError:
diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py
index a193f93..4bd5d15 100644
--- a/src/setuptools_scm/git.py
+++ b/src/setuptools_scm/git.py
@@ -2,6 +2,7 @@ from .config import Configuration
from .utils import do_ex, trace, require_command
from .version import meta
+import os
from os.path import isfile, join
import warnings
@@ -26,9 +27,19 @@ class GitWorkdir(object):
@classmethod
def from_potential_worktree(cls, wd):
- real_wd, _, ret = do_ex("git rev-parse --show-toplevel", wd)
+ wd = os.path.abspath(wd)
+ real_wd, _, ret = do_ex("git rev-parse --show-prefix", wd)
+ real_wd = real_wd[:-1] # remove the trailing pathsep
if ret:
return
+ if not real_wd:
+ real_wd = wd
+ else:
+ assert wd.replace("\\", "/").endswith(real_wd)
+ # In windows wd contains ``\`` which should be replaced by ``/``
+ # for this assertion to work. Length of string isn't changed by replace
+ # ``\\`` is just and escape for `\`
+ real_wd = wd[: -len(real_wd)]
trace("real root", real_wd)
if not samefile(real_wd, wd):
return