From 228adaa287517015a5ec86d36fbd60b4bb031a31 Mon Sep 17 00:00:00 2001 From: Alexandre Foley Date: Mon, 5 Dec 2016 17:25:36 -0500 Subject: =?UTF-8?q?Wrap.py:=20Made=20it=20so=20using=20an=20already=20down?= =?UTF-8?q?loaded=20subproject=20is=20only=20for=20the=20wrap-file=20case.?= =?UTF-8?q?=20Git=20and=20Mercurial=20can=20update=20the=20repository=20if?= =?UTF-8?q?=20it=20the=20wrap=20is=20one.=20Also=20did=20a=20bit=20of=20cl?= =?UTF-8?q?eanup.=20interpreter.py:=20There=E2=80=99s=20a=20catch=20all=20?= =?UTF-8?q?except=20clause=20at=20the=20line=201928,=20it=20didn=E2=80=99t?= =?UTF-8?q?=20give=20the=20user=20any=20information=20whatsoever=20about?= =?UTF-8?q?=20the=20exception=20it=20caught.=20Now=20it=20at=20least=20pri?= =?UTF-8?q?nt=20it=20to=20the=20log=20as=20a=20warning.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mesonbuild/wrap/wrap.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'mesonbuild/wrap/wrap.py') diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 37d6df7..1ebff3c 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -94,13 +94,10 @@ class Resolver: fname = os.path.join(self.subdir_root, packagename + '.wrap') dirname = os.path.join(self.subdir_root, packagename) try: - if os.listdir(dirname): - # The directory is there and not empty? Great, use it. - return packagename - else: - mlog.warning('Subproject directory %s is empty, possibly because of an unfinished' - 'checkout, removing to reclone' % dirname) - os.rmdir(checkoutdir) + if not os.listdir(dirname): + mlog.warning('Subproject directory %s is empty, removing to' + ' ensure clean download' % dirname) + os.rmdir(dirname) except NotADirectoryError: raise RuntimeError('%s is not a directory, can not use as subproject.' % dirname) except FileNotFoundError: @@ -111,6 +108,11 @@ class Resolver: return None p = PackageDefinition(fname) if p.type == 'file': + if os.path.isdir(dirname): + # project already there? great, use it! + # only for the file case because otherwise we prevent git + # and hg from updating the subproject. or doing that fancy git push feature that doesn't belong + return packagename if not os.path.isdir(self.cachedir): os.mkdir(self.cachedir) self.download(p, packagename) @@ -130,12 +132,11 @@ class Resolver: if is_there: try: subprocess.check_call(['git', 'rev-parse']) - is_there = True except subprocess.CalledProcessError: raise RuntimeError('%s is not empty but is not a valid ' 'git repository, we can not work with it' - ' as a subproject directory.' % ( - checkoutdir)) + ' as a subproject directory.' + % (checkoutdir)) if revno.lower() == 'head': # Failure to do pull is not a fatal error, @@ -163,12 +164,16 @@ class Resolver: revno = p.get('revision') is_there = os.path.isdir(checkoutdir) if is_there: + #Need to add a check that the directory is a valid HG repo if revno.lower() == 'tip': # Failure to do pull is not a fatal error, # because otherwise you can't develop without # a working net connection. subprocess.call(['hg', 'pull'], cwd=checkoutdir) + subprocess.call(['hg','update','tip'],cwd = checkoutdir) else: + #check that the tag/branch/revision we want is available in the + # repo, if not, pull and update. if subprocess.call(['hg', 'checkout', revno], cwd=checkoutdir) != 0: subprocess.check_call(['hg', 'pull'], cwd=checkoutdir) subprocess.check_call(['hg', 'checkout', revno], -- cgit v1.1 From 61d5934e63af65536cd22ef16127b4920c21c4f3 Mon Sep 17 00:00:00 2001 From: Alexandre Foley Date: Tue, 6 Dec 2016 09:45:20 -0500 Subject: Added a few missing whitespace as noted by Ignatenkobrain. Replaced a comment by the piece of code it said was needed. --- mesonbuild/wrap/wrap.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'mesonbuild/wrap/wrap.py') diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 1ebff3c..57c7353 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -99,7 +99,7 @@ class Resolver: ' ensure clean download' % dirname) os.rmdir(dirname) except NotADirectoryError: - raise RuntimeError('%s is not a directory, can not use as subproject.' % dirname) + raise RuntimeError('%s is not a directory, can not use as subproject.' %dirname) except FileNotFoundError: pass @@ -111,7 +111,7 @@ class Resolver: if os.path.isdir(dirname): # project already there? great, use it! # only for the file case because otherwise we prevent git - # and hg from updating the subproject. or doing that fancy git push feature that doesn't belong + # and hg from updating the subproject. return packagename if not os.path.isdir(self.cachedir): os.mkdir(self.cachedir) @@ -164,15 +164,16 @@ class Resolver: revno = p.get('revision') is_there = os.path.isdir(checkoutdir) if is_there: - #Need to add a check that the directory is a valid HG repo + if not os.path.isdir(os.path.join(checkoutdir, '.hg')): + raise RuntimeError('Subproject %s is not a valid mercurial repo.'%p.get('directory')) if revno.lower() == 'tip': # Failure to do pull is not a fatal error, # because otherwise you can't develop without # a working net connection. subprocess.call(['hg', 'pull'], cwd=checkoutdir) - subprocess.call(['hg','update','tip'],cwd = checkoutdir) + subprocess.call(['hg', 'update', 'tip'],cwd = checkoutdir) else: - #check that the tag/branch/revision we want is available in the + # check that the tag/branch/revision we want is available in the # repo, if not, pull and update. if subprocess.call(['hg', 'checkout', revno], cwd=checkoutdir) != 0: subprocess.check_call(['hg', 'pull'], cwd=checkoutdir) -- cgit v1.1 From 27cd8c1e28f310891fa671976a0f3b4231ceb4b0 Mon Sep 17 00:00:00 2001 From: Alexandre Foley Date: Tue, 6 Dec 2016 12:32:39 -0500 Subject: =?UTF-8?q?The=20=E2=80=9Cdirectory=20present=20and=20not=20empty?= =?UTF-8?q?=E2=80=9D=20return=20condition=20was=20necessary=20for=20subpro?= =?UTF-8?q?ject=20to=20work=20without=20a=20wrap=20file.=20Put=20it=20back?= =?UTF-8?q?=20with=20that=20added=20condition=20that=20there=20mustn?= =?UTF-8?q?=E2=80=99t=20be=20a=20wrap=20file=20present=20for=20returning?= =?UTF-8?q?=20the=20package=20immediately.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mesonbuild/wrap/wrap.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mesonbuild/wrap/wrap.py') diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 57c7353..12536fe 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -94,7 +94,12 @@ class Resolver: fname = os.path.join(self.subdir_root, packagename + '.wrap') dirname = os.path.join(self.subdir_root, packagename) try: - if not os.listdir(dirname): + if os.listdir(dirname): + if not os.path.isfile(fname) : + # The directory is there, not empty and there isn't a wrap file? + # Great, use it. + return packagename + else: mlog.warning('Subproject directory %s is empty, removing to' ' ensure clean download' % dirname) os.rmdir(dirname) -- cgit v1.1