Skip to content

Commit 4073419

Browse files
Fix issues related to Path.parent with no parent directory (#1434)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent ac38993 commit 4073419

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

newrelic/admin/run_program.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,18 @@ def log_message(text, *args):
9999
# be found in current working directory even though '.'
100100
# not in PATH.
101101

102-
program_exe_path = Path(args[0])
102+
program_exe_path = args[0]
103103

104-
if not program_exe_path.parent:
104+
# Don't use path.parent, as it can't distinguish between ./ and no parent.
105+
if not os.path.dirname(program_exe_path): # noqa: PTH120
105106
program_search_path = os.environ.get("PATH", "").split(os.pathsep)
106107
for path in program_search_path:
107108
path = Path(path) / program_exe_path
108109
if path.exists() and os.access(path, os.X_OK):
109-
program_exe_path = path
110+
program_exe_path = str(path) # Convert to str to match other code path
110111
break
111112

112-
log_message("program_exe_path = %r", str(program_exe_path))
113+
log_message("program_exe_path = %r", program_exe_path)
113114
log_message("execl_arguments = %r", [program_exe_path, *args])
114115

115116
os.execl(program_exe_path, *args) # noqa: S606

newrelic/admin/run_python.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ def log_message(text, *args):
9696
# this script in preference to that used to execute this
9797
# script.
9898

99-
bin_directory = Path(sys.argv[0]).parent
99+
argv_executable = sys.argv[0]
100100

101+
# Don't use path.parent, as it can't distinguish between ./ and no parent.
102+
bin_directory = os.path.dirname(argv_executable) # noqa: PTH120
101103
if bin_directory:
102104
python_exe = Path(sys.executable).name
103-
python_exe_path = bin_directory / python_exe
105+
python_exe_path = Path(bin_directory) / python_exe
104106
if not python_exe_path.exists() or not os.access(python_exe_path, os.X_OK):
105-
python_exe_path = sys.executable
107+
python_exe_path = Path(sys.executable)
106108
else:
107-
python_exe_path = sys.executable
109+
python_exe_path = Path(sys.executable)
108110

109111
log_message("python_exe_path = %r", str(python_exe_path))
110112
log_message("execl_arguments = %r", [python_exe_path, python_exe_path, *args])

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ def newrelic_agent_next_version(version):
8484

8585

8686
script_directory = Path(__file__).parent
87-
if not script_directory:
88-
script_directory = Path(os.getcwd())
8987

9088
readme_file = script_directory / "README.md"
9189
with readme_file.open() as f:

0 commit comments

Comments
 (0)