Skip to content

Commit e165d28

Browse files
committed
Allow passing alternate args to python service
Invoking `python()` with no args still starts the python_worker. But if you pass arguments, you can make python do something else. See also apposed/appose-java@603718a
1 parent 88e0137 commit e165d28

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/appose/environment.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,23 @@ def delete(self) -> Environment:
109109
self.builder().delete()
110110
return self
111111

112-
def python(self) -> Service:
112+
def python(self, *args) -> Service:
113113
"""
114-
Create a Python script service.
114+
Create a Python script service, or launch a custom Python process.
115115
116-
This is a *high level* way to create a service, enabling execution of
117-
Python scripts asynchronously on its linked process running a
118-
`python_worker`.
116+
If invoked without arguments, this is a *high level* way to create a
117+
a service, enabling execution of Python scripts asynchronously on its
118+
linked process running a `python_worker`.
119+
120+
Or if invoked with any arguments, this becomes a *lower level* function
121+
for launching Python with any arguments of your choice. This can be
122+
useful to perform actions such as installing a wheel (`python -m pip
123+
install /path/to/wheel-file`), without the usual bother of
124+
platform-specific special casing.
125+
126+
Args:
127+
args: Optional alternate args to pass to the python process.
128+
If empty, a normal Appose `python_worker` will be started.
119129
120130
Returns:
121131
The newly created service.
@@ -133,11 +143,11 @@ def python(self) -> Service:
133143
"bin/python",
134144
"bin/python.exe",
135145
]
136-
return self.service(
137-
python_exes,
146+
python_args = args or [
138147
"-c",
139148
"import appose.python_worker; appose.python_worker.main()",
140-
).syntax(PythonSyntax())
149+
]
150+
return self.service(python_exes, *python_args).syntax(PythonSyntax())
141151

142152
def groovy(
143153
self,

0 commit comments

Comments
 (0)