docstr: Returns a class that can be used as a replacement for the
  ``sdist`` command in ``setuptools`` and that will clean up
  ``vendor/source/igraph`` before running the original ``sdist``
  command.
docstr_tok: ["Returns","a","class","that","can","be","used","as","a","replacement","for","the","``","sdist","``","command","in","``","setuptools","``","and","that","will","clean","up","``","vendor\/source\/igraph","``","before","running","the","original","``","sdist","``","command","."]
code: def sdist(self):
      """Returns a class that can be used as a replacement for the
      ``sdist`` command in ``setuptools`` and that will clean up
      ``vendor/source/igraph`` before running the original ``sdist``
      command.
      """
      from setuptools.command.sdist import sdist
  
      def is_git_repo(folder) -> bool:
          return (Path(folder) / ".git").exists()
  
      def cleanup_git_repo(folder) -> None:
          with working_directory(folder):
              if os.path.exists(".git"):
                  retcode = subprocess.call(
                      "git clean -dfx", shell=True
                  )
                  if retcode:
                      raise RuntimeError(
                          f"Failed to clean {folder} with git"
                      )
  
      class custom_sdist(sdist):
          def run(self):
              igraph_source_repo = Path("vendor", "source", "igraph")
              igraph_build_dir = Path("vendor", "build", "igraph")
              version_file = igraph_source_repo / "IGRAPH_VERSION"
              version = None
  
              # Check whether the source repo contains an IGRAPH_VERSION file,
              # and extract the version number from that
              if version_file.exists():
                  version = (
                      version_file.read_text().strip().split("\n")[0]
                  )
  
              # If no IGRAPH_VERSION file exists, but we have a git repo, try
              # git describe
              if not version and is_git_repo(igraph_source_repo):
                  with working_directory(igraph_source_repo):
                      version = (
                          subprocess.check_output(
                              "git describe", shell=True
                          )
                          .decode("utf-8")
                          .strip()
                      )
  
              # If we still don't have a version number, try to parse it from
              # include/igraph_version.h
              if not version:
                  version_header = (
                      igraph_build_dir / "include" / "igraph_version.h"
                  )
                  if not version_header.exists():
                      raise RuntimeError(
                          "You need to build the C core of igraph first before generating a source tarball of the Python interface of igraph"
                      )
  
                  with version_header.open("r") as fp:
                      lines = [
                          line.strip()
                          for line in fp
                          if line.startswith("#define IGRAPH_VERSION ")
                      ]
                      if len(lines) == 1:
                          version = lines[0].split('"')[1]
  
              if not isinstance(version, str) or len(version) < 5:
                  raise RuntimeError(
                      f"Cannot determine the version number of the C core in {igraph_source_repo}"
                  )
  
              if not is_git_repo(igraph_source_repo):
                  # The Python interface was extracted from an official
                  # tarball so there is no need to tweak anything
                  return sdist.run(self)
              else:
                  # Clean up vendor/source/igraph with git
                  cleanup_git_repo(igraph_source_repo)
  
                  # Copy the generated parser sources from the build folder
                  parser_dir = (
                      igraph_build_dir / "src" / "io" / "parsers"
                  )
                  if parser_dir.is_dir():
                      shutil.copytree(
                          parser_dir,
                          igraph_source_repo / "src" / "io" / "parsers",
                      )
                  else:
                      raise RuntimeError(
                          "You need to build the C core of igraph first before "
                          "generating a source tarball of the Python interface"
                      )
  
                  # Add a version file to the tarball
                  version_file.write_text(version)
  
                  # Run the original sdist command
                  retval = sdist.run(self)
  
                  # Clean up vendor/source/igraph with git again
                  cleanup_git_repo(igraph_source_repo)
  
                  return retval
  
      return custom_sdist
  
imports: import os
  import platform
  import sys
  from setuptools import find_packages, setup, Command, Extension
  import glob
  import shlex
  import shutil
  import subprocess
  import sysconfig
  from contextlib import contextmanager
  from pathlib import Path
  from select import select
  from shutil import which
  from time import sleep
  from typing import List, Iterable, Iterator, Optional, Tuple, TypeVar, Union
label_desc: Use image node_id 5 for calling the BuildConfiguration obj's underlying member method code with example usage: obj.sdist() and returns: custom_sdist, unknown, sdist, retval