Skip to content

Commit a5ed8fd

Browse files
authored
Merge pull request #125 from AndreasGocht/master
using our own `abspath` function as `os.path.abspath` might fail during shutdown. See https://bugs.python.org/msg315588 for more details.
2 parents d7cf1c7 + c0612be commit a5ed8fd

5 files changed

Lines changed: 88 additions & 55 deletions

File tree

scorep/_instrumenters/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import os
1+
from scorep._bindings import abspath
22

33

44
def get_module_name(frame):
55
"""Get the name of the module the given frame resides in"""
6-
modulename = frame.f_globals.get('__name__', None)
6+
modulename = frame.f_globals.get("__name__", None)
77
if modulename is None:
88
# this is a NUMPY special situation, see NEP-18, and Score-P Issue
99
# issues #63
@@ -18,7 +18,7 @@ def get_file_name(frame):
1818
"""Get the full path to the file the given frame resides in"""
1919
file_name = frame.f_code.co_filename
2020
if file_name is not None:
21-
full_file_name = os.path.abspath(file_name)
21+
full_file_name = abspath(file_name)
2222
else:
2323
full_file_name = "None"
2424
return full_file_name

scorep/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.3.0"
1+
__version__ = "3.3.1"

setup.py

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,92 @@
55
from scorep.instrumenter import has_c_instrumenter
66

77
if scorep.helper.get_scorep_version() < 5.0:
8-
raise RuntimeError(
9-
"Score-P version less than 5.0, plase use Score-P >= 5.0")
8+
raise RuntimeError("Score-P version less than 5.0, plase use Score-P >= 5.0")
109

1110
link_mode = scorep.helper.get_scorep_config("Link mode:")
1211
if not ("shared=yes" in link_mode):
1312
raise RuntimeError(
14-
"Score-P not build with \"--enable-shared\". Link mode is:\n{}".format(link_mode))
13+
'Score-P not build with "--enable-shared". Link mode is:\n{}'.format(link_mode)
14+
)
1515

1616
check_compiler = scorep.helper.get_scorep_config("C99 compiler used:")
1717
if "gcc" in check_compiler:
1818
gcc_plugin = scorep.helper.get_scorep_config("GCC plug-in support:")
1919
if not ("yes" in gcc_plugin):
20-
raise RuntimeError("Score-P uses GCC but is not build with GCC Compiler Plugin. "
21-
"GCC plug-in support is:\n{}".format(gcc_plugin))
20+
raise RuntimeError(
21+
"Score-P uses GCC but is not build with GCC Compiler Plugin. "
22+
"GCC plug-in support is:\n{}".format(gcc_plugin)
23+
)
2224

2325

2426
cmodules = []
2527
(include, _, _, _, _) = scorep.helper.generate_compile_deps([])
26-
src_folder = os.path.abspath('src')
28+
src_folder = os.path.abspath("src")
2729
include += [src_folder]
28-
sources = ['src/methods.cpp', 'src/scorep_bindings.cpp', 'src/scorepy/events.cpp']
29-
define_macros = [('PY_SSIZE_T_CLEAN', '1')]
30+
sources = [
31+
"src/methods.cpp",
32+
"src/scorep_bindings.cpp",
33+
"src/scorepy/events.cpp",
34+
"src/scorepy/pathUtils.cpp",
35+
]
36+
define_macros = [("PY_SSIZE_T_CLEAN", "1")]
3037
# We are using the UTF-8 string features from Python 3
3138
# The C Instrumenter functions are not available on PyPy
3239
if has_c_instrumenter():
33-
sources.extend([
34-
'src/classes.cpp',
35-
'src/scorepy/cInstrumenter.cpp',
36-
'src/scorepy/pythonHelpers.cpp',
37-
'src/scorepy/pathUtils.cpp',
38-
])
39-
define_macros.append(('SCOREPY_ENABLE_CINSTRUMENTER', '1'))
40+
sources.extend(
41+
[
42+
"src/classes.cpp",
43+
"src/scorepy/cInstrumenter.cpp",
44+
"src/scorepy/pythonHelpers.cpp",
45+
]
46+
)
47+
define_macros.append(("SCOREPY_ENABLE_CINSTRUMENTER", "1"))
4048
else:
41-
define_macros.append(('SCOREPY_ENABLE_CINSTRUMENTER', '0'))
49+
define_macros.append(("SCOREPY_ENABLE_CINSTRUMENTER", "0"))
4250

43-
cmodules.append(Extension('scorep._bindings',
44-
include_dirs=include,
45-
define_macros=define_macros,
46-
extra_compile_args=["-std=c++11"],
47-
sources=sources))
51+
cmodules.append(
52+
Extension(
53+
"scorep._bindings",
54+
include_dirs=include,
55+
define_macros=define_macros,
56+
extra_compile_args=["-std=c++11"],
57+
sources=sources,
58+
)
59+
)
4860

4961
setup(
50-
name='scorep',
62+
name="scorep",
5163
version=scorep._version.__version__,
52-
description='This is a Score-P tracing package for python',
53-
author='Andreas Gocht',
54-
author_email='andreas.gocht@tu-dresden.de',
55-
url='https://github.com/score-p/scorep_binding_python',
56-
long_description='''
64+
description="This is a Score-P tracing package for python",
65+
author="Andreas Gocht",
66+
author_email="andreas.gocht@tu-dresden.de",
67+
url="https://github.com/score-p/scorep_binding_python",
68+
long_description="""
5769
This package allows tracing of python code using Score-P.
5870
A working Score-P version is required.
5971
To enable tracing it uses LD_PRELOAD to load the Score-P runtime libraries.
6072
Besides this, it uses the traditional python-tracing infrastructure.
61-
''',
62-
packages=['scorep', 'scorep._instrumenters'],
73+
""",
74+
packages=["scorep", "scorep._instrumenters"],
6375
ext_modules=cmodules,
6476
classifiers=[
65-
'Development Status :: 4 - Beta',
66-
'Environment :: Console',
67-
'Intended Audience :: Developers',
68-
'Topic :: Software Development :: Testing',
69-
'Topic :: Software Development :: Quality Assurance',
70-
'Programming Language :: Python :: 2',
71-
'Programming Language :: Python :: 2.7',
72-
'Programming Language :: Python :: 3',
73-
'Programming Language :: Python :: 3.4',
74-
'Programming Language :: Python :: 3.5',
75-
'Programming Language :: Python :: 3.6',
76-
'Programming Language :: Python :: 3.7',
77-
'Programming Language :: Python :: 3.8',
78-
'Programming Language :: Python :: 3.9',
79-
'Programming Language :: Python :: Implementation :: CPython',
80-
'Programming Language :: Python :: Implementation :: PyPy',
81-
'Operating System :: POSIX',
82-
'Operating System :: Unix',
77+
"Development Status :: 4 - Beta",
78+
"Environment :: Console",
79+
"Intended Audience :: Developers",
80+
"Topic :: Software Development :: Testing",
81+
"Topic :: Software Development :: Quality Assurance",
82+
"Programming Language :: Python :: 2",
83+
"Programming Language :: Python :: 2.7",
84+
"Programming Language :: Python :: 3",
85+
"Programming Language :: Python :: 3.4",
86+
"Programming Language :: Python :: 3.5",
87+
"Programming Language :: Python :: 3.6",
88+
"Programming Language :: Python :: 3.7",
89+
"Programming Language :: Python :: 3.8",
90+
"Programming Language :: Python :: 3.9",
91+
"Programming Language :: Python :: Implementation :: CPython",
92+
"Programming Language :: Python :: Implementation :: PyPy",
93+
"Operating System :: POSIX",
94+
"Operating System :: Unix",
8395
],
8496
)

src/methods.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "methods.hpp"
22
#include "scorepy/events.hpp"
3+
#include "scorepy/pathUtils.hpp"
34
#include <Python.h>
45
#include <cstdint>
56
#include <scorep/SCOREP_User_Functions.h>
@@ -180,6 +181,16 @@ extern "C"
180181
return PyUnicode_FromString(SCOREP_GetExperimentDirName());
181182
}
182183

184+
static PyObject* abspath(PyObject* self, PyObject* args)
185+
{
186+
const char* path;
187+
188+
if (!PyArg_ParseTuple(args, "s", &path))
189+
return NULL;
190+
191+
return PyUnicode_FromString(scorepy::abspath(path).c_str());
192+
}
193+
183194
static PyMethodDef ScorePMethods[] = {
184195
{ "region_begin", region_begin, METH_VARARGS, "enter a region." },
185196
{ "region_end", region_end, METH_VARARGS, "exit a region." },
@@ -194,6 +205,7 @@ extern "C"
194205
{ "parameter_string", parameter_string, METH_VARARGS, "User parameter string." },
195206
{ "get_experiment_dir_name", get_experiment_dir_name, METH_VARARGS,
196207
"Get the Score-P experiment dir." },
208+
{ "abspath", abspath, METH_VARARGS, "Estimates the absolute Path." },
197209
{ NULL, NULL, 0, NULL } /* Sentinel */
198210
};
199211
}

test/test_scorep.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ def call(arguments, expected_returncode=0, env=None):
1919
arguments, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
2020
)
2121
print(out.stdout, out.stderr)
22-
assert out.returncode == expected_returncode
22+
try:
23+
assert out.returncode == expected_returncode
24+
except AssertionError as e:
25+
e.args += ("stderr: {}".format(out.stderr.decode("utf-8")),)
26+
raise
2327
stdout, stderr = (out.stdout, out.stderr)
2428
else:
2529
p = subprocess.Popen(
2630
arguments, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
2731
)
2832
stdout, stderr = p.communicate()
29-
assert p.returncode == expected_returncode
33+
try:
34+
assert p.returncode == expected_returncode
35+
except AssertionError as e:
36+
e.args += ("stderr: {}".format(stderr.decode("utf-8")),)
37+
raise
3038
return stdout.decode("utf-8"), stderr.decode("utf-8")
3139

3240

@@ -51,8 +59,8 @@ def requires_package(name):
5159

5260

5361
cinstrumenter_skip_mark = pytest.mark.skipif(
54-
sys.version_info.major < 3 or platform.python_implementation() == 'PyPy',
55-
reason="CInstrumenter only available in Python 3 and not in PyPy"
62+
sys.version_info.major < 3 or platform.python_implementation() == "PyPy",
63+
reason="CInstrumenter only available in Python 3 and not in PyPy",
5664
)
5765
# All instrumenters (except dummy which isn't a real one)
5866
ALL_INSTRUMENTERS = [
@@ -90,6 +98,7 @@ def test_has_version():
9098
@cinstrumenter_skip_mark
9199
def test_has_c_instrumenter():
92100
from scorep.instrumenter import has_c_instrumenter
101+
93102
assert has_c_instrumenter()
94103

95104

0 commit comments

Comments
 (0)