ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.136 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/alt/python37/lib/python3.7/site-packages/setuptools_scm/ |
Upload File : |
import os
import subprocess
import tarfile
import logging
from .file_finder import scm_find_files
from .utils import trace
log = logging.getLogger(__name__)
def _git_toplevel(path):
try:
with open(os.devnull, "wb") as devnull:
out = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"],
cwd=(path or "."),
universal_newlines=True,
stderr=devnull,
)
trace("find files toplevel", out)
return os.path.normcase(os.path.realpath(out.strip()))
except subprocess.CalledProcessError:
# git returned error, we are not in a git repo
return None
except OSError:
# git command not found, probably
return None
def _git_interpret_archive(fd, toplevel):
tf = tarfile.open(fileobj=fd, mode="r|*")
git_files = set()
git_dirs = {toplevel}
for member in tf.getmembers():
name = os.path.normcase(member.name).replace("/", os.path.sep)
if member.type == tarfile.DIRTYPE:
git_dirs.add(name)
else:
git_files.add(name)
return git_files, git_dirs
def _git_ls_files_and_dirs(toplevel):
# use git archive instead of git ls-file to honor
# export-ignore git attribute
cmd = ["git", "archive", "--prefix", toplevel + os.path.sep, "HEAD"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=toplevel)
try:
return _git_interpret_archive(proc.stdout, toplevel)
except Exception:
if proc.wait() != 0:
log.exception("listing git files failed - pretending there aren't any")
return (), ()
def git_find_files(path=""):
toplevel = _git_toplevel(path)
if not toplevel:
return []
git_files, git_dirs = _git_ls_files_and_dirs(toplevel)
return scm_find_files(path, git_files, git_dirs)