Skip to content

Add support for Python 3.10 #706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ workflows:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- test_nooptionals:
matrix:
parameters:
Expand Down
3 changes: 1 addition & 2 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -47,6 +43,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",
Expand Down
9 changes: 1 addition & 8 deletions tests/openmetrics/test_exposition.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions tests/openmetrics/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import math
import sys
import unittest

from prometheus_client.core import (
CollectorRegistry, CounterMetricFamily, Exemplar,
Expand All @@ -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):

Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from __future__ import absolute_import, unicode_literals

import sys
from unittest import TestCase
from unittest import skipUnless, TestCase

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
import asyncio
Expand Down
9 changes: 1 addition & 8 deletions tests/test_exposition.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import unicode_literals

import sys
import threading
import time
import unittest

import pytest

Expand All @@ -17,12 +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
except ImportError:
Expand Down Expand Up @@ -98,7 +92,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)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_gc_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions tests/test_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import glob
import os
import shutil
import sys
import tempfile
import unittest
import warnings

from prometheus_client import mmap_dict, values
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

import math
import sys
import unittest

from prometheus_client.core import (
CollectorRegistry, CounterMetricFamily, GaugeMetricFamily,
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions tests/test_twisted.py
Original file line number Diff line number Diff line change
@@ -1,14 +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
from twisted.trial.unittest import TestCase
Expand Down
11 changes: 0 additions & 11 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand Down