|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
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 |
18 | 19 |
|
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") |
24 | 23 |
|
25 | 24 |
|
26 | 25 | 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): |
30 | 29 | continue
|
31 | 30 |
|
| 31 | + error = f"Could not get version for package {pkg}" |
| 32 | + |
32 | 33 | try:
|
33 |
| - version = subprocess.check_output( |
| 34 | + hatch_version = check_output( |
34 | 35 | "hatch version",
|
35 | 36 | shell=True,
|
36 | 37 | cwd=pkg_path,
|
37 |
| - universal_newlines=True, |
| 38 | + universal_newlines=True |
38 | 39 | )
|
| 40 | + |
39 | 41 | except CalledProcessError as exc:
|
40 | 42 | print(f"Could not get hatch version from path {pkg_path}")
|
41 | 43 | print(exc.output)
|
42 |
| - raise exc |
43 | 44 |
|
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") |
45 | 57 |
|
46 | 58 | with open(pyproject_toml_path, "rb") as file:
|
47 |
| - pyproject_toml = tomli.load(file) |
| 59 | + pyproject_toml = load(file) |
48 | 60 |
|
49 | 61 | instrumentation = {
|
50 | 62 | "name": pyproject_toml["project"]["name"],
|
51 |
| - "version": version.strip(), |
| 63 | + "version": hatch_version.strip(), |
52 | 64 | "instruments": pyproject_toml["project"]["optional-dependencies"][
|
53 | 65 | "instruments"
|
54 | 66 | ],
|
|
0 commit comments