@@ -33,15 +33,63 @@ def ensure_site_env(name: str) -> str:
3333 return fullname
3434
3535
36- def install_package (
36+ def install_in_rhino_with_pip (
3737 packages : list [str ],
3838 requirements : Optional [str ] = None ,
3939 env : str = "default" ,
4040 upgrade : bool = False ,
4141 deps : bool = True ,
4242 clear : bool = False ,
4343):
44- """Install a package with Rhino's CPython pip."""
44+ """Install a package with Rhino's CPython pip.
45+
46+ Parameters
47+ ----------
48+ packages : list of str
49+ The package(s) to install (PyPI names or local package paths).
50+ requirements : str, optional
51+ Path to a requirements file.
52+ env : str, optional
53+ Name of the site env, without the random suffix.
54+ upgrade : bool, optional
55+ Attempt to upgrade packages already installed.
56+ deps : bool, optional
57+ If False, do not install dependencies.
58+ clear : bool, optional
59+ If True, clear the environment before installing.
60+
61+ Returns
62+ -------
63+ int
64+ The return code from the pip install command.
65+
66+ Raises
67+ ------
68+ ValueError
69+ If both packages and requirements are provided, or if neither are provided.
70+
71+ Examples
72+ --------
73+ >>> install_in_rhino_with_pip(packages=["requests"], env="myenv", upgrade=True)
74+ >>> install_in_rhino_with_pip(requirements="requirements.txt", env="myenv")
75+ >>> install_in_rhino_with_pip(packages=["."], env="myenv")
76+ >>> install_in_rhino_with_pip(packages=[".."], env="myenv")
77+
78+ Notes
79+ -----
80+ This function is made available as a command line script under the name `install_in_rhino`.
81+ On the command line you can use the following syntax
82+
83+ .. code-block:: bash
84+
85+ install_in_rhino requests numpy
86+ install_in_rhino -r requirements.txt --env myenv --upgrade
87+ install_in_rhino . --env myenv
88+ install_in_rhino .. --env myenv
89+ install_in_rhino -r requirements.txt --env myenv --no-deps
90+ install_in_rhino requests --env myenv --clear
91+
92+ """
4593
4694 if requirements and packages :
4795 raise ValueError ("You must provide either packages or a requirements file, not both." )
@@ -103,7 +151,7 @@ def main():
103151 parser .set_defaults (deps = True )
104152 args = parser .parse_args ()
105153
106- install_package (
154+ install_in_rhino_with_pip (
107155 packages = args .packages ,
108156 requirements = args .requirements ,
109157 env = args .env ,
@@ -113,5 +161,9 @@ def main():
113161 )
114162
115163
164+ # =============================================================================
165+ # Main
166+ # =============================================================================
167+
116168if __name__ == "__main__" :
117169 main ()
0 commit comments