Skip to content

Commit 38c303e

Browse files
gselzerclaude
andcommitted
Require ResidentWorkerService for completion
The Appose-Python dialect now requires its ResidentWorkerService, as the script engine does, so ApposePythonEnvironments need not handle its absence. Its test-only settle and build constructor parameters are gone too, along with the test of its debouncing that needed them: that environments get built is covered by ApposePythonCompletionIntegrationTest#testNewDependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent eb5c05b commit 38c303e

4 files changed

Lines changed: 10 additions & 130 deletions

File tree

‎src/main/java/org/scijava/plugins/scripting/appose/python/completion/ApposePythonDialect.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class ApposePythonDialect implements ScriptDialect {
6868
private static final String NUMPY = "_scijava_numpy",
6969
WORKER = "_scijava_python_worker";
7070

71-
@Parameter(required = false)
71+
@Parameter
7272
private ResidentWorkerService workers;
7373

7474
private ApposePythonEnvironments environments;

‎src/main/java/org/scijava/plugins/scripting/appose/python/completion/ApposePythonEnvironments.java‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.util.concurrent.ThreadFactory;
4848
import java.util.concurrent.TimeUnit;
4949
import java.util.concurrent.locks.Lock;
50-
import java.util.function.Consumer;
5150

5251
import org.apposed.appose.Environment;
5352
import org.apposed.appose.util.Environments;
@@ -79,7 +78,7 @@ final class ApposePythonEnvironments {
7978
* How long an environment's configuration must stay the same before it is
8079
* built, in milliseconds.
8180
*/
82-
static final long SETTLE = 5000;
81+
private static final long SETTLE = 5000;
8382

8483
/** Where settling environments are waited for. */
8584
private static final ScheduledExecutorService TIMER = Executors
@@ -89,15 +88,9 @@ final class ApposePythonEnvironments {
8988
private static final ExecutorService BUILDS = Executors
9089
.newSingleThreadExecutor(daemon("appose-python-prebuild"));
9190

92-
/** The resident workers, to find built environments; or null if none. */
91+
/** The resident workers, to find built environments. */
9392
private final ResidentWorkerService workers;
9493

95-
/** How long a configuration must stay the same before it is built. */
96-
private final long settle;
97-
98-
/** Builds an environment; or null, to build none. */
99-
private final Consumer<ScriptEnvironment> build;
100-
10194
/** Scripts waiting to settle, by path ("" if unsaved): what, and when. */
10295
private final Map<String, Settling> settling = new HashMap<>();
10396

@@ -120,25 +113,9 @@ protected boolean removeEldestEntry(
120113
}
121114
};
122115

123-
/** @param workers The resident workers, or null if none (none built). */
116+
/** @param workers The resident workers. */
124117
ApposePythonEnvironments(final ResidentWorkerService workers) {
125-
this(workers, SETTLE, null);
126-
}
127-
128-
/**
129-
* @param workers The resident workers, or null if none.
130-
* @param settle How long a configuration must stay the same before it is
131-
* built, in milliseconds.
132-
* @param build Builds an environment (e.g. a fake one, in tests); or null,
133-
* to build them with the workers (if any).
134-
*/
135-
ApposePythonEnvironments(final ResidentWorkerService workers,
136-
final long settle, final Consumer<ScriptEnvironment> build)
137-
{
138118
this.workers = workers;
139-
this.settle = settle;
140-
this.build = build != null ? build : workers != null ? this::build
141-
: null;
142119
}
143120

144121
/**
@@ -207,8 +184,8 @@ private String findScriptPython(final String text, final String path) {
207184
if (env == null) return null;
208185
// NB: A read-only lookup: worker(...) would replace the worker whenever
209186
// the configuration changed, i.e. as the user edits it.
210-
final ResidentWorker worker = workers == null ? null : workers.find(
211-
env.name, env.activate, env.config());
187+
final ResidentWorker worker = workers.find(env.name, env.activate, env
188+
.config());
212189
if (worker != null && worker.environment().isBuilt()) {
213190
try {
214191
final String python = pythonExecutable(worker.environment().get());
@@ -228,13 +205,12 @@ private String findScriptPython(final String text, final String path) {
228205

229206
/**
230207
* Builds an environment once its configuration has stayed the same for a
231-
* while (see {@link #settle}), unless it was tried already.
208+
* while (see {@link #SETTLE}), unless it was tried already.
232209
*/
233210
private void prepare(final String path, final ScriptEnvironment env) {
234211
// NB: By script, not by environment: an unsaved script's environment
235212
// is named after its configuration, so changes to it with each edit.
236213
final String script = path == null ? "" : path;
237-
if (build == null) return;
238214
final String key = env.name + "\n" + env.config();
239215
synchronized (settling) {
240216
if (key.equals(tried.get(script))) return;
@@ -248,8 +224,8 @@ private void prepare(final String path, final ScriptEnvironment env) {
248224
settling.remove(script);
249225
if (key.equals(tried.put(script, key))) return;
250226
}
251-
CompletableFuture.runAsync(() -> build.accept(env), BUILDS);
252-
}, settle, TimeUnit.MILLISECONDS)));
227+
CompletableFuture.runAsync(() -> build(env), BUILDS);
228+
}, SETTLE, TimeUnit.MILLISECONDS)));
253229
}
254230
}
255231

‎src/test/java/org/scijava/plugins/scripting/appose/python/completion/ApposePythonDialectTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void testEnvironmentWithoutOne() {
147147
public void testScriptWorkersUntouched() {
148148
// Finding where a script runs does not create (or replace) a worker for
149149
// it at once, even as its metadata is edited: only once the metadata
150-
// has settled (see ApposePythonEnvironmentsTest).
150+
// has settled.
151151
final String script = "# /// script\n# dependencies = [\"appose\"]\n" +
152152
"# ///\nimport os\nos.pa";
153153
dialect.environment(script, null);

‎src/test/java/org/scijava/plugins/scripting/appose/python/completion/ApposePythonEnvironmentsTest.java‎

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)