@@ -209,10 +209,14 @@ def changelog(
209209@show_command ()
210210def requirements (no_pager : bool = False , depth : int = - 1 ):
211211 """
212- Lists the requirements of this library, and their dependencies
212+ Lists the requirements of this library, and their dependencies.
213213 """
214214
215+ # stdlib
216+ import shutil
217+
215218 # 3rd party
219+ from domdf_python_tools .compat import importlib_metadata
216220 from domdf_python_tools .iterative import make_tree
217221 from domdf_python_tools .paths import PathPlus
218222 from domdf_python_tools .stringlist import StringList
@@ -225,6 +229,16 @@ def requirements(no_pager: bool = False, depth: int = -1):
225229 buf = StringList ([f"{ rh .templates .globals ['pypi_name' ]} =={ rh .templates .globals ['version' ]} " ])
226230 raw_requirements = sorted (read_requirements ("requirements.txt" )[0 ])
227231 tree : List [Union [str , List [str ], List [Union [str , List ]]]] = []
232+ venv_dir = (rh .target_repo / "venv" )
233+
234+ if venv_dir .is_dir ():
235+ # Use virtualenv as it exists
236+ search_path = []
237+
238+ for directory in (venv_dir / "lib" ).glob ("python3.*" ):
239+ search_path .append (str (directory / "site-packages" ))
240+
241+ importlib_metadata .DistributionFinder .Context .path = search_path
228242
229243 for requirement in raw_requirements :
230244 tree .append (str (requirement ))
@@ -234,6 +248,10 @@ def requirements(no_pager: bool = False, depth: int = -1):
234248
235249 buf .extend (make_tree (tree ))
236250
251+ if shutil .get_terminal_size ().lines >= len (buf ):
252+ # Don't use pager if fewer lines that terminal height
253+ no_pager = True
254+
237255 if no_pager :
238256 click .echo (str (buf ))
239257 else :
0 commit comments