From dea2ddb038b01eff16f5da4a19c7282e438ec19a Mon Sep 17 00:00:00 2001 From: Jonathan Steffan Date: Sat, 8 Jul 2023 11:50:01 -0600 Subject: [PATCH 1/6] Add Python 3.12 Support - Remove use of imp module (setKeyFunction*) - Update tests for unittest changes - Update ConfigParser read --- lib/carbon/routers.py | 12 ------------ lib/carbon/tests/test_log.py | 2 +- lib/carbon/tests/test_protocols.py | 8 ++++---- lib/carbon/tests/test_routers.py | 6 +++--- lib/carbon/tests/test_storage.py | 26 +++++++++++++------------- lib/carbon/tests/test_util.py | 16 ++++++++-------- setup.py | 2 +- 7 files changed, 30 insertions(+), 42 deletions(-) diff --git a/lib/carbon/routers.py b/lib/carbon/routers.py index d1c47b7a7..9b8d8ef1d 100644 --- a/lib/carbon/routers.py +++ b/lib/carbon/routers.py @@ -1,4 +1,3 @@ -import imp from carbon.hashing import ConsistentHashRing, carbonHash from carbon.util import PluginRegistrar from six import with_metaclass @@ -125,17 +124,6 @@ def getDestinations(self, metric): def getKey(self, metric): return metric - def setKeyFunction(self, func): - self.getKey = func - - def setKeyFunctionFromModule(self, keyfunc_spec): - module_path, func_name = keyfunc_spec.rsplit(':', 1) - module_file = open(module_path, 'U') - description = ('.py', 'U', imp.PY_SOURCE) - module = imp.load_module('keyfunc_module', module_file, module_path, description) - keyfunc = getattr(module, func_name) - self.setKeyFunction(keyfunc) - class AggregatedConsistentHashingRouter(DatapointRouter): plugin_name = 'aggregated-consistent-hashing' diff --git a/lib/carbon/tests/test_log.py b/lib/carbon/tests/test_log.py index 41344d7d8..228e8ccf5 100644 --- a/lib/carbon/tests/test_log.py +++ b/lib/carbon/tests/test_log.py @@ -23,4 +23,4 @@ def test_write_to_logfile(self): with open(path.join(tmpdir, 'creates.log')) as logfile: read_line = logfile.readline() - self.assertRegexpMatches(read_line, '.*😀😀😀😀 test !!!!') + self.assertRegex(read_line, '.*😀😀😀😀 test !!!!') diff --git a/lib/carbon/tests/test_protocols.py b/lib/carbon/tests/test_protocols.py index a9848f586..e1df74417 100644 --- a/lib/carbon/tests/test_protocols.py +++ b/lib/carbon/tests/test_protocols.py @@ -34,7 +34,7 @@ def test_build(self): expected_plugins = sorted(expected_plugins) plugins = sorted(MetricReceiver.plugins.keys()) - self.assertEquals(expected_plugins, plugins) + self.assertEqual(expected_plugins, plugins) class _FakeService(object): def addService(_, __): @@ -339,7 +339,7 @@ def test_cache_query_response_has_datapoints(self): def test_cache_query_returns_empty_if_no_match(self): self.send_request('cache-query', metric='carbon.foo') - self.assertEquals({'datapoints': []}, self.response) + self.assertEqual({'datapoints': []}, self.response) def test_cache_query_returns_cached_datapoints_if_matches(self): self.cache.store('carbon.foo', (600, 1.0)) @@ -356,7 +356,7 @@ def test_cache_bulk_query_response_has_datapointsByMetric(self): def test_cache_bulk_query_response_returns_empty_if_no_match(self): self.send_request('cache-query-bulk', metrics=[]) - self.assertEquals({'datapointsByMetric': {}}, self.response) + self.assertEqual({'datapointsByMetric': {}}, self.response) def test_cache_bulk_query_response(self): self.cache.store('carbon.foo', (600, 1.0)) @@ -364,4 +364,4 @@ def test_cache_bulk_query_response(self): expected_response = {'carbon.foo': [(600, 1.0)], 'carbon.bar': [(600, 2.0)]} self.send_request('cache-query-bulk', metrics=['carbon.foo', 'carbon.bar']) - self.assertEquals({'datapointsByMetric': expected_response}, self.response) + self.assertEqual({'datapointsByMetric': expected_response}, self.response) diff --git a/lib/carbon/tests/test_routers.py b/lib/carbon/tests/test_routers.py index baada73e7..959ab89d6 100644 --- a/lib/carbon/tests/test_routers.py +++ b/lib/carbon/tests/test_routers.py @@ -36,7 +36,7 @@ def testBasic(self): router = routers.RelayRulesRouter(createSettings()) for destination in DESTINATIONS: router.addDestination(parseDestination(destination)) - self.assertEquals(len(list(router.getDestinations('foo.bar'))), 1) + self.assertEqual(len(list(router.getDestinations('foo.bar'))), 1) class TestOtherRouters(unittest.TestCase): @@ -48,9 +48,9 @@ def testBasic(self): continue router = routers.DatapointRouter.plugins[plugin](settings) - self.assertEquals(len(list(router.getDestinations('foo.bar'))), 0) + self.assertEqual(len(list(router.getDestinations('foo.bar'))), 0) for destination in DESTINATIONS: router.addDestination(parseDestination(destination)) - self.assertEquals(len(list(router.getDestinations('foo.bar'))), + self.assertEqual(len(list(router.getDestinations('foo.bar'))), settings['REPLICATION_FACTOR']) diff --git a/lib/carbon/tests/test_storage.py b/lib/carbon/tests/test_storage.py index dacaeddb0..e33b1878d 100644 --- a/lib/carbon/tests/test_storage.py +++ b/lib/carbon/tests/test_storage.py @@ -21,9 +21,9 @@ # def test_loadAggregationSchemas_load_default_schema(self): # from carbon.storage import loadAggregationSchemas, defaultAggregation # schema_list = loadAggregationSchemas() -# self.assertEquals(len(schema_list), 1) +# self.assertEqual(len(schema_list), 1) # schema = schema_list[0] -# self.assertEquals(schema, defaultAggregation) +# self.assertEqual(schema, defaultAggregation) # def test_loadStorageSchemas_raise_CarbonConfigException(self): # from carbon.storage import loadStorageSchemas @@ -51,28 +51,28 @@ def tearDown(self): def test_loadStorageSchemas_return_schemas(self): from carbon.storage import loadStorageSchemas, PatternSchema, Archive schema_list = loadStorageSchemas() - self.assertEquals(len(schema_list), 3) + self.assertEqual(len(schema_list), 3) expected = [ PatternSchema('carbon', r'^carbon\.', [Archive.fromString('60:90d')]), PatternSchema('default_1min_for_1day', '.*', [Archive.fromString('60s:1d')]) ] for schema, expected_schema in zip(schema_list[:-1], expected): - self.assertEquals(schema.name, expected_schema.name) - self.assertEquals(schema.pattern, expected_schema.pattern) + self.assertEqual(schema.name, expected_schema.name) + self.assertEqual(schema.pattern, expected_schema.pattern) for (archive, expected_archive) in zip(schema.archives, expected_schema.archives): - self.assertEquals(archive.getTuple(), expected_archive.getTuple()) + self.assertEqual(archive.getTuple(), expected_archive.getTuple()) def test_loadStorageSchemas_return_the_default_schema_last(self): from carbon.storage import loadStorageSchemas, defaultSchema schema_list = loadStorageSchemas() last_schema = schema_list[-1] - self.assertEquals(last_schema.name, defaultSchema.name) - self.assertEquals(last_schema.archives, defaultSchema.archives) + self.assertEqual(last_schema.name, defaultSchema.name) + self.assertEqual(last_schema.archives, defaultSchema.archives) def test_loadAggregationSchemas_return_schemas(self): from carbon.storage import loadAggregationSchemas, PatternSchema schema_list = loadAggregationSchemas() - self.assertEquals(len(schema_list), 5) + self.assertEqual(len(schema_list), 5) expected = [ PatternSchema('min', r'\.min$', (0.1, 'min')), PatternSchema('max', r'\.max$', (0.1, 'max')), @@ -80,12 +80,12 @@ def test_loadAggregationSchemas_return_schemas(self): PatternSchema('default_average', '.*', (0.5, 'average')) ] for schema, expected_schema in zip(schema_list[:-1], expected): - self.assertEquals(schema.name, expected_schema.name) - self.assertEquals(schema.pattern, expected_schema.pattern) - self.assertEquals(schema.archives, expected_schema.archives) + self.assertEqual(schema.name, expected_schema.name) + self.assertEqual(schema.pattern, expected_schema.pattern) + self.assertEqual(schema.archives, expected_schema.archives) def test_loadAggregationSchema_return_the_default_schema_last(self): from carbon.storage import loadAggregationSchemas, defaultAggregation schema_list = loadAggregationSchemas() last_schema = schema_list[-1] - self.assertEquals(last_schema, defaultAggregation) + self.assertEqual(last_schema, defaultAggregation) diff --git a/lib/carbon/tests/test_util.py b/lib/carbon/tests/test_util.py index 5198b8876..337a1b7c7 100644 --- a/lib/carbon/tests/test_util.py +++ b/lib/carbon/tests/test_util.py @@ -21,7 +21,7 @@ def setTcpKeepAlive(self, value): s.setsockopt(socket.SOL_TCP, socket.SO_KEEPALIVE, value) enableTcpKeepAlive(_Transport(), True, None) - self.assertEquals(s.getsockopt(socket.SOL_TCP, socket.SO_KEEPALIVE), 1) + self.assertEqual(s.getsockopt(socket.SOL_TCP, socket.SO_KEEPALIVE), 1) def test_sanitizing_name_as_tag_value(self): test_cases = [ @@ -61,7 +61,7 @@ def test_sanitizing_name_as_tag_value(self): ) else: result = TaggedSeries.sanitize_name_as_tag_value(test_case['original']) - self.assertEquals(result, test_case['expected']) + self.assertEqual(result, test_case['expected']) def test_validate_tag_key_and_value(self): # assert that it raises exception when sanitized name is still not valid @@ -114,10 +114,10 @@ def test_valid_dest_unbracketed(self): ] actual = parseDestinations(dests) - self.assertEquals(len(expected), len(actual)) + self.assertEqual(len(expected), len(actual)) for exp, act in zip(expected, actual): - self.assertEquals(exp, act) + self.assertEqual(exp, act) def test_valid_dest_bracketed(self): # Tests valid destinations in the bracketed form of . @@ -136,10 +136,10 @@ def test_valid_dest_bracketed(self): ] actual = parseDestinations(dests) - self.assertEquals(len(expected), len(actual)) + self.assertEqual(len(expected), len(actual)) for exp, act in zip(expected, actual): - self.assertEquals(exp, act) + self.assertEqual(exp, act) def test_valid_dest_without_instance(self): # Tests destinations without instance specified. @@ -160,10 +160,10 @@ def test_valid_dest_without_instance(self): ] actual = parseDestinations(dests) - self.assertEquals(len(expected), len(actual)) + self.assertEqual(len(expected), len(actual)) for exp, act in zip(expected, actual): - self.assertEquals(exp, act) + self.assertEqual(exp, act) def test_wrong_dest(self): # Some cases of invalid input, e.g. invalid/missing port. diff --git a/setup.py b/setup.py index 417497eb5..1eb37a9d0 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ with open('setup.cfg', 'r') as f: orig_setup_cfg = f.read() f.seek(0) - cf.readfp(f, 'setup.cfg') + cf.read_file(f, 'setup.cfg') if os.environ.get('GRAPHITE_NO_PREFIX'): cf.remove_section('install') From afc96867de8ac215fff996386b016d4f34bb9d5c Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Sun, 17 Sep 2023 11:27:58 +0200 Subject: [PATCH 2/6] Add Python 3.12 to tests --- .github/workflows/tests-amd64.yml | 17 ++++++++++------- tox.ini | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests-amd64.yml b/.github/workflows/tests-amd64.yml index b80c8aa72..36cbb76f3 100644 --- a/.github/workflows/tests-amd64.yml +++ b/.github/workflows/tests-amd64.yml @@ -25,14 +25,17 @@ jobs: - name: "Python 3.10" python-version: '3.10' toxenv: 'py310' - - name: "Pypy 3.10" - python-version: 'pypy-3.10' - toxenv: 'pypy3' - name: "Python 3.11" python-version: '3.11' toxenv: 'py311' + - name: "Pypy 3.12" + python-version: 'pypy-3.12' + toxenv: 'pypy3' + - name: "Python 3.12" + python-version: '3.12' + toxenv: 'py312' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -48,18 +51,18 @@ jobs: run: | tox - name: Linting - if: ${{ matrix.python-version==3.11 }} + if: ${{ matrix.python-version==3.12 }} env: TOXENV: lint run: | tox - name: Run Codecov - if: ${{ matrix.python-version==3.11 }} + if: ${{ matrix.python-version==3.12 }} env: TOXENV: lint run: | pip install codecov codecov - name: Upload coverage to Codecov - if: ${{ matrix.python-version==3.11 }} + if: ${{ matrix.python-version==3.12 }} uses: codecov/codecov-action@v3 diff --git a/tox.ini b/tox.ini index 071fe3467..5a2e82e79 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{37,38,39,310,311,py3}{,-pyhash}, + py{37,38,39,310,311,312,py3}{,-pyhash}, lint, benchmark From d2d399456d2b8444f35ed249e28e65724c032556 Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Sun, 17 Sep 2023 11:32:08 +0200 Subject: [PATCH 3/6] py3.12 not released yet --- .github/workflows/tests-amd64.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests-amd64.yml b/.github/workflows/tests-amd64.yml index 36cbb76f3..d49120784 100644 --- a/.github/workflows/tests-amd64.yml +++ b/.github/workflows/tests-amd64.yml @@ -28,12 +28,12 @@ jobs: - name: "Python 3.11" python-version: '3.11' toxenv: 'py311' - - name: "Pypy 3.12" - python-version: 'pypy-3.12' + - name: "Pypy 3.11" + python-version: 'pypy-3.11' toxenv: 'pypy3' - - name: "Python 3.12" - python-version: '3.12' - toxenv: 'py312' +# - name: "Python 3.12" +# python-version: '3.12' +# toxenv: 'py312' steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -51,18 +51,18 @@ jobs: run: | tox - name: Linting - if: ${{ matrix.python-version==3.12 }} + if: ${{ matrix.python-version==3.11 }} env: TOXENV: lint run: | tox - name: Run Codecov - if: ${{ matrix.python-version==3.12 }} + if: ${{ matrix.python-version==3.11 }} env: TOXENV: lint run: | pip install codecov codecov - name: Upload coverage to Codecov - if: ${{ matrix.python-version==3.12 }} + if: ${{ matrix.python-version==3.11 }} uses: codecov/codecov-action@v3 From 7fd5ec0b983d34c363789b5b6980f0f31917d83a Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Sun, 17 Sep 2023 11:34:28 +0200 Subject: [PATCH 4/6] only pypy3.10 exists --- .github/workflows/tests-amd64.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests-amd64.yml b/.github/workflows/tests-amd64.yml index d49120784..3815f9853 100644 --- a/.github/workflows/tests-amd64.yml +++ b/.github/workflows/tests-amd64.yml @@ -25,12 +25,12 @@ jobs: - name: "Python 3.10" python-version: '3.10' toxenv: 'py310' + - name: "Pypy 3.10" + python-version: 'pypy-3.10' + toxenv: 'pypy3' - name: "Python 3.11" python-version: '3.11' toxenv: 'py311' - - name: "Pypy 3.11" - python-version: 'pypy-3.11' - toxenv: 'pypy3' # - name: "Python 3.12" # python-version: '3.12' # toxenv: 'py312' From 37f949d5b18eee71a7c185497015b8cd6a719cd1 Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Sun, 17 Sep 2023 11:37:55 +0200 Subject: [PATCH 5/6] fix linting --- lib/carbon/tests/test_routers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/carbon/tests/test_routers.py b/lib/carbon/tests/test_routers.py index 959ab89d6..8d05a37a9 100644 --- a/lib/carbon/tests/test_routers.py +++ b/lib/carbon/tests/test_routers.py @@ -52,5 +52,4 @@ def testBasic(self): for destination in DESTINATIONS: router.addDestination(parseDestination(destination)) - self.assertEqual(len(list(router.getDestinations('foo.bar'))), - settings['REPLICATION_FACTOR']) + self.assertEqual(len(list(router.getDestinations('foo.bar'))), settings['REPLICATION_FACTOR']) From 5b82e16ac37d24c1968849324980958954b793af Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Sun, 17 Sep 2023 11:40:54 +0200 Subject: [PATCH 6/6] fix linting --- lib/carbon/tests/test_routers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/carbon/tests/test_routers.py b/lib/carbon/tests/test_routers.py index 8d05a37a9..f6309e8f2 100644 --- a/lib/carbon/tests/test_routers.py +++ b/lib/carbon/tests/test_routers.py @@ -52,4 +52,7 @@ def testBasic(self): for destination in DESTINATIONS: router.addDestination(parseDestination(destination)) - self.assertEqual(len(list(router.getDestinations('foo.bar'))), settings['REPLICATION_FACTOR']) + self.assertEqual( + len(list(router.getDestinations('foo.bar'))), + settings['REPLICATION_FACTOR'] + )