Ejemplo n.º 1
0
    def make_build_properties(cls):
        pi = PythonInterpreter()
        base_info = {
            'class': pi.identity().interpreter,
            'version': pi.identity().version,
            'platform': get_platform(),
        }
        try:
            from twitter.pants import get_buildroot, get_scm
            buildroot = get_buildroot()
            scm = get_scm()

            now = localtime()
            if scm:
                revision = scm.commit_id
                tag = scm.tag_name or 'none'
                branchname = scm.branch_name or revision
            else:
                revision = 'unknown'
                tag = 'none'
                branchname = 'unknown'
            base_info.update({
                'date': strftime('%A %b %d, %Y', now),
                'time': strftime('%H:%M:%S', now),
                'timestamp': strftime('%m.%d.%Y %H:%M', now),
                'branch': branchname,
                'tag': tag,
                'sha': revision,
                'user': getpass.getuser(),
                'machine': socket.gethostname(),
                'path': buildroot
            })
        except ImportError:
            pass
        return base_info
Ejemplo n.º 2
0
  def __init__(self, scm):
    super(ScmWorkspace, self).__init__()

    self._scm = scm or get_scm()

    if self._scm is None:
      raise self.WorkspaceError('Cannot figure out what changed without a configured source-control system.')
Ejemplo n.º 3
0
  def make_build_properties(cls):
    pi = PythonInterpreter()
    base_info = {
      'class': pi.identity().interpreter,
      'version': pi.identity().version,
      'platform': get_platform(),
    }
    try:
      from twitter.pants import get_buildroot, get_scm
      buildroot = get_buildroot()
      scm = get_scm()

      now = localtime()
      revision = scm.commit_id
      tag = scm.tag_name or 'none'
      branchname = scm.branch_name or revision
      base_info.update({
        'date': strftime('%A %b %d, %Y', now),
        'time': strftime('%H:%M:%S', now),
        'timestamp': strftime('%m.%d.%Y %H:%M', now),
        'branch': branchname,
        'tag': tag,
        'sha': revision,
        'user': getpass.getuser(),
        'machine': socket.gethostname(),
        'path': buildroot
      })
    except ImportError:
      pass
    return base_info
Ejemplo n.º 4
0
  def __init__(self, context, scm=None, outstream=sys.stdout):
    """Creates a WhatChanged task that uses an Scm to determine changed files.

    context:    The pants execution context.
    scm:        The scm to use, taken from the globally configured scm if None.
    outstream:  The stream to write changed files or targets to.
    """
    super(ScmWhatChanged, self).__init__(context, ScmWorkspace(scm or get_scm()), outstream)
Ejemplo n.º 5
0
  def __init__(self, context, scm=None, outstream=sys.stdout):
    """Creates a WhatChanged task that uses an Scm to determine changed files.

    context:    The pants execution context.
    scm:        The scm to use, taken from the globally configured scm if None.
    outstream:  The stream to write changed files or targets to.
    """
    super(ScmWhatChanged, self).__init__(context, ScmWorkspace(scm or get_scm()), outstream)
Ejemplo n.º 6
0
 def add_scm_info(self):
   """A helper function to add SCM-related info."""
   scm = get_scm()
   if scm:
     revision = scm.commit_id
     tag = scm.tag_name or 'none'
     branch = scm.branch_name or revision
   else:
     revision, tag, branch = 'none', 'none', 'none'
   self.add_infos(('revision', revision), ('tag', tag), ('branch', branch))
Ejemplo n.º 7
0
 def add_scm_info(self):
   """Adds SCM-related info and returns a dict composed of just this added info."""
   scm = get_scm()
   if scm:
     revision = scm.commit_id
     tag = scm.tag_name or 'none'
     branch = scm.branch_name or revision
   else:
     revision, tag, branch = 'none', 'none', 'none'
   return self.add_infos(('revision', revision), ('tag', tag), ('branch', branch))
Ejemplo n.º 8
0
 def __init__(self, context, scm=None):
   Task.__init__(self, context)
   ScmPublish.__init__(self, scm or get_scm(),
                       self.context.config.getlist(
                         ThriftGemerator._CONFIG_SECTION, 'restrict_push_branches'))
   options = context.options
   self._output_dir = (options.thrift_gemerator_outdir or
                       self.get_workdir(section=ThriftGemerator._CONFIG_SECTION, workdir='gems'))
   self._override = options.thrift_gemerator_override
   self._dryrun = options.gem_publish_dryrun
   self._commit = options.gem_publish_commit
Ejemplo n.º 9
0
 def add_scm_info(self):
     """Adds SCM-related info and returns a dict composed of just this added info."""
     scm = get_scm()
     if scm:
         revision = scm.commit_id
         tag = scm.tag_name or 'none'
         branch = scm.branch_name or revision
     else:
         revision, tag, branch = 'none', 'none', 'none'
     return self.add_infos(('revision', revision), ('tag', tag),
                           ('branch', branch))
Ejemplo n.º 10
0
 def add_scm_info(self):
     """A helper function to add SCM-related info."""
     scm = get_scm()
     if scm:
         revision = scm.commit_id
         tag = scm.tag_name or 'none'
         branch = scm.branch_name or revision
     else:
         revision, tag, branch = 'none', 'none', 'none'
     self.add_infos(('revision', revision), ('tag', tag),
                    ('branch', branch))
Ejemplo n.º 11
0
 def __init__(self, context, scm=None):
     Task.__init__(self, context)
     ScmPublish.__init__(
         self, scm or get_scm(),
         self.context.config.getlist(ThriftGemerator._CONFIG_SECTION,
                                     'restrict_push_branches'))
     options = context.options
     self._output_dir = (options.thrift_gemerator_outdir
                         or self.get_workdir(
                             section=ThriftGemerator._CONFIG_SECTION,
                             workdir='gems'))
     self._override = options.thrift_gemerator_override
     self._dryrun = options.gem_publish_dryrun
     self._commit = options.gem_publish_commit
Ejemplo n.º 12
0
  def __init__(self, context, scm=None, restrict_push_branches=None):
    Task.__init__(self, context)

    self.scm = scm or get_scm()
    self.restrict_push_branches = frozenset(restrict_push_branches or ())
    self.outdir = context.config.get('jar-publish', 'workdir')
    self.cachedir = os.path.join(self.outdir, 'cache')

    if context.options.jar_publish_local:
      local_repo = dict(
        resolver='publish_local',
        path=os.path.abspath(os.path.expanduser(context.options.jar_publish_local)),
        confs=context.config.getlist('jar-publish', 'publish_local_confs', default=['*']),
        auth=None
      )
      self.repos = defaultdict(lambda: local_repo)
      self.commit = False
      self.snapshot = context.options.jar_publish_local_snapshot
    else:
      self.repos = context.config.getdict('jar-publish', 'repos')
      for repo, data in self.repos.items():
        auth = data.get('auth')
        if auth:
          credentials = context.resolve(auth).next()
          user = credentials.username()
          password = credentials.password()
          self.context.log.debug('Found auth for repo: %s %s:%s' % (repo, user, password))
          data['auth'] = (user, password)
      self.commit = context.options.jar_publish_commit
      self.snapshot = False

    self.ivycp = context.config.getlist('ivy', 'classpath')
    self.ivysettings = context.config.get('ivy', 'ivy_settings')

    self.dryrun = context.options.jar_publish_dryrun
    self.transitive = context.options.jar_publish_transitive
    self.force = context.options.jar_publish_force

    def parse_jarcoordinate(coordinate):
      components = coordinate.split('#', 1)
      if len(components) == 2:
        org, name = components
        return org, name
      else:
        try:
          address = Address.parse(get_buildroot(), coordinate)
          try:
            target = Target.get(address)
            if not target:
              siblings = Target.get_all_addresses(address.buildfile)
              prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these'
              raise TaskError('%s => %s?:\n    %s' % (address, prompt,
                                                      '\n    '.join(str(a) for a in siblings)))
            if not is_exported(target):
              raise TaskError('%s is not an exported target' % coordinate)
            return target.provides.org, target.provides.name
          except (ImportError, SyntaxError, TypeError):
            raise TaskError('Failed to parse %s' % address.buildfile.relpath)
        except IOError:
          raise TaskError('No BUILD file could be found at %s' % coordinate)

    self.overrides = {}
    if context.options.jar_publish_overrides:
      def parse_override(override):
        try:
          coordinate, rev = override.split('=', 1)
          try:
            rev = Semver.parse(rev)
          except ValueError as e:
            raise TaskError('Invalid version %s: %s' % (rev, e))
          return parse_jarcoordinate(coordinate), rev
        except ValueError:
          raise TaskError('Invalid override: %s' % override)

      self.overrides.update(parse_override(o) for o in context.options.jar_publish_overrides)

    self.restart_at = None
    if context.options.jar_publish_restart_at:
      self.restart_at = parse_jarcoordinate(context.options.jar_publish_restart_at)

    context.products.require('jars')
    context.products.require('source_jars')
    context.products.require('idl_jars')
    context.products.require('javadoc_jars')
Ejemplo n.º 13
0
    def __init__(self, context, scm=None):
        Task.__init__(self, context)
        ScmPublish.__init__(
            self, scm or get_scm(),
            self.context.config.getlist(JarPublish._CONFIG_SECTION,
                                        'restrict_push_branches'))
        self.outdir = os.path.join(context.config.getdefault('pants_workdir'),
                                   'publish')
        self.cachedir = os.path.join(self.outdir, 'cache')

        self._jvmargs = context.config.getlist(JarPublish._CONFIG_SECTION,
                                               'ivy_jvmargs',
                                               default=[])

        if context.options.jar_publish_local:
            local_repo = dict(resolver='publish_local',
                              path=os.path.abspath(
                                  os.path.expanduser(
                                      context.options.jar_publish_local)),
                              confs=['*'],
                              auth=None)
            self.repos = defaultdict(lambda: local_repo)
            self.commit = False
            self.snapshot = context.options.jar_publish_local_snapshot
        else:
            self.repos = context.config.getdict(JarPublish._CONFIG_SECTION,
                                                'repos')
            for repo, data in self.repos.items():
                auth = data.get('auth')
                if auth:
                    credentials = context.resolve(auth).next()
                    user = credentials.username(data['resolver'])
                    password = credentials.password(data['resolver'])
                    self.context.log.debug('Found auth for repo=%s user=%s' %
                                           (repo, user))
                    self.repos[repo]['username'] = user
                    self.repos[repo]['password'] = password
            self.commit = context.options.jar_publish_commit
            self.snapshot = False

        self.ivycp = context.config.getlist('ivy', 'classpath')
        self.ivysettings = context.config.get('jar-publish', 'ivy_settings')

        self.dryrun = context.options.jar_publish_dryrun
        self.transitive = context.options.jar_publish_transitive
        self.force = context.options.jar_publish_force

        def parse_jarcoordinate(coordinate):
            components = coordinate.split('#', 1)
            if len(components) == 2:
                org, name = components
                return org, name
            else:
                try:
                    address = Address.parse(get_buildroot(), coordinate)
                    try:
                        target = Target.get(address)
                        if not target:
                            siblings = Target.get_all_addresses(
                                address.buildfile)
                            prompt = 'did you mean' if len(
                                siblings
                            ) == 1 else 'maybe you meant one of these'
                            raise TaskError('%s => %s?:\n    %s' %
                                            (address, prompt, '\n    '.join(
                                                str(a) for a in siblings)))
                        if not target.is_exported:
                            raise TaskError('%s is not an exported target' %
                                            coordinate)
                        return target.provides.org, target.provides.name
                    except (ImportError, SyntaxError, TypeError):
                        raise TaskError('Failed to parse %s' %
                                        address.buildfile.relpath)
                except IOError:
                    raise TaskError('No BUILD file could be found at %s' %
                                    coordinate)

        self.overrides = {}
        if context.options.jar_publish_override:

            def parse_override(override):
                try:
                    coordinate, rev = override.split('=', 1)
                    try:
                        rev = Semver.parse(rev)
                    except ValueError as e:
                        raise TaskError('Invalid version %s: %s' % (rev, e))
                    return parse_jarcoordinate(coordinate), rev
                except ValueError:
                    raise TaskError('Invalid override: %s' % override)

            self.overrides.update(
                parse_override(o)
                for o in context.options.jar_publish_override)

        self.restart_at = None
        if context.options.jar_publish_restart_at:
            self.restart_at = parse_jarcoordinate(
                context.options.jar_publish_restart_at)

        context.products.require('jars')
        context.products.require('source_jars')
Ejemplo n.º 14
0
  def __init__(self, scm):
    super(ScmWorkspace, self).__init__()

    self._scm = scm or get_scm()