Beispiel #1
0
def get_egginfo_for(package, trunk=True, branch=False, tag=False, name="", extra_require=None):
    """ Checks out a package and returns its setup module
    """
    if (trunk and branch and tag) or (not trunk and not branch and not tag):
        raise ValueError("Excepts one and only one of trunk, branch " + "and tag to be positive")
    if branch or tag and not name:
        raise ValueError("Provide a branch/tag name")
    dir = tempfile.mkdtemp(suffix="-" + package)
    prev_cwd = os.getcwd()
    os.chdir(dir)
    egg = None
    try:
        pkg_url = PackageSourceMemory().guess_url(package)
        if trunk:
            co_url = os.path.join(pkg_url, "trunk")
        elif branch:
            co_url = os.path.join(pkg_url, "branches", name)
        elif tag:
            co_url = os.path.join(pkg_url, "tags", name)
        cmd = "svn co %s %s" % (co_url, dir)
        if runcmd_with_exitcode(cmd, log=False) != 0:
            raise Exception("Failed to checkout %s" % package)
        if not os.path.isfile("setup.py"):
            raise Exception("Could not find setup.py in checkout of %s" % package)
        egg = distutils.core.run_setup("setup.py")
    except:
        os.chdir(prev_cwd)
        shutil.rmtree(dir)
        raise
    else:
        os.chdir(prev_cwd)
        shutil.rmtree(dir)
    return egg
Beispiel #2
0
 def check_doc(self):
     if self.options.ignore_doc_errors:
         return
     output.part_title('Checking setup.py docstring (restructuredtext)')
     cmd = '%s setup.py check --restructuredtext --strict' % sys.executable
     if runcmd_with_exitcode(cmd, log=0)!=0:
         output.error('You have errors in your docstring (README.txt, HISTORY.txt, ...)'+\
                          '\nRun "ftw checkdocs" for more details.', exit=1)
Beispiel #3
0
 def get_info(self, package, force_reload=False, prompt=True):
     svn_url = PackageSourceMemory().guess_url(package, prompt=prompt)
     if not svn_url:
         return None
     data = self.get_cached_info(package)
     update = force_reload
     rev = self.get_revision_for(package)
     if not data:
         update = True
     elif rev > data["rev"]:
         update = True
     if update:
         svn.check_project_layout(svn_url)
         data = {
             "name": package,
             "tags": svn.get_existing_tags(svn_url),
             "newest_tag": "",
             "changes": False,
             "rev": rev,
             "url": svn_url,
             "history": None,
         }
         if data["tags"]:
             # find newest tag
             tags = [k for k, v in data["tags"].items()]
             tags.sort(lambda a, b: cmp(data["tags"][a], data["tags"][b]))
             tags.reverse()
             newest_tag = tags[0]
             data["newest_tag"] = newest_tag
             newest_tag_url = os.path.join(svn_url, "tags", newest_tag)
             trunk_url = os.path.join(svn_url, "trunk")
             rows = (
                 runcmd_with_exitcode(
                     "svn diff %s %s --summarize" % (trunk_url, newest_tag_url), log=False, respond=True
                 )[1]
                 .strip()
                 .split("\n")
             )
             for row in rows:
                 flag, url = re.split("\W*", row.strip(), maxsplit=1)
                 url = url.strip()
                 if (
                     url.startswith(os.path.join(trunk_url, package.replace(".", "/")))
                     and not url.endswith("version.txt")
                     and not url.endswith(".mo")
                 ):
                     data["changes"] = True
                     break
         else:
             data["changes"] = True
         self.set_cached_info(package, data)
     return data
Beispiel #4
0
    def check_description(self):
        """ Validates the restructured text of the long_description and
        included files

        """
        self.notify_part('Check the long_description')
        self.notify_check('long_description should be restructured text')
        cmd = '%s setup.py check --restructuredtext --strict' % sys.executable
        if runcmd_with_exitcode(cmd, log=0) == 0:
            self.notify(True)
        else:
            self.notify(False, 'You have restructured text errors in your long_description.',
                        'Run "ftw checkdocs" for detailed errors.', 0)
Beispiel #5
0
 def __call__(self):
     if not os.path.isfile('setup.py'):
         output.error('File not found: %s' % os.path.abspath('setup.py'),
                      exit=1)
     cmd = '%s setup.py check --restructuredtext --strict' % sys.executable
     if self.options.show:
         self.show_description()
         return
     elif self.options.browser:
         description = '\n'.join(self.get_description())
         response = open('long_description.html', 'w+')
         publish_file(writer_name='html',
                      destination=response,
                      source=StringIO(description))
         runcmd_with_exitcode('open long_description.html')
         return
     code, response, error = runcmd_with_exitcode(cmd, log=True,
                                                  respond=True,
                                                  respond_error=True)
     if code == 0:
         print '* docs okay'
     else:
         xpr = re.compile('\(line ([\d]*)\)')
         description = self.get_description()
         error = error.strip().split('\n')
         for err in error:
             print output.colorize(err, output.ERROR)
             line = xpr.search(err)
             if line:
                 line_nr = int(line.groups()[0]) - 1
                 start_line = line_nr - self.options.offrows
                 start_line = start_line > 0 and start_line or 0
                 end_line = line_nr + self.options.offrows + 1
                 end_line = end_line < len(description) and \
                     end_line or len(description)
                 line_range = range(start_line, end_line)
                 self.show_description(line_range, higlight=line_nr)
                 print ''
Beispiel #6
0
    def _validate_setup_py(self, respond=True, respond_error=True):
        """Runs the egg_info command on the ./setup.py for checking if it still
        works.

        """
        # usually run when something has changed. so lets
        # remove our cached egginfo stuff
        try:
            del self._egg_info
        except:
            pass
        cmd = '%s setup.py egg_info' % sys.executable
        return runcmd_with_exitcode(cmd, respond=respond,
                                    respond_error=respond_error)
Beispiel #7
0
 def get_history_for(self, package, tag, force_reload=False, prompt=True):
     data = self.get_info(package, force_reload, prompt)
     if not data:
         return None
     history = data.get("history", None)
     if history is not None and history.get(tag, False):
         return history[tag]
     else:
         history = {}
         svn_url = PackageSourceMemory().guess_url(package, prompt=prompt)
         subpath = tag == "trunk" and "trunk" or "tags/%s" % tag
         file_url = os.path.join(svn_url, subpath, "docs", "HISTORY.txt")
         cmd = "svn cat %s" % file_url
         history[tag] = runcmd_with_exitcode(cmd, log=False, respond=True)[1]
         data = self.get_cached_info(package)
         data["history"] = history
         self.set_cached_info(package, data)
         return history[tag]
Beispiel #8
0
def is_git_svn(directory):
    directory = os.path.abspath(directory)
    dir = directory.split('/')
    while len(dir)>1:
        path = '/'.join(dir)
        gitconfig = os.path.join(path, '.git', 'config')
        if os.path.isfile(gitconfig) and '[svn-remote' in open(gitconfig).read():
            # check if the remote really works. maybe we have just migrated the package
            # and do not use the svn remote any more
            foo, out, err = runcmd_with_exitcode('cd %s ; git svn info' % path,
                                                 log=False, respond=True,
                                                 respond_error=True)
            if len(err.strip()):
                output.error('Your svn remote is not working. Fix it or '
                             'remove it. (%s)' % directory,
                             exit=True)
            return True
        # if there is .svn (but no .git) it is a .svn directory and
        # do not have to continue walking up...
        if svn.is_subversion(path):
            return False
        dir.pop()
    return False
Beispiel #9
0
    def pre_build_check(self):
        """ Check if a build will work later. Check this before doing anything
        by building and loading the egg.
        """
        output.part_title('Make a test-build for preventing bad dists')
        cwd = os.getcwd()
        # make a sdist
        runcmd('%s setup.py sdist' % sys.executable)
        os.chdir('dist')
        # switch dir
        print output.colorize('cd dist', output.INFO)
        # extract
        runcmd('tar -xf *.tar.gz')
        # find extracted dir / chdir
        distdir = None
        for file_ in os.listdir('.'):
            if os.path.isdir(file_):
                distdir = file_
                break
        if not distdir:
            output.error('Something is wrong: could not find extracted dist directory',
                         exit=1)
        os.chdir(distdir)
        print output.colorize('cd %s' % distdir, output.INFO)
        # test setup.py
        cmd = '%s setup.py egg_info' % sys.executable
        state, response, error = runcmd_with_exitcode(cmd,
                                                      respond=True,
                                                      respond_error=True)
        # cd back to original dir
        os.chdir(cwd)
        # remove stuff
        runcmd('rm -rf dist')
        # did it work?
        if state != 0:
            output.error('Something\'s wrong: could not load setup.py on distribution, ' +\
                             'you may have a problem with your setup.py / MANIFEST.in:',
                         exit=(not error and True or False))
            if response:
                print output.colorize(response, output.INFO)
            if error:
                output.error(error, exit=True)

        # check locales
        locales_dir = os.path.join(scm.get_package_name('.').replace('.', '/'),
                                   'locales')
        if os.path.isdir(locales_dir):
            for basedir, dirs, files in os.walk(locales_dir):
                for file_ in files:
                    path = os.path.join(basedir, file_)
                    if path.endswith('.po'):
                        # check with msgfmt
                        exitcode, errors = runcmd_with_exitcode(
                            'msgfmt -o /dev/null %s' % path,
                            log=True,
                            respond_error=True)
                        if exitcode > 0:
                            output.error(errors, exit=True)

                        data = open(path).read()
                        if 'fuzzy' in data:
                            print path
                            output.error('You have "Fuzzy" entries in your '
                            'translations! I\'m not releasing '
                                         'it like this.', exit=True)
Beispiel #10
0
def has_remote(remote):
    """Checks if there is a `remote` configured in the repo '.'
    """
    cmd = 'git remote show %s' % remote
    exitcode = runcmd_with_exitcode(cmd, log=False, respond=False)
    return exitcode == 0