From 41ba0c5c850bb88b27543c2c6304ff573ac9d552 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Sat, 24 Dec 2022 13:58:40 -0800 Subject: [PATCH] lint --- .isort.cfg | 18 +++++ CHANGELOG.md | 2 +- .../monitor/opentelemetry/distro/distro.py | 10 ++- azure-monitor-opentelemetry-distro/setup.py | 73 ++++++++++--------- .../tests/exporter/test_exporter.py | 8 +- .../tests/instrumentation/test_flask.py | 1 - .../tests/instrumentation/test_psycopg2.py | 1 - .../tests/instrumentation/test_requests.py | 1 - pyproject.toml | 14 ++++ tox.ini | 6 +- 10 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 .isort.cfg create mode 100644 pyproject.toml diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..3165851 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,18 @@ +[settings] +include_trailing_comma=True +force_grid_wrap=0 +use_parentheses=True +line_length=79 +profile=black + +; 3 stands for Vertical Hanging Indent, e.g. +; from third_party import ( +; lib1, +; lib2, +; lib3, +; ) +; docs: https://github.com/timothycrosley/isort#multi-line-output-modes +multi_line_output=3 +skip=target +skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,.tox/* +known_third_party=opentelemetry,psutil,pytest,redis,redis_opentracing diff --git a/CHANGELOG.md b/CHANGELOG.md index 515d282..461b1fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - Update CONTRIBUTING.md, support Py3.11 ([#210](https://github.com/microsoft/ApplicationInsights-Python/pull/210)) - Updated setup.py, directory structure - ([#210](https://github.com/microsoft/ApplicationInsights-Python/pull/210)) + ([#214](https://github.com/microsoft/ApplicationInsights-Python/pull/214)) ## [1.0.0b8](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b8) - 2022-09-26 diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py index dddc351..e11c765 100644 --- a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py +++ b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py @@ -6,8 +6,10 @@ from os import environ -from opentelemetry.environment_variables import (OTEL_METRICS_EXPORTER, - OTEL_TRACES_EXPORTER) +from opentelemetry.environment_variables import ( + OTEL_METRICS_EXPORTER, + OTEL_TRACES_EXPORTER, +) from opentelemetry.instrumentation.distro import BaseDistro @@ -18,4 +20,6 @@ class AzureMonitorDistro(BaseDistro): environ.setdefault( OTEL_METRICS_EXPORTER, "azure_monitor_opentelemetry_exporter" ) - environ.setdefault(OTEL_TRACES_EXPORTER, "azure_monitor_opentelemetry_exporter") + environ.setdefault( + OTEL_TRACES_EXPORTER, "azure_monitor_opentelemetry_exporter" + ) diff --git a/azure-monitor-opentelemetry-distro/setup.py b/azure-monitor-opentelemetry-distro/setup.py index e47edb2..4ede375 100644 --- a/azure-monitor-opentelemetry-distro/setup.py +++ b/azure-monitor-opentelemetry-distro/setup.py @@ -10,15 +10,14 @@ import os import re -from setuptools import setup, find_packages - +from setuptools import find_packages, setup # Change the PACKAGE_NAME only to change folder and different name PACKAGE_NAME = "azure-monitor-opentelemetry-distro" PACKAGE_PPRINT_NAME = "Azure Monitor Opentelemetry Distro" # a-b-c => a/b/c -package_folder_path = PACKAGE_NAME.replace('-', '/') +package_folder_path = PACKAGE_NAME.replace("-", "/") # azure v0.x is not compatible with this package @@ -29,8 +28,8 @@ try: try: ver = azure.__version__ raise Exception( - 'This package is incompatible with azure=={}. '.format(ver) + - 'Uninstall it with "pip uninstall azure".' + "This package is incompatible with azure=={}. ".format(ver) + + 'Uninstall it with "pip uninstall azure".' ) except AttributeError: pass @@ -38,46 +37,51 @@ except ImportError: pass # Version extraction inspired from 'requests' -with open(os.path.join(package_folder_path, '_version.py'), 'r') as fd: - version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', - fd.read(), re.MULTILINE).group(1) +with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: + version = re.search( + r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE + ).group(1) if not version: - raise RuntimeError('Cannot find version information') + raise RuntimeError("Cannot find version information") setup( name=PACKAGE_NAME, version=version, - description='Microsoft {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), - long_description=open('README.md', 'r').read(), - long_description_content_type='text/markdown', - license='MIT License', - author='Microsoft Corporation', - author_email='ascl@microsoft.com', - url='https://github.com/microsoft/ApplicationInsights-Python/tree/main/azure-monitor-opentelemetry-distro', + description="Microsoft {} Client Library for Python".format( + PACKAGE_PPRINT_NAME + ), + long_description=open("README.md", "r").read(), + long_description_content_type="text/markdown", + license="MIT License", + author="Microsoft Corporation", + author_email="ascl@microsoft.com", + url="https://github.com/microsoft/ApplicationInsights-Python/tree/main/azure-monitor-opentelemetry-distro", classifiers=[ "Development Status :: 4 - Beta", - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'License :: OSI Approved :: MIT License', + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "License :: OSI Approved :: MIT License", ], zip_safe=False, - packages=find_packages(exclude=[ - 'tests', - 'samples', - # Exclude packages that will be covered by PEP420 or nspkg - 'azure', - 'azure.monitor', - 'azure.monitor.opentelemetry' - ]), + packages=find_packages( + exclude=[ + "tests", + "samples", + # Exclude packages that will be covered by PEP420 or nspkg + "azure", + "azure.monitor", + "azure.monitor.opentelemetry", + ] + ), include_package_data=True, package_data={ - 'pytyped': ['py.typed'], + "pytyped": ["py.typed"], }, python_requires=">=3.7", install_requires=[ @@ -95,6 +99,5 @@ setup( "opentelemetry_configurator": [ "azure_monitor_opentelemetry_configurator = azure.monitor.opentelemetry.distro.configurator:AzureMonitorConfigurator" ], - } + }, ) - diff --git a/azure-monitor-opentelemetry-distro/tests/exporter/test_exporter.py b/azure-monitor-opentelemetry-distro/tests/exporter/test_exporter.py index f2963a0..21561ac 100644 --- a/azure-monitor-opentelemetry-distro/tests/exporter/test_exporter.py +++ b/azure-monitor-opentelemetry-distro/tests/exporter/test_exporter.py @@ -14,9 +14,11 @@ import unittest -from azure.monitor.opentelemetry.exporter import (AzureMonitorLogExporter, - AzureMonitorMetricExporter, - AzureMonitorTraceExporter) +from azure.monitor.opentelemetry.exporter import ( + AzureMonitorLogExporter, + AzureMonitorMetricExporter, + AzureMonitorTraceExporter, +) class TestAzureMonitorExporters(unittest.TestCase): diff --git a/azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py index f56559f..4663c98 100644 --- a/azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py +++ b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py @@ -19,4 +19,3 @@ class TestFlaskInstrumentation(unittest.TestCase): self.fail( f"Unexpected exception raised when instrumenting {FlaskInstrumentor.__name__}" ) - diff --git a/azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py index 31fc1c4..63bcd7d 100644 --- a/azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py +++ b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py @@ -18,4 +18,3 @@ class TestPsycopg2Instrumentation(unittest.TestCase): self.fail( f"Unexpected exception raised when instrumenting {Psycopg2Instrumentor.__name__}" ) - diff --git a/azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py index 8eab6fe..3c9697d 100644 --- a/azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py +++ b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py @@ -18,4 +18,3 @@ class TestRequestsInstrumentation(unittest.TestCase): self.fail( f"Unexpected exception raised when instrumenting {RequestsInstrumentor.__name__}" ) - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7034b90 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.black] +line-length = 79 +exclude = ''' +( + /( # generated files + .github| + .tox| + .vscode| + venv| + .*/build/lib/.*| + scripts + )/ +) +''' diff --git a/tox.ini b/tox.ini index 4422302..b979af3 100644 --- a/tox.ini +++ b/tox.ini @@ -25,8 +25,8 @@ commands_pre = python -m pip install -e {toxinidir}/azure-monitor-opentelemetry-distro commands = - black {toxinidir} - isort --recursive {toxinidir} + black --config pyproject.toml {toxinidir} --diff --check + isort --settings-path .isort.cfg {toxinidir} --diff --check-only + flake8 {toxinidir} ; TODO ; pylint {toxinidir} - flake8 {toxinidir}