Skip to content

Commit 6753c87

Browse files
authored
Update tooling (#1330)
1 parent 273ae3c commit 6753c87

20 files changed

+112
-277
lines changed

.coveragerc

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[run]
22
omit =
33
*/tests/*
4-
*/setup.py
54
*/gen/*

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ exclude =
2121
docs/examples/opentelemetry-example-app/build/*
2222
opentelemetry-proto/build/*
2323
opentelemetry-proto/src/opentelemetry/proto/
24+
scripts/*

.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension-pkg-whitelist=
77

88
# Add list of files or directories to be excluded. They should be base names, not
99
# paths.
10-
ignore=CVS,gen,Dockerfile,docker-compose.yml,README.md,requirements.txt
10+
ignore=CVS,gen,Dockerfile,docker-compose.yml,README.md,requirements.txt,docs
1111

1212
# Add files or directories matching the regex patterns to be excluded. The
1313
# regex matches against base names, not paths.

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ Below is a checklist of things to be mindful of when implementing a new instrume
185185
- The instrumentation should follow the semantic conventions defined [here](https://github.com/open-telemetry/opentelemetry-specification/tree/main/semantic_conventions)
186186
- Extends from [BaseInstrumentor](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py#L26)
187187
- Supports auto-instrumentation
188-
- Add an entry point (ex. https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-requests/setup.cfg#L56)
189-
- Run `python scripts/setup.py` followed by `python scripts/generate_instrumentation_bootstrap.py` after adding a new instrumentation package.
188+
- Add an entry point (ex. https://github.com/open-telemetry/opentelemetry-python-contrib/blob/f045c43affff6ff1af8fa2f7514a4fdaca97dacf/instrumentation/opentelemetry-instrumentation-requests/pyproject.toml#L44)
189+
- Run `python scripts/generate_instrumentation_bootstrap.py` after adding a new instrumentation package.
190190
- Functionality that is common amongst other instrumentation and can be abstracted [here](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation)
191191
- Request/response [hooks](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/408) for http instrumentations
192192
- `suppress_instrumentation` functionality

docs/conf.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,11 @@ def getlistcfg(strval):
183183
scm_web = "https://github.com/" + REPO + "blob/" + branch
184184

185185
# Store variables in the epilogue so they are globally available.
186-
rst_epilog = """
187-
.. |SCM_WEB| replace:: {s}
188-
.. |SCM_RAW_WEB| replace:: {sr}
189-
.. |SCM_BRANCH| replace:: {b}
190-
""".format(
191-
s=scm_web, sr=scm_raw_web, b=branch
192-
)
186+
rst_epilog = f"""
187+
.. |SCM_WEB| replace:: {scm_web}
188+
.. |SCM_RAW_WEB| replace:: {scm_raw_web}
189+
.. |SCM_BRANCH| replace:: {branch}
190+
"""
193191

194192
# used to have links to repo files
195193
extlinks = {

gen-requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ markupsafe==2.0.1
55
isort
66
black
77
requests
8+
tomli
9+
tomli_w
10+
hatch
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,74 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = [
3+
"hatchling",
4+
]
35
build-backend = "hatchling.build"
46

57
[project]
68
name = "opentelemetry-contrib-instrumentations"
7-
dynamic = ["version"]
9+
dynamic = [
10+
"version",
11+
]
812
description = "OpenTelemetry Contrib Instrumentation Packages"
913
readme = "README.rst"
1014
license = "Apache-2.0"
1115
requires-python = ">=3.7"
1216
authors = [
13-
{ name = "OpenTelemetry Authors", email = "[email protected]" },
17+
{ name = "OpenTelemetry Authors", email = "[email protected]" },
1418
]
1519
classifiers = [
16-
"Development Status :: 4 - Beta",
17-
"Intended Audience :: Developers",
18-
"License :: OSI Approved :: Apache Software License",
19-
"Programming Language :: Python",
20-
"Programming Language :: Python :: 3",
21-
"Programming Language :: Python :: 3.7",
22-
"Programming Language :: Python :: 3.8",
23-
"Programming Language :: Python :: 3.9",
24-
"Programming Language :: Python :: 3.10",
20+
"Development Status :: 4 - Beta",
21+
"Intended Audience :: Developers",
22+
"License :: OSI Approved :: Apache Software License",
23+
"Programming Language :: Python",
24+
"Programming Language :: Python :: 3",
25+
"Programming Language :: Python :: 3.7",
26+
"Programming Language :: Python :: 3.8",
27+
"Programming Language :: Python :: 3.9",
28+
"Programming Language :: Python :: 3.10",
2529
]
2630
dependencies = [
27-
"opentelemetry-instrumentation-aio-pika==0.33b0",
28-
"opentelemetry-instrumentation-aiohttp-client==0.33b0",
29-
"opentelemetry-instrumentation-aiopg==0.33b0",
30-
"opentelemetry-instrumentation-asgi==0.33b0",
31-
"opentelemetry-instrumentation-asyncpg==0.33b0",
32-
"opentelemetry-instrumentation-aws-lambda==0.33b0",
33-
"opentelemetry-instrumentation-boto3sqs==0.33b0",
34-
"opentelemetry-instrumentation-boto==0.33b0",
35-
"opentelemetry-instrumentation-botocore==0.33b0",
36-
"opentelemetry-instrumentation-celery==0.33b0",
37-
"opentelemetry-instrumentation-confluent-kafka==0.33b0",
38-
"opentelemetry-instrumentation-dbapi==0.33b0",
39-
"opentelemetry-instrumentation-django==0.33b0",
40-
"opentelemetry-instrumentation-elasticsearch==0.33b0",
41-
"opentelemetry-instrumentation-falcon==0.33b0",
42-
"opentelemetry-instrumentation-fastapi==0.33b0",
43-
"opentelemetry-instrumentation-flask==0.33b0",
44-
"opentelemetry-instrumentation-grpc==0.33b0",
45-
"opentelemetry-instrumentation-httpx==0.33b0",
46-
"opentelemetry-instrumentation-jinja2==0.33b0",
47-
"opentelemetry-instrumentation-kafka-python==0.33b0",
48-
"opentelemetry-instrumentation-logging==0.33b0",
49-
"opentelemetry-instrumentation-mysql==0.33b0",
50-
"opentelemetry-instrumentation-pika==0.33b0",
51-
"opentelemetry-instrumentation-psycopg2==0.33b0",
52-
"opentelemetry-instrumentation-pymemcache==0.33b0",
53-
"opentelemetry-instrumentation-pymongo==0.33b0",
54-
"opentelemetry-instrumentation-pymysql==0.33b0",
55-
"opentelemetry-instrumentation-pyramid==0.33b0",
56-
"opentelemetry-instrumentation-redis==0.33b0",
57-
"opentelemetry-instrumentation-remoulade==0.33b0",
58-
"opentelemetry-instrumentation-requests==0.33b0",
59-
"opentelemetry-instrumentation-sklearn==0.33b0",
60-
"opentelemetry-instrumentation-sqlalchemy==0.33b0",
61-
"opentelemetry-instrumentation-sqlite3==0.33b0",
62-
"opentelemetry-instrumentation-starlette==0.33b0",
63-
"opentelemetry-instrumentation-system-metrics==0.33b0",
64-
"opentelemetry-instrumentation-tornado==0.33b0",
65-
"opentelemetry-instrumentation-urllib3==0.33b0",
66-
"opentelemetry-instrumentation-urllib==0.33b0",
67-
"opentelemetry-instrumentation-wsgi==0.33b0",
31+
"opentelemetry-instrumentation-aio-pika==0.33b0",
32+
"opentelemetry-instrumentation-aiohttp-client==0.33b0",
33+
"opentelemetry-instrumentation-aiopg==0.33b0",
34+
"opentelemetry-instrumentation-asgi==0.33b0",
35+
"opentelemetry-instrumentation-asyncpg==0.33b0",
36+
"opentelemetry-instrumentation-aws-lambda==0.33b0",
37+
"opentelemetry-instrumentation-boto==0.33b0",
38+
"opentelemetry-instrumentation-boto3sqs==0.33b0",
39+
"opentelemetry-instrumentation-botocore==0.33b0",
40+
"opentelemetry-instrumentation-celery==0.33b0",
41+
"opentelemetry-instrumentation-confluent-kafka==0.33b0",
42+
"opentelemetry-instrumentation-dbapi==0.33b0",
43+
"opentelemetry-instrumentation-django==0.33b0",
44+
"opentelemetry-instrumentation-elasticsearch==0.33b0",
45+
"opentelemetry-instrumentation-falcon==0.33b0",
46+
"opentelemetry-instrumentation-fastapi==0.33b0",
47+
"opentelemetry-instrumentation-flask==0.33b0",
48+
"opentelemetry-instrumentation-grpc==0.33b0",
49+
"opentelemetry-instrumentation-httpx==0.33b0",
50+
"opentelemetry-instrumentation-jinja2==0.33b0",
51+
"opentelemetry-instrumentation-kafka-python==0.33b0",
52+
"opentelemetry-instrumentation-logging==0.33b0",
53+
"opentelemetry-instrumentation-mysql==0.33b0",
54+
"opentelemetry-instrumentation-pika==0.33b0",
55+
"opentelemetry-instrumentation-psycopg2==0.33b0",
56+
"opentelemetry-instrumentation-pymemcache==0.33b0",
57+
"opentelemetry-instrumentation-pymongo==0.33b0",
58+
"opentelemetry-instrumentation-pymysql==0.33b0",
59+
"opentelemetry-instrumentation-pyramid==0.33b0",
60+
"opentelemetry-instrumentation-redis==0.33b0",
61+
"opentelemetry-instrumentation-remoulade==0.33b0",
62+
"opentelemetry-instrumentation-requests==0.33b0",
63+
"opentelemetry-instrumentation-sklearn==0.33b0",
64+
"opentelemetry-instrumentation-sqlalchemy==0.33b0",
65+
"opentelemetry-instrumentation-sqlite3==0.33b0",
66+
"opentelemetry-instrumentation-starlette==0.33b0",
67+
"opentelemetry-instrumentation-system-metrics==0.33b0",
68+
"opentelemetry-instrumentation-tornado==0.33b0",
69+
"opentelemetry-instrumentation-urllib==0.33b0",
70+
"opentelemetry-instrumentation-urllib3==0.33b0",
71+
"opentelemetry-instrumentation-wsgi==0.33b0",
6872
]
6973

7074
[project.optional-dependencies]
@@ -78,8 +82,10 @@ path = "src/opentelemetry/contrib-instrumentations/version.py"
7882

7983
[tool.hatch.build.targets.sdist]
8084
include = [
81-
"/src",
85+
"/src",
8286
]
8387

8488
[tool.hatch.build.targets.wheel]
85-
packages = ["src/opentelemetry"]
89+
packages = [
90+
"src/opentelemetry",
91+
]

opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def is_instrumented_by_opentelemetry(self):
6060
def instrumentation_dependencies(self) -> Collection[str]:
6161
"""Return a list of python packages with versions that the will be instrumented.
6262
63-
The format should be the same as used in requirements.txt or setup.py.
63+
The format should be the same as used in requirements.txt or pyproject.toml.
6464
6565
For example, if an instrumentation instruments requests 1.x, this method should look
6666
like:

scripts/build.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
set -ev
77

88
# Get the latest versions of packaging tools
9-
python3 -m pip install --upgrade pip setuptools wheel
9+
python3 -m pip install --upgrade pip build setuptools wheel
1010

1111
BASEDIR=$(dirname $(readlink -f $(dirname $0)))
1212
DISTDIR=dist
@@ -21,9 +21,9 @@ DISTDIR=dist
2121
echo "building $d"
2222
cd "$d"
2323
# Some ext directories (such as docker tests) are not intended to be
24-
# packaged. Verify the intent by looking for a setup.py.
25-
if [ -f setup.py ]; then
26-
python3 setup.py sdist --dist-dir "$BASEDIR/dist/" clean --all
24+
# packaged. Verify the intent by looking for a pyproject.toml.
25+
if [ -f pyproject.toml ]; then
26+
python3 -m build --outdir "$BASEDIR/dist/"
2727
fi
2828
)
2929
done

scripts/build_a_package.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ distdir=${basedir}/dist
4242
mkdir -p $distdir
4343
rm -rf $distdir/*
4444

45-
setup_py_file_path=$(ls **/$pkg_name/setup.py)
45+
pyproject_toml_file_path=$(ls **/$pkg_name/pyproject.toml)
4646

47-
if [ -z $setup_py_file_path ]; then
48-
echo "Error! setup.py not found for $pkg_name, can't build."
47+
if [ -z $pyproject_toml_file_path ]; then
48+
echo "Error! pyproject.toml not found for $pkg_name, can't build."
4949
exit -1
5050
fi
5151

52-
directory_with_package=$(dirname $setup_py_file_path)
52+
directory_with_package=$(dirname $pyproject_toml_file_path)
5353

5454
cd $directory_with_package
5555

56-
python3 setup.py sdist --dist-dir ${distdir} clean --all
56+
python3 -m build --outdir ${distdir}
5757

5858
cd $distdir
5959

scripts/check_for_valid_readme.py

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def main():
3636
print("FAILED: RST syntax errors in", readme)
3737
continue
3838
except FileNotFoundError:
39-
error = True
4039
print("FAILED: README.rst not found in", path)
4140
continue
4241
if args.verbose:

scripts/coverage.sh

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -e
44

55
function cov {
66
pytest \
7-
--ignore-glob=*/setup.py \
87
--cov ${1} \
98
--cov-append \
109
--cov-branch \

scripts/eachdist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def parse_args(args=None):
8383
commands according to `format` and `--all`.
8484
8585
Target paths are initially all Python distribution root paths
86-
(as determined by the existence of setup.py, etc. files).
86+
(as determined by the existence of pyproject.toml, etc. files).
8787
They are then augmented according to the section of the
8888
`PROJECT_ROOT/eachdist.ini` config file specified by the `--mode` option.
8989
@@ -282,7 +282,7 @@ def find_targets_unordered(rootpath):
282282
continue
283283
if any(
284284
(subdir / marker).exists()
285-
for marker in ("setup.py", "pyproject.toml")
285+
for marker in ("pyproject.toml")
286286
):
287287
yield subdir
288288
else:

scripts/generate_instrumentation_bootstrap.py

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
logging.basicConfig(level=logging.INFO)
3232
logger = logging.getLogger("instrumentation_list_generator")
3333

34-
_auto_generation_msg = """
35-
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/{source}.
36-
# RUN `python scripts/generate_setup.py` TO REGENERATE.
37-
"""
38-
3934
_template = """
4035
{header}
4136

scripts/generate_instrumentation_metapackage.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
import logging
1818
import os
19-
from configparser import ConfigParser
19+
20+
import tomli
21+
import tomli_w
2022

2123
logging.basicConfig(level=logging.INFO)
2224
logger = logging.getLogger("instrumentation_metapackage_generator")
@@ -65,17 +67,17 @@ def get_instrumentation_packages():
6567
def main():
6668
dependencies = get_instrumentation_packages()
6769

68-
setup_cfg_path = os.path.join(
69-
root_path, "opentelemetry-contrib-instrumentations", "setup.cfg"
70+
pyproject_toml_path = os.path.join(
71+
root_path, "opentelemetry-contrib-instrumentations", "pyproject.toml"
7072
)
71-
config = ConfigParser()
72-
config.read(setup_cfg_path)
7373

74-
deps = "\n".join(f"{pkg}=={version}" for pkg, version in dependencies)
74+
deps = [f"{pkg}=={version}" for pkg, version in dependencies]
75+
with open(pyproject_toml_path, "rb") as file:
76+
pyproject_toml = tomli.load(file)
7577

76-
config["options"]["install_requires"] = "\n" + deps
77-
with open(setup_cfg_path, "w", encoding="utf-8") as fh:
78-
config.write(fh)
78+
pyproject_toml["project"]["dependencies"] = deps
79+
with open(pyproject_toml_path, "wb") as fh:
80+
tomli_w.dump(pyproject_toml, fh)
7981

8082

8183
if __name__ == "__main__":

0 commit comments

Comments
 (0)