From 9e67ea6df31ccb8ea6d8586108c06f4991336ff2 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 13 Oct 2021 09:50:08 +0300 Subject: [PATCH 1/3] Add support for Python 3.10 Signed-off-by: Hugo van Kemenade --- .circleci/config.yml | 1 + setup.py | 1 + tox.ini | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d95e6ee..b555a052 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,6 +75,7 @@ workflows: - "3.7" - "3.8" - "3.9" + - "3.10" - test_nooptionals: matrix: parameters: diff --git a/setup.py b/setup.py index 0469f935..2dbfdcb6 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: System :: Monitoring", diff --git a/tox.ini b/tox.ini index 8b2105c7..29845187 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = coverage-clean,py2.7,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9,pypy2.7,pypy3.7,{py2.7,py3.9}-nooptionals,coverage-report,flake8,isort +envlist = coverage-clean,py2.7,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,pypy2.7,pypy3.7,{py2.7,py3.9}-nooptionals,coverage-report,flake8,isort [base] From a9800c4261ae8895bdb7bbe94f5f45f3df7c9ac1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 13 Oct 2021 09:57:58 +0300 Subject: [PATCH 2/3] Remove redundant Python 2.6 code Signed-off-by: Hugo van Kemenade --- prometheus_client/exposition.py | 3 +-- setup.py | 8 ++------ tests/openmetrics/test_exposition.py | 9 +-------- tests/openmetrics/test_parser.py | 8 +------- tests/test_asgi.py | 6 +----- tests/test_exposition.py | 8 +------- tests/test_gc_collector.py | 7 +------ tests/test_multiprocess.py | 10 +--------- tests/test_parser.py | 9 +-------- tests/test_twisted.py | 6 +----- tests/test_wsgi.py | 11 ----------- 11 files changed, 11 insertions(+), 74 deletions(-) diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py index 551c708d..8bccc609 100644 --- a/prometheus_client/exposition.py +++ b/prometheus_client/exposition.py @@ -34,7 +34,6 @@ CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8') """Content type of the latest text format""" PYTHON27_OR_OLDER = sys.version_info < (3, ) -PYTHON26_OR_OLDER = sys.version_info < (2, 7) PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5) @@ -445,7 +444,7 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler) gateway_url = urlparse(gateway) # See https://bugs.python.org/issue27657 for details on urlparse in py>=3.7.6. if not gateway_url.scheme or ( - (PYTHON376_OR_NEWER or PYTHON26_OR_OLDER) + PYTHON376_OR_NEWER and gateway_url.scheme not in ['http', 'https'] ): gateway = 'http://{0}'.format(gateway) diff --git a/setup.py b/setup.py index 2dbfdcb6..185d3524 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,9 @@ from os import path -import sys from setuptools import setup -if sys.version_info >= (2, 7): - with open(path.join(path.abspath(path.dirname(__file__)), 'README.md')) as f: - long_description = f.read() -else: # Assuming we don't run setup in order to publish under python 2.6 - long_description = "NA" +with open(path.join(path.abspath(path.dirname(__file__)), 'README.md')) as f: + long_description = f.read() setup( diff --git a/tests/openmetrics/test_exposition.py b/tests/openmetrics/test_exposition.py index 72578a0b..58ec05d9 100644 --- a/tests/openmetrics/test_exposition.py +++ b/tests/openmetrics/test_exposition.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals -import sys import time +import unittest from prometheus_client import ( CollectorRegistry, Counter, Enum, Gauge, Histogram, Info, Metric, Summary, @@ -11,12 +11,6 @@ ) from prometheus_client.openmetrics.exposition import generate_latest -if sys.version_info < (2, 7): - # We need the skip decorators from unittest2 on Python 2.6. - import unittest2 as unittest -else: - import unittest - class TestGenerateText(unittest.TestCase): def setUp(self): @@ -70,7 +64,6 @@ def test_summary(self): # EOF """, generate_latest(self.registry)) - @unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.") def test_histogram(self): s = Histogram('hh', 'A histogram', registry=self.registry) s.observe(0.05) diff --git a/tests/openmetrics/test_parser.py b/tests/openmetrics/test_parser.py index 104547eb..8fd2319d 100644 --- a/tests/openmetrics/test_parser.py +++ b/tests/openmetrics/test_parser.py @@ -2,6 +2,7 @@ import math import sys +import unittest from prometheus_client.core import ( CollectorRegistry, CounterMetricFamily, Exemplar, @@ -12,12 +13,6 @@ from prometheus_client.openmetrics.exposition import generate_latest from prometheus_client.openmetrics.parser import text_string_to_metric_families -if sys.version_info < (2, 7): - # We need the skip decorators from unittest2 on Python 2.6. - import unittest2 as unittest -else: - import unittest - class TestParse(unittest.TestCase): @@ -549,7 +544,6 @@ def test_fallback_to_state_machine_label_parsing(self): mock2.assert_not_called() mock3.assert_called_once_with('1') - @unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.") def test_roundtrip(self): text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary diff --git a/tests/test_asgi.py b/tests/test_asgi.py index 0f14bfc3..f8ea48a7 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -1,15 +1,11 @@ from __future__ import absolute_import, unicode_literals -import sys from unittest import TestCase +from unittest import skipUnless from prometheus_client import CollectorRegistry, Counter from prometheus_client.exposition import CONTENT_TYPE_LATEST -if sys.version_info < (2, 7): - from unittest2 import skipUnless -else: - from unittest import skipUnless try: # Python >3.5 only diff --git a/tests/test_exposition.py b/tests/test_exposition.py index 7bb404b5..7884528f 100644 --- a/tests/test_exposition.py +++ b/tests/test_exposition.py @@ -1,8 +1,8 @@ from __future__ import unicode_literals -import sys import threading import time +import unittest import pytest @@ -17,11 +17,6 @@ passthrough_redirect_handler, ) -if sys.version_info < (2, 7): - # We need the skip decorators from unittest2 on Python 2.6. - import unittest2 as unittest -else: - import unittest try: from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer @@ -98,7 +93,6 @@ def test_summary(self): ss_created{a="c",b="d"} 123.456 """, generate_latest(self.registry)) - @unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.") def test_histogram(self): s = Histogram('hh', 'A histogram', registry=self.registry) s.observe(0.05) diff --git a/tests/test_gc_collector.py b/tests/test_gc_collector.py index c0cda88f..00714422 100644 --- a/tests/test_gc_collector.py +++ b/tests/test_gc_collector.py @@ -3,12 +3,7 @@ import gc import platform import sys - -if sys.version_info < (2, 7): - # We need the skip decorators from unittest2 on Python 2.6. - import unittest2 as unittest -else: - import unittest +import unittest from prometheus_client import CollectorRegistry, GCCollector diff --git a/tests/test_multiprocess.py b/tests/test_multiprocess.py index 96792a36..af008b93 100644 --- a/tests/test_multiprocess.py +++ b/tests/test_multiprocess.py @@ -3,9 +3,9 @@ import glob import os import shutil -import sys import tempfile import warnings +import unittest from prometheus_client import mmap_dict, values from prometheus_client.core import ( @@ -18,12 +18,6 @@ get_value_class, MultiProcessValue, MutexValue, ) -if sys.version_info < (2, 7): - # We need the skip decorators from unittest2 on Python 2.6. - import unittest2 as unittest -else: - import unittest - class TestMultiProcessDeprecation(unittest.TestCase): def setUp(self): @@ -196,7 +190,6 @@ def files(): c3 = Counter('c3', 'c3', registry=None) self.assertEqual(files(), ['counter_0.db', 'counter_1.db']) - @unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.") def test_collect(self): pid = 0 values.ValueClass = MultiProcessValue(lambda: pid) @@ -257,7 +250,6 @@ def add_label(key, value): self.assertEqual(metrics['h'].samples, expected_histogram) - @unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.") def test_merge_no_accumulate(self): pid = 0 values.ValueClass = MultiProcessValue(lambda: pid) diff --git a/tests/test_parser.py b/tests/test_parser.py index 44a3fa45..780f0bc7 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import math -import sys +import unittest from prometheus_client.core import ( CollectorRegistry, CounterMetricFamily, GaugeMetricFamily, @@ -10,12 +10,6 @@ from prometheus_client.exposition import generate_latest from prometheus_client.parser import text_string_to_metric_families -if sys.version_info < (2, 7): - # We need the skip decorators from unittest2 on Python 2.6. - import unittest2 as unittest -else: - import unittest - class TestParse(unittest.TestCase): def assertEqualMetrics(self, first, second, msg=None): @@ -289,7 +283,6 @@ def test_timestamps(self): b.add_metric([], 88, timestamp=1234566) self.assertEqualMetrics([a, b], list(families)) - @unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.") def test_roundtrip(self): text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary diff --git a/tests/test_twisted.py b/tests/test_twisted.py index 110aded7..6772f8ba 100644 --- a/tests/test_twisted.py +++ b/tests/test_twisted.py @@ -1,13 +1,9 @@ from __future__ import absolute_import, unicode_literals -import sys +from unittest import skipUnless from prometheus_client import CollectorRegistry, Counter, generate_latest -if sys.version_info < (2, 7): - from unittest2 import skipUnless -else: - from unittest import skipUnless try: from twisted.internet import reactor diff --git a/tests/test_wsgi.py b/tests/test_wsgi.py index 79fea884..7a285a9c 100644 --- a/tests/test_wsgi.py +++ b/tests/test_wsgi.py @@ -22,17 +22,6 @@ def capture(self, status, header): self.captured_status = status self.captured_headers = header - def assertIn(self, item, iterable): - try: - super().assertIn(item, iterable) - except: # Python < 2.7 - self.assertTrue( - item in iterable, - msg="{item} not found in {iterable}".format( - item=item, iterable=iterable - ) - ) - def validate_metrics(self, metric_name, help_text, increments): """ WSGI app serves the metrics from the provided registry. From bf1e7dcdeb3cadeea44cc83fd5989b41e5529824 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 13 Oct 2021 10:04:01 +0300 Subject: [PATCH 3/3] isort Signed-off-by: Hugo van Kemenade --- tests/test_asgi.py | 4 +--- tests/test_exposition.py | 1 - tests/test_multiprocess.py | 2 +- tests/test_twisted.py | 1 - 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_asgi.py b/tests/test_asgi.py index f8ea48a7..139c8717 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -1,12 +1,10 @@ from __future__ import absolute_import, unicode_literals -from unittest import TestCase -from unittest import skipUnless +from unittest import skipUnless, TestCase from prometheus_client import CollectorRegistry, Counter from prometheus_client.exposition import CONTENT_TYPE_LATEST - try: # Python >3.5 only import asyncio diff --git a/tests/test_exposition.py b/tests/test_exposition.py index 7884528f..757f1705 100644 --- a/tests/test_exposition.py +++ b/tests/test_exposition.py @@ -17,7 +17,6 @@ passthrough_redirect_handler, ) - try: from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer except ImportError: diff --git a/tests/test_multiprocess.py b/tests/test_multiprocess.py index af008b93..310f8c77 100644 --- a/tests/test_multiprocess.py +++ b/tests/test_multiprocess.py @@ -4,8 +4,8 @@ import os import shutil import tempfile -import warnings import unittest +import warnings from prometheus_client import mmap_dict, values from prometheus_client.core import ( diff --git a/tests/test_twisted.py b/tests/test_twisted.py index 6772f8ba..ea1796f4 100644 --- a/tests/test_twisted.py +++ b/tests/test_twisted.py @@ -4,7 +4,6 @@ from prometheus_client import CollectorRegistry, Counter, generate_latest - try: from twisted.internet import reactor from twisted.trial.unittest import TestCase