|
19 | 19 | import inspect |
20 | 20 | import io |
21 | 21 | import os |
22 | | -import subprocess |
| 22 | +import shutil |
23 | 23 | import sys |
24 | 24 | import typing as t |
25 | 25 | from pathlib import Path |
@@ -112,21 +112,17 @@ def manage_script(self) -> t.Union[str, Path]: |
112 | 112 | a manage.py script being invoked directly as a script. Completion should work in this case |
113 | 113 | as well, but it does complicate the installation for some shell's so we must first figure |
114 | 114 | out which mode we are in. |
| 115 | +
|
| 116 | + If this property returns a string the command is available as a command on the path. If it |
| 117 | + returns a path the command is available as a script but is not generally available on the |
| 118 | + path. |
115 | 119 | """ |
116 | 120 | cmd_pth = Path(sys.argv[0]) |
117 | | - if cmd_pth.exists(): |
118 | | - # manage.py might happen to be on the current path, but it might also be installed as |
119 | | - # a command - we test it here by invoking it to be sure |
120 | | - try: |
121 | | - subprocess.run( |
122 | | - [cmd_pth.name, "--help"], |
123 | | - check=True, |
124 | | - stdout=subprocess.PIPE, |
125 | | - stderr=subprocess.PIPE, |
126 | | - ) |
127 | | - except (subprocess.CalledProcessError, FileNotFoundError): |
128 | | - return cmd_pth.absolute() |
129 | | - return cmd_pth.name |
| 121 | + # manage.py might happen to be on the current path, but it might also be installed as |
| 122 | + # a command - we test it here using which to be sure |
| 123 | + if shutil.which(cmd_pth.name): |
| 124 | + return cmd_pth.name |
| 125 | + return cmd_pth.absolute() |
130 | 126 |
|
131 | 127 | @cached_property |
132 | 128 | def manage_script_name(self) -> str: |
@@ -610,3 +606,6 @@ def noop(self): |
610 | 606 | has no use other than to avoid any potential attribute access errors when we spoof |
611 | 607 | completion logic |
612 | 608 | """ |
| 609 | + import ipdb |
| 610 | + |
| 611 | + ipdb.set_trace() |
0 commit comments