Skip to content

Commit a79caa2

Browse files
FIX: pdoc cli ignoring virtual environment
fixes: pdoc3#44
1 parent a1f0a15 commit a79caa2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pdoc/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,26 @@ def main(_args=None):
299299
# Support loading modules specified as python paths relative to cwd
300300
sys.path.append(os.getcwd())
301301

302+
# Virtual Environment Handling for system pdoc cli
303+
try:
304+
# this will raise a KeyError if not in a virtual envitonment.
305+
venvPath = os.environ['VIRTUAL_ENV']
306+
# pdoc is installed in the current v.e., it will find v.e. local modules.
307+
if path.isdir(path.join(venvPath,
308+
'lib',
309+
'site-packages',
310+
'pdoc')):
311+
312+
pass
313+
else:
314+
# pdoc cli is running with system Python context despite being invoked in a v.e.
315+
sys.path.append(path.join(venvPath,
316+
'lib',
317+
'site-packages'))
318+
except KeyError:
319+
# pdoc cli was not invoked in a virtual environment
320+
pass
321+
302322
if args.http:
303323
args.html = True
304324
args.external_links = True

0 commit comments

Comments
 (0)