Skip to content

Commit 1ee7261

Browse files
authored
Refactor bootstrap generation (#2101)
* Refactor bootstrap generation This makes the bootstrap script get the package version directly from pypi instead of from our lists of packages. This makes sure that the packages are actually available for the end user to install. Fixes #2053 * Fix lint * Fix lint * Remove aiohttp * Add missing dependency for aiohttp-client * Use hatch version
1 parent 2a174b2 commit 1ee7261

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py

-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
"library": "aiohttp ~= 3.0",
2525
"instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.46b0.dev",
2626
},
27-
{
28-
"library": "aiohttp ~= 3.0",
29-
"instrumentation": "opentelemetry-instrumentation-aiohttp-server==0.46b0.dev",
30-
},
3127
{
3228
"library": "aiopg >= 0.13.0, < 2.0.0",
3329
"instrumentation": "opentelemetry-instrumentation-aiopg==0.46b0.dev",
@@ -191,7 +187,6 @@
191187
"opentelemetry-instrumentation-dbapi==0.46b0.dev",
192188
"opentelemetry-instrumentation-logging==0.46b0.dev",
193189
"opentelemetry-instrumentation-sqlite3==0.46b0.dev",
194-
"opentelemetry-instrumentation-threading==0.46b0.dev",
195190
"opentelemetry-instrumentation-urllib==0.46b0.dev",
196191
"opentelemetry-instrumentation-wsgi==0.46b0.dev",
197192
]

scripts/otel_packaging.py

+29-17
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,55 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
16-
import subprocess
17-
from subprocess import CalledProcessError
15+
from tomli import load
16+
from os import path, listdir
17+
from subprocess import check_output, CalledProcessError
18+
from requests import get
1819

19-
import tomli
20-
21-
scripts_path = os.path.dirname(os.path.abspath(__file__))
22-
root_path = os.path.dirname(scripts_path)
23-
instrumentations_path = os.path.join(root_path, "instrumentation")
20+
scripts_path = path.dirname(path.abspath(__file__))
21+
root_path = path.dirname(scripts_path)
22+
instrumentations_path = path.join(root_path, "instrumentation")
2423

2524

2625
def get_instrumentation_packages():
27-
for pkg in sorted(os.listdir(instrumentations_path)):
28-
pkg_path = os.path.join(instrumentations_path, pkg)
29-
if not os.path.isdir(pkg_path):
26+
for pkg in sorted(listdir(instrumentations_path)):
27+
pkg_path = path.join(instrumentations_path, pkg)
28+
if not path.isdir(pkg_path):
3029
continue
3130

31+
error = f"Could not get version for package {pkg}"
32+
3233
try:
33-
version = subprocess.check_output(
34+
hatch_version = check_output(
3435
"hatch version",
3536
shell=True,
3637
cwd=pkg_path,
37-
universal_newlines=True,
38+
universal_newlines=True
3839
)
40+
3941
except CalledProcessError as exc:
4042
print(f"Could not get hatch version from path {pkg_path}")
4143
print(exc.output)
42-
raise exc
4344

44-
pyproject_toml_path = os.path.join(pkg_path, "pyproject.toml")
45+
try:
46+
response = get(f"https://pypi.org/pypi/{pkg}/json", timeout=10)
47+
48+
except Exception:
49+
print(error)
50+
continue
51+
52+
if response.status_code != 200:
53+
print(error)
54+
continue
55+
56+
pyproject_toml_path = path.join(pkg_path, "pyproject.toml")
4557

4658
with open(pyproject_toml_path, "rb") as file:
47-
pyproject_toml = tomli.load(file)
59+
pyproject_toml = load(file)
4860

4961
instrumentation = {
5062
"name": pyproject_toml["project"]["name"],
51-
"version": version.strip(),
63+
"version": hatch_version.strip(),
5264
"instruments": pyproject_toml["project"]["optional-dependencies"][
5365
"instruments"
5466
],

0 commit comments

Comments
 (0)