Example #1
0
  def get_entry(self, target):
    """Given an internal target, return a PushDb.Entry, which might contain defaults."""
    db_get, _ = self._accessors_for_target(target)

    major = int(db_get('revision.major', '0'))
    minor = int(db_get('revision.minor', '0'))
    patch = int(db_get('revision.patch', '0'))
    snapshot = str(db_get('revision.snapshot', 'false')).lower() == 'true'
    named_version = db_get('revision.named_version', None)
    named_is_latest = str(db_get('revision.named_is_latest', 'false')).lower() == 'true'
    sha = db_get('revision.sha', None)
    fingerprint = db_get('revision.fingerprint', None)
    sem_ver = Semver(major, minor, patch, snapshot=snapshot)
    named_ver = Namedver(named_version) if named_version else None
    return self.Entry(sem_ver, named_ver, named_is_latest, sha, fingerprint)
    def test_namedver(self):
        Namedver.parse('12345')
        Namedver.parse('a_b-c.1.2')
        Namedver.parse('a')
        Namedver.parse('1')
        Namedver.parse('1.2')

        # Can't match semver
        with self.assertRaises(ValueError):
            Namedver.parse('1.2.3')

        # No special characters other than (-_.)
        with self.assertRaises(ValueError):
            Namedver.parse('Foo*')

        # No whitespace
        with self.assertRaises(ValueError):
            Namedver.parse('a d')

        # Must contain alphanumeric characters
        with self.assertRaises(ValueError):
            Namedver.parse('')
        with self.assertRaises(ValueError):
            Namedver.parse('-')
        with self.assertRaises(ValueError):
            Namedver.parse('_')
        with self.assertRaises(ValueError):
            Namedver.parse('.')
        with self.assertRaises(ValueError):
            Namedver.parse('.-_')
Example #3
0
  def __init__(self, *args, **kwargs):
    super(JarPublish, self).__init__(*args, **kwargs)
    self.cachedir = os.path.join(self.workdir, 'cache')

    self._jvm_options = self.get_options().jvm_options

    self.log = self.context.log

    if self.get_options().local:
      local_repo = dict(
        resolver='publish_local',
        path=os.path.abspath(os.path.expanduser(self.get_options().local)),
        confs=['default'],
        auth=None
      )
      self.repos = defaultdict(lambda: local_repo)
      self.commit = False
      self.local_snapshot = self.get_options().local_snapshot
    else:
      self.repos = self.get_options().repos
      if not self.repos:
        raise TaskError(
          "This repo is not configured to publish externally! Please configure per\n"
          "http://pantsbuild.org/publish.html#authenticating-to-the-artifact-repository,\n"
          "by setting --publish-jar-repos=<dict> or re-run with '--publish-jar-local=<dir>'.")
      for repo, data in self.repos.items():
        auth = data.get('auth')
        if auth:
          credentials = next(iter(self.context.resolve(auth)))
          user = credentials.username(data['resolver'])
          password = credentials.password(data['resolver'])
          self.context.log.debug('Found auth for repo={} user={}'.format(repo, user))
          self.repos[repo]['username'] = user
          self.repos[repo]['password'] = password
      self.commit = self.get_options().commit
      self.push_postscript = self.get_options().push_postscript or ''
      self.local_snapshot = False

    self.scm = get_scm() if self.commit else None

    self.named_snapshot = self.get_options().named_snapshot
    if self.named_snapshot:
      self.named_snapshot = Namedver.parse(self.named_snapshot)

    self.dryrun = self.get_options().dryrun
    self.force = self.get_options().force
    self.publish_changelog = self.get_options().changelog and self.scm

    def parse_jarcoordinate(coordinate):
      components = coordinate.split('#', 1)
      if len(components) == 2:
        org, name = components
        return org, name
      else:
        spec = components[0]
        address = Address.parse(spec)
        try:
          self.context.build_graph.inject_address_closure(address)
          target = self.context.build_graph.get_target(address)
          if not target:
            siblings = self.context.address_mapper.addresses_in_spec_path(address.spec_path)
            prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these'
            raise TaskError('{} => {}?:\n    {}'.format(address, prompt,
                                                        '\n    '.join(str(a) for a in siblings)))
          if not self._is_exported(target):
            raise TaskError('{} is not an exported target'.format(coordinate))
          return target.provides.org, target.provides.name
        except (BuildFile.BuildFileError,
                BuildFileParser.BuildFileParserError,
                AddressLookupError) as e:
          raise TaskError('{message}\n  Problem identifying target at {spec}'
                          .format(message=e, spec=spec))

    self.overrides = {}
    if self.get_options().override:
      if self.named_snapshot:
        raise TaskError('Options --named-snapshot and --override are mutually exclusive!')

      def parse_override(override):
        try:
          coordinate, rev = override.split('=', 1)
          try:
            # overrides imply semantic versioning
            rev = Semver.parse(rev)
          except ValueError as e:
            raise TaskError('Invalid version {}: {}'.format(rev, e))
          return parse_jarcoordinate(coordinate), rev
        except ValueError:
          raise TaskError('Invalid override: {}'.format(override))

      self.overrides.update(parse_override(o) for o in self.get_options().override)

    self.restart_at = None
    if self.get_options().restart_at:
      self.restart_at = parse_jarcoordinate(self.get_options().restart_at)
Example #4
0
  def __init__(self, *args, **kwargs):
    super(JarPublish, self).__init__(*args, **kwargs)
    self.cachedir = os.path.join(self.workdir, 'cache')

    self._jvm_options = self.get_options().jvm_options

    self.scm = get_scm()
    self.log = self.context.log

    if self.get_options().local:
      local_repo = dict(
        resolver='publish_local',
        path=os.path.abspath(os.path.expanduser(self.get_options().local)),
        confs=['default'],
        auth=None
      )
      self.repos = defaultdict(lambda: local_repo)
      self.commit = False
      self.local_snapshot = self.get_options().local_snapshot
    else:
      self.repos = self.get_options().repos
      if not self.repos:
        raise TaskError(
          "This repo is not configured to publish externally! Please configure per\n"
          "http://pantsbuild.github.io/publish.html#authenticating-to-the-artifact-repository,\n"
          "by setting --publish-jar-repos=<dict> or re-run with '--publish-jar-local=<dir>'.")
      for repo, data in self.repos.items():
        auth = data.get('auth')
        if auth:
          credentials = next(iter(self.context.resolve(auth)))
          user = credentials.username(data['resolver'])
          password = credentials.password(data['resolver'])
          self.context.log.debug('Found auth for repo={} user={}'.format(repo, user))
          self.repos[repo]['username'] = user
          self.repos[repo]['password'] = password
      self.commit = self.get_options().commit
      self.push_postscript = self.get_options().push_postscript or ''
      self.local_snapshot = False

    self.named_snapshot = self.get_options().named_snapshot
    if self.named_snapshot:
      self.named_snapshot = Namedver.parse(self.named_snapshot)

    self.dryrun = self.get_options().dryrun
    self.transitive = self.get_options().transitive
    self.force = self.get_options().force
    self.publish_changelog = self.get_options().changelog

    def parse_jarcoordinate(coordinate):
      components = coordinate.split('#', 1)
      if len(components) == 2:
        org, name = components
        return org, name
      else:
        spec = components[0]
        address = Address.parse(spec)
        try:
          self.context.build_graph.inject_address_closure(address)
          target = self.context.build_graph.get_target(address)
          if not target:
            siblings = self.context.address_mapper.addresses_in_spec_path(address.spec_path)
            prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these'
            raise TaskError('{} => {}?:\n    {}'.format(address, prompt,
                                                        '\n    '.join(str(a) for a in siblings)))
          if not target.is_exported:
            raise TaskError('{} is not an exported target'.format(coordinate))
          return target.provides.org, target.provides.name
        except (BuildFile.BuildFileError,
                BuildFileParser.BuildFileParserError,
                AddressLookupError) as e:
          raise TaskError('{message}\n  Problem identifying target at {spec}'
                          .format(message=e, spec=spec))

    self.overrides = {}
    if self.get_options().override:
      if self.named_snapshot:
        raise TaskError('Options --named-snapshot and --override are mutually exclusive!')

      def parse_override(override):
        try:
          coordinate, rev = override.split('=', 1)
          try:
            # overrides imply semantic versioning
            rev = Semver.parse(rev)
          except ValueError as e:
            raise TaskError('Invalid version {}: {}'.format(rev, e))
          return parse_jarcoordinate(coordinate), rev
        except ValueError:
          raise TaskError('Invalid override: {}'.format(override))

      self.overrides.update(parse_override(o) for o in self.get_options().override)

    self.restart_at = None
    if self.get_options().restart_at:
      self.restart_at = parse_jarcoordinate(self.get_options().restart_at)
Example #5
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.cachedir = os.path.join(self.workdir, "cache")

        self._jvm_options = self.get_options().jvm_options

        self.log = self.context.log

        if self.get_options().local:
            local_repo = dict(
                resolver="publish_local",
                path=os.path.abspath(
                    os.path.expanduser(self.get_options().local)),
                confs=["default"],
                auth=None,
            )
            self.repos = defaultdict(lambda: local_repo)
            self.commit = False
            self.local_snapshot = self.get_options().local_snapshot
        else:
            self.repos = self.get_options().repos
            if not self.repos:
                raise TaskError(
                    "This repo is not configured to publish externally! Please configure per\n"
                    "http://pantsbuild.org/publish.html#authenticating-to-the-artifact-repository,\n"
                    "by setting --publish-jar-repos=<dict> or re-run with '--publish-jar-local=<dir>'."
                )
            for repo, data in self.repos.items():
                auth = data.get("auth")
                if auth:
                    credentials = next(iter(self.context.resolve(auth)))
                    user = credentials.username(data["resolver"])
                    password = credentials.password(data["resolver"])
                    self.context.log.debug(
                        f"Found auth for repo={repo} user={user}")
                    self.repos[repo]["username"] = user
                    self.repos[repo]["password"] = password
            self.commit = self.get_options().commit
            self.push_postscript = self.get_options().push_postscript or ""
            self.local_snapshot = False

        self.scm = get_scm() if self.commit else None

        self.named_snapshot = self.get_options().named_snapshot
        if self.named_snapshot:
            self.named_snapshot = Namedver.parse(self.named_snapshot)

        self.dryrun = self.get_options().dryrun
        self.force = self.get_options().force
        self.publish_changelog = self.get_options().changelog and self.scm

        def parse_jarcoordinate(coordinate):
            components = coordinate.split("#", 1)
            if len(components) == 2:
                org, name = components
                return org, name
            else:
                spec = components[0]
                address = Address.parse(spec)
                try:
                    self.context.build_graph.inject_address_closure(address)
                    target = self.context.build_graph.get_target(address)
                    if not target:
                        siblings = self.context.address_mapper.addresses_in_spec_path(
                            address.spec_path)
                        prompt = ("did you mean" if len(siblings) == 1 else
                                  "maybe you meant one of these")
                        raise TaskError("{} => {}?:\n    {}".format(
                            address, prompt,
                            "\n    ".join(str(a) for a in siblings)))
                    if not self._is_exported(target):
                        raise TaskError(
                            f"{coordinate} is not an exported target")
                    return target.provides.org, target.provides.name
                except AddressLookupError as e:
                    raise TaskError(
                        f"{e!r}\n  Problem identifying target at {spec}")

        self.overrides = {}
        if self.get_options().override:
            if self.named_snapshot:
                raise TaskError(
                    "Options --named-snapshot and --override are mutually exclusive!"
                )

            def parse_override(override):
                try:
                    coordinate, rev = override.split("=", 1)
                    try:
                        # overrides imply semantic versioning
                        rev = Semver.parse(rev)
                    except ValueError as e:
                        raise TaskError(f"Invalid version {rev}: {e!r}")
                    return parse_jarcoordinate(coordinate), rev
                except ValueError:
                    raise TaskError(f"Invalid override: {override}")

            self.overrides.update(
                parse_override(o) for o in self.get_options().override)

        self.restart_at = None
        if self.get_options().restart_at:
            self.restart_at = parse_jarcoordinate(
                self.get_options().restart_at)
Example #6
0
    def test_namedver(self):
        Namedver.parse("12345")
        Namedver.parse("a_b-c.1.2")
        Namedver.parse("a")
        Namedver.parse("1")
        Namedver.parse("1.2")

        # Can't match semver
        with self.assertRaises(ValueError):
            Namedver.parse("1.2.3")

        # No special characters other than (-_.)
        with self.assertRaises(ValueError):
            Namedver.parse("Foo*")

        # No whitespace
        with self.assertRaises(ValueError):
            Namedver.parse("a d")

        # Must contain alphanumeric characters
        with self.assertRaises(ValueError):
            Namedver.parse("")
        with self.assertRaises(ValueError):
            Namedver.parse("-")
        with self.assertRaises(ValueError):
            Namedver.parse("_")
        with self.assertRaises(ValueError):
            Namedver.parse(".")
        with self.assertRaises(ValueError):
            Namedver.parse(".-_")
  def test_namedver(self):
    Namedver.parse('12345')
    Namedver.parse('a_b-c.1.2')
    Namedver.parse('a')
    Namedver.parse('1')
    Namedver.parse('1.2')

    # Can't match semver
    with self.assertRaises(ValueError):
      Namedver.parse('1.2.3')

    # No special characters other than (-_.)
    with self.assertRaises(ValueError):
      Namedver.parse('Foo*')

    # No whitespace
    with self.assertRaises(ValueError):
      Namedver.parse('a d')

    # Must contain alphanumeric characters
    with self.assertRaises(ValueError):
      Namedver.parse('')
    with self.assertRaises(ValueError):
      Namedver.parse('-')
    with self.assertRaises(ValueError):
      Namedver.parse('_')
    with self.assertRaises(ValueError):
      Namedver.parse('.')
    with self.assertRaises(ValueError):
      Namedver.parse('.-_')