Open mithro opened 8 years ago
@mithro Do you want to fix this, and thoroughly test that you have not broken anything? setuptools is brimming with ridiculous design flaws, and doing seemingly simple things like this often means opening a whole can of worms.
This is the code I came up with for litex's setup.py to check this.
def check_submodules(basedir):
try:
modules = open(os.path.join(basedir, ".gitmodules")).read()
except FileNotFoundError as e:
return []
submodule_errors = []
for line in modules.splitlines():
match = re.search("path = (.+)", line)
if not match:
continue
modulepath = match.groups()[0]
fullpath = os.path.normpath(os.path.join(basedir, modulepath))
assert os.path.exists(fullpath)
assert os.path.isdir(fullpath)
if not os.path.exists(os.path.join(fullpath, ".git")):
submodule_errors.append(fullpath)
continue
submodule_errors += check_submodules(fullpath)
return submodule_errors
if sys.version_info[:3] < (3, 3):
raise SystemExit("You need Python 3.3+")
submodule_errors = check_submodules(os.path.dirname(__file__))
if submodule_errors:
raise SystemExit("""\
The following git submodules are not initialized:{}
Please run:
git submodule update --recursive --init
git submodule foreach git submodule update --recursive --init
""".format("\n * ".join([""]+submodule_errors)))
Do you think something similar would be suitable for misoc?
Parsing .gitmodules
is fragile (when done like that) and complicated. How about checking the output of git submodule status
? It will even tell you directly if the submodule is initialized.
I would say it is not especially fragile if fixed to ignore whitespace, and take end-of-line/beginning-of-line into account. I.e. r"^\w*path\w*=\w*(.+)"
, since that captures the actual grammar used by git.
I think launching a subprocess (and parsing its output) is likely to be more fragile than parsing the .gitmodule
files but happy to do which ever version you prefer.
I forgot to init the submodules when cloning misoc. Running
python setup.py install
worked fine but I later got an error like the following when trying to build;Running
git submodule update --init
in the misoc directory and thenpython setup.py install
again fixed the problem.python setup.py install
should probably complain if it can't find the needed files from submodules.