Exemplo n.º 1
0
 def test_rejects_ordered_collections(self):
   with self.assertRaisesRegexp(TypeError,
                                re.escape('CoercingEncoder does not support OrderedDict inputs')):
     stable_json_sha1(OrderedDict([('a', 3)]))
   with self.assertRaisesRegexp(TypeError,
                                re.escape('CoercingEncoder does not support OrderedSet inputs')):
     stable_json_sha1(OrderedSet([3]))
Exemplo n.º 2
0
 def test_rejects_ordered_collections(self):
   with self.assertRaisesRegexp(TypeError,
                                re.escape('CoercingEncoder does not support OrderedDict inputs')):
     stable_json_sha1(OrderedDict([('a', 3)]))
   with self.assertRaisesRegexp(TypeError,
                                re.escape('CoercingEncoder does not support OrderedSet inputs')):
     stable_json_sha1(OrderedSet([3]))
Exemplo n.º 3
0
    def test_known_checksums(self):
        """Check a laundry list of supported inputs to stable_json_sha1().

    This checks both that the method can successfully handle the type of input object, but also that
    the hash of specific objects remains stable.
    """
        self.assertEqual(stable_json_sha1({}),
                         'bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f')
        self.assertEqual(stable_json_sha1(()),
                         '97d170e1550eee4afc0af065b78cda302a97674c')
        self.assertEqual(stable_json_sha1([]),
                         '97d170e1550eee4afc0af065b78cda302a97674c')
        self.assertEqual(stable_json_sha1(set()),
                         '97d170e1550eee4afc0af065b78cda302a97674c')
        self.assertEqual(stable_json_sha1([{}]),
                         '4e9950a1f2305f56d358cad23f28203fb3aacbef')
        self.assertEqual(stable_json_sha1([('a', 3)]),
                         'd6abed2e53c1595fb3075ecbe020365a47af1f6f')
        self.assertEqual(stable_json_sha1({'a': 3}),
                         '9e0e6d8a99c72daf40337183358cbef91bba7311')
        self.assertEqual(stable_json_sha1([{
            'a': 3
        }]), '8f4e36849a0b8fbe9c4a822c80fbee047c65458a')
        self.assertEqual(stable_json_sha1({1}),
                         'f629ae44b7b3dcfed444d363e626edf411ec69a8')
Exemplo n.º 4
0
 def test_checksum_ordering(self):
     self.assertEqual(stable_json_sha1(set([2, 1, 3])),
                      "a01eda32e4e0b1393274e91d1b3e9ecfc5eaba85")
     self.assertEqual(stable_json_sha1({
         "b": 4,
         "a": 3
     }), "6348df9579e7a72f6ec3fb37751db73b2c97a135")
     self.assertEqual(stable_json_sha1([("b", 4), ("a", 3)]),
                      "8e72bb976e71ea81887eb94730655fe49c454d0c")
     self.assertEqual(stable_json_sha1([{
         "b": 4,
         "a": 3
     }]), "4735d702f51fb8a98edb9f6f3eb3df1d6d38a77f")
Exemplo n.º 5
0
 def test_checksum_ordering(self):
     self.assertEqual(stable_json_sha1(set([2, 1, 3])),
                      'a01eda32e4e0b1393274e91d1b3e9ecfc5eaba85')
     self.assertEqual(stable_json_sha1({
         'b': 4,
         'a': 3
     }), '6348df9579e7a72f6ec3fb37751db73b2c97a135')
     self.assertEqual(stable_json_sha1([('b', 4), ('a', 3)]),
                      '8e72bb976e71ea81887eb94730655fe49c454d0c')
     self.assertEqual(stable_json_sha1([{
         'b': 4,
         'a': 3
     }]), '4735d702f51fb8a98edb9f6f3eb3df1d6d38a77f')
Exemplo n.º 6
0
  def test_known_checksums(self):
    """Check a laundry list of supported inputs to stable_json_sha1().

    This checks both that the method can successfully handle the type of input object, but also that
    the hash of specific objects remains stable.
    """
    self.assertEqual(stable_json_sha1({}), 'bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f')
    self.assertEqual(stable_json_sha1(()), '97d170e1550eee4afc0af065b78cda302a97674c')
    self.assertEqual(stable_json_sha1([]), '97d170e1550eee4afc0af065b78cda302a97674c')
    self.assertEqual(stable_json_sha1(set()), '97d170e1550eee4afc0af065b78cda302a97674c')
    self.assertEqual(stable_json_sha1([{}]), '4e9950a1f2305f56d358cad23f28203fb3aacbef')
    self.assertEqual(stable_json_sha1([('a', 3)]), 'd6abed2e53c1595fb3075ecbe020365a47af1f6f')
    self.assertEqual(stable_json_sha1({'a': 3}), '9e0e6d8a99c72daf40337183358cbef91bba7311')
    self.assertEqual(stable_json_sha1([{'a': 3}]), '8f4e36849a0b8fbe9c4a822c80fbee047c65458a')
    self.assertEqual(stable_json_sha1({1}), 'f629ae44b7b3dcfed444d363e626edf411ec69a8')
Exemplo n.º 7
0
 def fingerprint_iter():
     for req in self:
         hash_items = (
             repr(req._requirement),
             req._repository,
             req._name,
             req._use_2to3,
             req.compatibility,
         )
         yield stable_json_sha1(hash_items)
Exemplo n.º 8
0
 def fingerprint_iter():
   for req in self:
     hash_items = (
       repr(req._requirement),
       req._repository,
       req._name,
       req._use_2to3,
       req.compatibility,
     )
     yield stable_json_sha1(hash_items)
Exemplo n.º 9
0
 def cache_key(self):
   excludes = [(e.org, e.name) for e in self.excludes]
   return stable_json_sha1(dict(org=self.org,
                                name=self.name,
                                rev=self.rev,
                                force=self.force,
                                ext=self.ext,
                                url=self.get_url(relative=True),
                                classifier=self.classifier,
                                transitive=self.transitive,
                                mutable=self.mutable,
                                excludes=excludes))
Exemplo n.º 10
0
    def _compute_fingerprint(self):
        data = (self.org, self.name)

        # NB: The None occupies the legacy rev 3rd slot.  The rev was never populated and always None,
        # so maintaining the slot and its value just serve to preserve the fingerprint and thus
        # containing targets in caches out in the world.
        data += (None, )

        if self.publication_metadata:
            fingerprint = self.publication_metadata.fingerprint()
            if fingerprint:
                data += (fingerprint, )
        return stable_json_sha1(data)
Exemplo n.º 11
0
 def cache_key(self):
     excludes = [(e.org, e.name) for e in self.excludes]
     return stable_json_sha1(
         dict(org=self.org,
              name=self.name,
              rev=self.rev,
              force=self.force,
              ext=self.ext,
              url=self.get_url(relative=True),
              classifier=self.classifier,
              transitive=self.transitive,
              mutable=self.mutable,
              excludes=excludes))
Exemplo n.º 12
0
 def _generate_fingerprinted_pex_path(self, tool_subsystem, interpreter):
   # `tool_subsystem.get_requirement_specs()` is a list, but order shouldn't actually matter. This
   # should probably be sorted, but it's possible a user could intentionally tweak order to work
   # around a particular requirement resolution resolve-order issue. In practice the lists are
   # expected to be mostly static, so we accept the risk of too-fine-grained caching creating lots
   # of pexes in the cache dir.
   specs_fingerprint = stable_json_sha1(tool_subsystem.get_requirement_specs())
   return os.path.join(
     get_pants_cachedir(),
     'python',
     str(interpreter.identity),
     self.fingerprint,
     f'{tool_subsystem.options_scope}-{specs_fingerprint}.pex',
   )
Exemplo n.º 13
0
 def _generate_fingerprinted_pex_path(self, tool_subsystem, interpreter):
   # `tool_subsystem.get_requirement_specs()` is a list, but order shouldn't actually matter. This
   # should probably be sorted, but it's possible a user could intentionally tweak order to work
   # around a particular requirement resolution resolve-order issue. In practice the lists are
   # expected to be mostly static, so we accept the risk of too-fine-grained caching creating lots
   # of pexes in the cache dir.
   specs_fingerprint = stable_json_sha1(tool_subsystem.get_requirement_specs())
   return os.path.join(
     get_pants_cachedir(),
     'python',
     str(interpreter.identity),
     self.fingerprint,
     '{}-{}.pex'.format(tool_subsystem.options_scope, specs_fingerprint),
   )
Exemplo n.º 14
0
    def compute_fingerprint(self, target):
        if isinstance(target, Resources):
            # Just do nothing, this kind of dependency shouldn't affect result's hash.
            return None

        hasher = hashlib.sha1()
        hasher.update(target.payload.fingerprint().encode())
        # Adding tags into cache key because it may decide which workflow applies to the target.
        hasher.update(stable_json_sha1(target.tags).encode())
        if isinstance(target, JarLibrary):
            # NB: Collects only the jars for the current jar_library, and hashes them to ensure that both
            # the resolved coordinates, and the requested coordinates are used. This ensures that if a
            # source file depends on a library with source compatible but binary incompatible signature
            # changes between versions, that you won't get runtime errors due to using an artifact built
            # against a binary incompatible version resolved for a previous compile.
            classpath_entries = self._classpath_products.get_artifact_classpath_entries_for_targets(
                [target])
            for _, entry in classpath_entries:
                hasher.update(str(entry.coordinate).encode())
        return hasher.hexdigest()
Exemplo n.º 15
0
 def test_non_string_dict_key_checksum(self):
     self.assertEqual(stable_json_sha1({('a', 'b'): 'asdf'}),
                      '45deafcfa78a92522166c77b24f5faaf9f3f5c5a')
Exemplo n.º 16
0
 def test_checksum_ordering(self):
   self.assertEqual(stable_json_sha1(set([2, 1, 3])), 'a01eda32e4e0b1393274e91d1b3e9ecfc5eaba85')
   self.assertEqual(stable_json_sha1({'b': 4, 'a': 3}), '6348df9579e7a72f6ec3fb37751db73b2c97a135')
   self.assertEqual(stable_json_sha1([('b', 4), ('a', 3)]), '8e72bb976e71ea81887eb94730655fe49c454d0c')
   self.assertEqual(stable_json_sha1([{'b': 4, 'a': 3}]), '4735d702f51fb8a98edb9f6f3eb3df1d6d38a77f')
Exemplo n.º 17
0
 def test_nested_dict_checksum(self):
   self.assertEqual(stable_json_sha1({(1,): {(2,): 3}}),
                    '63124afed13c4a92eb908fe95c1792528abe3621')
Exemplo n.º 18
0
 def compute_fingerprint(self, target):
   return stable_json_sha1(target.services)
Exemplo n.º 19
0
 def fingerprint(self):
     # TODO: url_builder is not a part of fingerprint.
     return stable_json_sha1(self.name)
Exemplo n.º 20
0
 def _compute_fingerprint(self):
   return stable_json_sha1(tuple(hash(req) for req in self))
Exemplo n.º 21
0
 def _compute_fingerprint(self):
   return stable_json_sha1(self._underlying)
Exemplo n.º 22
0
 def _compute_fingerprint(self):
     return stable_json_sha1(tuple(hash(req) for req in self))
Exemplo n.º 23
0
 def _compute_fingerprint(self):
     return stable_json_sha1((self._kw, self._binaries))
Exemplo n.º 24
0
 def compute_fingerprint(self, target):
     return stable_json_sha1(sorted(target.tags))
Exemplo n.º 25
0
 def test_string_like_dict_key_checksum(self):
     self.assertEqual(stable_json_sha1({'a': 3}),
                      '9e0e6d8a99c72daf40337183358cbef91bba7311')
     self.assertEqual(stable_json_sha1({b'a': 3}),
                      '9e0e6d8a99c72daf40337183358cbef91bba7311')
Exemplo n.º 26
0
 def _compute_fingerprint(self):
   return stable_json_sha1(tuple(jar.cache_key() for jar in self))
Exemplo n.º 27
0
 def test_nested_dict_checksum(self):
     self.assertEqual(stable_json_sha1({(1, ): {
                                            (2, ): 3
                                        }}),
                      '63124afed13c4a92eb908fe95c1792528abe3621')
Exemplo n.º 28
0
 def _compute_fingerprint(self):
     return stable_json_sha1(tuple(jar.cache_key() for jar in self))
Exemplo n.º 29
0
 def fingerprint(self):
     return combine_hashes(
         [self.wiki.fingerprint(),
          stable_json_sha1(self.config)])
Exemplo n.º 30
0
 def _compute_fingerprint(self):
   return stable_json_sha1(tuple(repr(exclude) for exclude in self))
Exemplo n.º 31
0
 def fingerprint(self):
   # TODO: url_builder is not a part of fingerprint.
   return stable_json_sha1(self.name)
Exemplo n.º 32
0
 def test_non_string_dict_key_checksum(self):
     self.assertEqual(stable_json_sha1({("a", "b"): "asdf"}),
                      "45deafcfa78a92522166c77b24f5faaf9f3f5c5a")
Exemplo n.º 33
0
 def _compute_fingerprint(self):
     return stable_json_sha1(tuple(repr(exclude) for exclude in self))
Exemplo n.º 34
0
 def test_non_string_dict_key_checksum(self):
   self.assertEqual(stable_json_sha1({('a', 'b'): 'asdf'}),
                    '45deafcfa78a92522166c77b24f5faaf9f3f5c5a')
Exemplo n.º 35
0
 def _compute_fingerprint(self):
     return stable_json_sha1(self._underlying)
Exemplo n.º 36
0
 def test_string_like_dict_key_checksum(self):
   self.assertEqual(stable_json_sha1({'a': 3}), '9e0e6d8a99c72daf40337183358cbef91bba7311')
   self.assertEqual(stable_json_sha1({b'a': 3}), '9e0e6d8a99c72daf40337183358cbef91bba7311')
Exemplo n.º 37
0
 def compute_fingerprint(self, target):
     return stable_json_sha1(target.services)
Exemplo n.º 38
0
 def fingerprint(self):
   return combine_hashes([self.wiki.fingerprint(), stable_json_sha1(self.config)])