diff --git a/.flake8 b/.flake8 index d31ad36e..6180ee0a 100644 --- a/.flake8 +++ b/.flake8 @@ -1,9 +1,17 @@ [flake8] ignore = - E501 # line too long, defer to black - W503 # allow line breaks before binary ops - W504 # allow line breaks after binary ops - E203 # allow whitespace before ':' (https://github.com/psf/black#slices) + # line too long, defer to black + E501 + + # allow line breaks before binary ops + W503 + + # allow line breaks after binary ops + W504 + + # allow whitespace before ':' (https://github.com/psf/black#slices) + E203 + exclude = .bzr .git @@ -15,3 +23,4 @@ exclude = venv*/ target __pycache__ + */build/lib/* diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..31658510 --- /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 797a3fe9..461b1fdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ([#205](https://github.com/microsoft/ApplicationInsights-Python/pull/205)) - Update CONTRIBUTING.md, support Py3.11 ([#210](https://github.com/microsoft/ApplicationInsights-Python/pull/210)) +- Updated setup.py, directory structure + ([#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/__init__.py b/azure-monitor-opentelemetry-distro/azure/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/__init__.py b/azure-monitor-opentelemetry-distro/azure/monitor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/__init__.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/__init__.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/azure-monitor-opentelemetry-distro/src/azure/monitor/opentelemetry/distro/version.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py similarity index 100% rename from azure-monitor-opentelemetry-distro/src/azure/monitor/opentelemetry/distro/version.py rename to azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py diff --git a/azure-monitor-opentelemetry-distro/src/azure/monitor/opentelemetry/distro/configurator.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/configurator.py similarity index 100% rename from azure-monitor-opentelemetry-distro/src/azure/monitor/opentelemetry/distro/configurator.py rename to azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/configurator.py diff --git a/azure-monitor-opentelemetry-distro/src/azure/monitor/opentelemetry/distro/distro.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py similarity index 75% rename from azure-monitor-opentelemetry-distro/src/azure/monitor/opentelemetry/distro/distro.py rename to azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py index dddc3518..e11c765e 100644 --- a/azure-monitor-opentelemetry-distro/src/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 @@ def _configure(self, **kwargs): 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/samples/simple.py b/azure-monitor-opentelemetry-distro/samples/simple.py new file mode 100644 index 00000000..9853862d --- /dev/null +++ b/azure-monitor-opentelemetry-distro/samples/simple.py @@ -0,0 +1,10 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License in the project root for +# license information. +# -------------------------------------------------------------------------- + +from azure.monitor.opentelemetry.distro.distro import AzureMonitorDistro + +distro = AzureMonitorDistro() +distro.configure() diff --git a/azure-monitor-opentelemetry-distro/setup.cfg b/azure-monitor-opentelemetry-distro/setup.cfg index b2f391f9..3c6e79cf 100644 --- a/azure-monitor-opentelemetry-distro/setup.cfg +++ b/azure-monitor-opentelemetry-distro/setup.cfg @@ -1,49 +1,2 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License in the project root for -# license information. -# -------------------------------------------------------------------------- -[metadata] -name = azure-monitor-opentelemetry-distro -description = Azure Monitor Distro for OpenTelemetry Python -long_description = file: README.md -long_description_content_type = text/markdown -author = Microsoft Corporation -url = https://github.com/microsoft/ApplicationInsights-Python -platforms = any -license = MIT License -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 - Typing :: Typed - -[options] -python_requires = >=3.7 -package_dir= - =src -packages=find_namespace: -zip_safe = False -include_package_data = True -install_requires = - azure-monitor-opentelemetry-exporter == 1.0.0b8 - opentelemetry-instrumentation ~= 0.35b0 - opentelemetry-instrumentation-django ~= 0.35b0 - opentelemetry-instrumentation-requests ~= 0.35b0 - opentelemetry-instrumentation-flask ~= 0.35b0 - opentelemetry-instrumentation-psycopg2 ~= 0.35b0 - -[options.packages.find] -where = src - -[options.entry_points] -opentelemetry_distro = - azure_monitor_opentelemetry_distro = azure.monitor.opentelemetry.distro.distro:AzureMonitorDistro -opentelemetry_configurator = - azure_monitor_opentelemetry_configurator = azure.monitor.opentelemetry.distro.configurator:AzureMonitorConfigurator +[bdist_wheel] +universal=1 diff --git a/azure-monitor-opentelemetry-distro/setup.py b/azure-monitor-opentelemetry-distro/setup.py index f730dd77..7ef63ee5 100644 --- a/azure-monitor-opentelemetry-distro/setup.py +++ b/azure-monitor-opentelemetry-distro/setup.py @@ -1,21 +1,103 @@ +#!/usr/bin/env python + # ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License in the project root for +# Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- + import os +import re -import setuptools +from setuptools import find_packages, setup -BASE_DIR = os.path.dirname(__file__) -VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "azure", "monitor", "opentelemetry", "distro", "version.py" -) -PACKAGE_INFO = {} -with open(VERSION_FILENAME, encoding="utf-8") as f: - exec(f.read(), PACKAGE_INFO) +# 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("-", "/") + + +# azure v0.x is not compatible with this package +# azure v0.x used to have a __version__ attribute (newer versions don't) +try: + import azure + + try: + ver = azure.__version__ + raise Exception( + "This package is incompatible with azure=={}. ".format(ver) + + 'Uninstall it with "pip uninstall azure".' + ) + except AttributeError: + pass +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) + +if not version: + raise RuntimeError("Cannot find version information") -setuptools.setup( - version=PACKAGE_INFO["VERSION"], +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", + 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", + ], + 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", + ] + ), + include_package_data=True, + package_data={ + "pytyped": ["py.typed"], + }, + python_requires=">=3.7", + install_requires=[ + "azure-monitor-opentelemetry-exporter>=1.0.0b11", + "opentelemetry-instrumentation~=0.35b0", + "opentelemetry-instrumentation-django~=0.35b0", + "opentelemetry-instrumentation-requests~=0.35b0", + "opentelemetry-instrumentation-flask~=0.35b0", + "opentelemetry-instrumentation-psycopg2~=0.35b0", + ], + entry_points={ + "opentelemetry_distro": [ + "azure_monitor_opentelemetry_distro = azure.monitor.opentelemetry.distro.distro:AzureMonitorDistro" + ], + "opentelemetry_configurator": [ + "azure_monitor_opentelemetry_configurator = azure.monitor.opentelemetry.distro.configurator:AzureMonitorConfigurator" + ], + }, ) diff --git a/tests/test_exporter.py b/azure-monitor-opentelemetry-distro/tests/exporter/test_exporter.py similarity index 84% rename from tests/test_exporter.py rename to azure-monitor-opentelemetry-distro/tests/exporter/test_exporter.py index f2963a07..21561ac5 100644 --- a/tests/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/test_flask.py b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py similarity index 63% rename from azure-monitor-opentelemetry-distro/tests/test_flask.py rename to azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py index 27601c76..4663c98e 100644 --- a/azure-monitor-opentelemetry-distro/tests/test_flask.py +++ b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_flask.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License in the project root for +# license information. +# -------------------------------------------------------------------------- + import unittest from opentelemetry.instrumentation.flask import FlaskInstrumentor @@ -13,4 +19,3 @@ def test_instrument(self): self.fail( f"Unexpected exception raised when instrumenting {FlaskInstrumentor.__name__}" ) - diff --git a/azure-monitor-opentelemetry-distro/tests/test_psycopg2.py b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py similarity index 60% rename from azure-monitor-opentelemetry-distro/tests/test_psycopg2.py rename to azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py index 794be58c..63bcd7dc 100644 --- a/azure-monitor-opentelemetry-distro/tests/test_psycopg2.py +++ b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_psycopg2.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License in the project root for +# license information. +# -------------------------------------------------------------------------- + import unittest from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor @@ -12,4 +18,3 @@ def test_instrument(self): self.fail( f"Unexpected exception raised when instrumenting {Psycopg2Instrumentor.__name__}" ) - diff --git a/azure-monitor-opentelemetry-distro/tests/test_requests.py b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py similarity index 60% rename from azure-monitor-opentelemetry-distro/tests/test_requests.py rename to azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py index 1328bf4b..3c9697d8 100644 --- a/azure-monitor-opentelemetry-distro/tests/test_requests.py +++ b/azure-monitor-opentelemetry-distro/tests/instrumentation/test_requests.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License in the project root for +# license information. +# -------------------------------------------------------------------------- + import unittest from opentelemetry.instrumentation.requests import RequestsInstrumentor @@ -12,4 +18,3 @@ def test_instrument(self): self.fail( f"Unexpected exception raised when instrumenting {RequestsInstrumentor.__name__}" ) - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..7034b902 --- /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 44223021..8e2f8937 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 --config .flake8 {toxinidir} ; TODO ; pylint {toxinidir} - flake8 {toxinidir}