Skip to content

Commit 8649b7b

Browse files
committed
Drop PythonDependencyExecutionContextView and unused PyProjectHelper helpers
1 parent 4ad16fb commit 8649b7b

2 files changed

Lines changed: 0 additions & 285 deletions

File tree

rewrite-python/src/main/java/org/openrewrite/python/internal/PyProjectHelper.java

Lines changed: 0 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.openrewrite.*;
2121
import org.openrewrite.json.JsonParser;
2222
import org.openrewrite.json.tree.Json;
23-
import org.openrewrite.marker.Markup;
2423
import org.openrewrite.python.PipfileParser;
2524
import org.openrewrite.python.marker.PythonResolutionResult;
2625
import org.openrewrite.python.marker.PythonResolutionResult.Dependency;
@@ -94,111 +93,6 @@ public static Path correspondingPipfilePath(Path pipfileLockPath) {
9493
return pipfileLockPath.resolveSibling("Pipfile");
9594
}
9695

97-
/**
98-
* If {@code tree} is a Python lock file (uv.lock or Pipfile.lock), capture
99-
* its current content into the shared {@link PythonDependencyExecutionContextView}
100-
* so downstream recipes can seed regeneration from it.
101-
*
102-
* @return {@code true} when the tree was recognized as a lock file
103-
*/
104-
/**
105-
* @deprecated Tied to the old {@link PythonDependencyExecutionContextView}-based design;
106-
* to be deleted in Task 8 of the Accumulator rework. New recipes should mirror
107-
* {@code AddDependency} and capture lock content directly into their {@code Accumulator}.
108-
*/
109-
@Deprecated
110-
public static boolean captureExistingLockContent(SourceFile sourceFile, Tree tree, ExecutionContext ctx) {
111-
Path sourcePath = sourceFile.getSourcePath();
112-
if (tree instanceof Toml.Document && sourcePath.endsWith("uv.lock")) {
113-
PythonDependencyExecutionContextView.view(ctx).getExistingLockContents().put(
114-
correspondingPyprojectPath(sourcePath),
115-
((Toml.Document) tree).printAll());
116-
return true;
117-
}
118-
if (tree instanceof Json.Document && sourcePath.endsWith("Pipfile.lock")) {
119-
PythonDependencyExecutionContextView.view(ctx).getExistingLockContents().put(
120-
correspondingPipfilePath(sourcePath),
121-
((Json.Document) tree).printAll());
122-
return true;
123-
}
124-
return false;
125-
}
126-
127-
/**
128-
* If a previous visitor regenerated lock content for this file, replay it here.
129-
* Returns the updated tree, or {@code null} if the tree is not a lock file or
130-
* there is no pending update.
131-
*/
132-
/**
133-
* @deprecated See {@link #captureExistingLockContent}. Use the visitor lock-branch
134-
* pattern in {@code AddDependency} instead.
135-
*/
136-
@Deprecated
137-
public static @Nullable Tree maybeReplayLockContent(Tree tree, ExecutionContext ctx) {
138-
if (tree instanceof Toml.Document) {
139-
Toml.Document doc = (Toml.Document) tree;
140-
if (doc.getSourcePath().endsWith("uv.lock")) {
141-
return maybeUpdateUvLock(doc, ctx);
142-
}
143-
}
144-
if (tree instanceof Json.Document) {
145-
Json.Document doc = (Json.Document) tree;
146-
if (doc.getSourcePath().endsWith("Pipfile.lock")) {
147-
return maybeUpdatePipfileLock(doc, ctx);
148-
}
149-
}
150-
return null;
151-
}
152-
153-
/**
154-
* If there is regenerated uv.lock content for this document, reparse the document
155-
* from that content. Returns {@code null} when no update is needed (either no
156-
* regenerated content exists, or the current document already matches).
157-
* <p>
158-
* After reparsing, the stored content is normalized to the printer output so that
159-
* subsequent recipe cycles see identical content and do not trigger spurious changes.
160-
*/
161-
/** @deprecated See {@link #captureExistingLockContent}. */
162-
@Deprecated
163-
public static Toml.@Nullable Document maybeUpdateUvLock(Toml.Document document, ExecutionContext ctx) {
164-
PythonDependencyExecutionContextView view = PythonDependencyExecutionContextView.view(ctx);
165-
Path pyprojectPath = correspondingPyprojectPath(document.getSourcePath());
166-
String newContent = view.getUpdatedLockFiles().get(pyprojectPath);
167-
if (newContent == null) {
168-
return null;
169-
}
170-
Toml.Document reparsed = reparseToml(document, newContent);
171-
String reparsedContent = reparsed.printAll();
172-
if (reparsedContent.equals(document.printAll())) {
173-
return null;
174-
}
175-
// Normalize stored content to printer output for round-trip stability
176-
view.getUpdatedLockFiles().put(pyprojectPath, reparsedContent);
177-
return reparsed;
178-
}
179-
180-
/**
181-
* If there is regenerated Pipfile.lock content for this document, reparse the
182-
* document from that content. Returns {@code null} when no update is needed.
183-
*/
184-
/** @deprecated See {@link #captureExistingLockContent}. */
185-
@Deprecated
186-
public static Json.@Nullable Document maybeUpdatePipfileLock(Json.Document document, ExecutionContext ctx) {
187-
PythonDependencyExecutionContextView view = PythonDependencyExecutionContextView.view(ctx);
188-
Path pipfilePath = correspondingPipfilePath(document.getSourcePath());
189-
String newContent = view.getUpdatedLockFiles().get(pipfilePath);
190-
if (newContent == null) {
191-
return null;
192-
}
193-
Json.Document reparsed = reparseJson(document, newContent);
194-
String reparsedContent = reparsed.printAll();
195-
if (reparsedContent.equals(document.printAll())) {
196-
return null;
197-
}
198-
view.getUpdatedLockFiles().put(pipfilePath, reparsedContent);
199-
return reparsed;
200-
}
201-
20296
/**
20397
* Reparse a JSON document from new content while preserving the original document's
20498
* identity (id) and markers.
@@ -367,116 +261,6 @@ public static EditAndRegenerateResult changed(
367261
return regen.regenerate(depsFile.printAll(), capturedLockContent);
368262
}
369263

370-
/**
371-
* After modifying a pyproject.toml document, regenerate the uv.lock file and
372-
* refresh the {@link PythonResolutionResult} marker. Returns the updated document.
373-
* <p>
374-
* Lock file state is shared across all Python dependency recipes via the
375-
* {@link ExecutionContext}, so sequential recipes in a composite correctly
376-
* build on each other's lock regeneration results.
377-
*
378-
* @param updated the modified pyproject.toml document
379-
* @param ctx the execution context holding shared lock file state
380-
* @return the document with refreshed marker (and possibly a warning markup)
381-
*/
382-
/** @deprecated See {@link #captureExistingLockContent}. Use {@link #editAndRegenerate} from the Accumulator pattern. */
383-
@Deprecated
384-
public static Toml.Document regenerateLockAndRefreshMarker(
385-
Toml.Document updated,
386-
ExecutionContext ctx) {
387-
PythonDependencyExecutionContextView view = PythonDependencyExecutionContextView.view(ctx);
388-
Map<Path, String> updatedLockFiles = view.getUpdatedLockFiles();
389-
Map<Path, String> existingLockContents = view.getExistingLockContents();
390-
391-
PythonResolutionResult marker = updated.getMarkers()
392-
.findFirst(PythonResolutionResult.class).orElse(null);
393-
394-
Path sourcePath = updated.getSourcePath();
395-
396-
// Attempt lock regeneration when we know a uv.lock exists — either
397-
// captured during scanning or already regenerated by a prior recipe
398-
boolean lockKnown = existingLockContents.containsKey(sourcePath) ||
399-
updatedLockFiles.containsKey(sourcePath) ||
400-
(marker != null && !marker.getResolvedDependencies().isEmpty());
401-
402-
if (marker != null && lockKnown) {
403-
String pyprojectContent = updated.printAll();
404-
// Prefer the most recently regenerated lock; fall back to original
405-
String seedLock = updatedLockFiles.getOrDefault(sourcePath,
406-
existingLockContents.get(sourcePath));
407-
408-
LockFileRegeneration.Result lockResult = LockFileRegeneration.UV.regenerate(pyprojectContent, seedLock);
409-
if (lockResult.isSuccess()) {
410-
updatedLockFiles.put(sourcePath, lockResult.getLockFileContent());
411-
existingLockContents.put(sourcePath, lockResult.getLockFileContent());
412-
} else {
413-
updated = Markup.warn(updated, new RuntimeException(
414-
"uv lock regeneration failed: " + lockResult.getErrorMessage()));
415-
}
416-
}
417-
418-
if (marker != null) {
419-
PythonResolutionResult newMarker = PythonDependencyParser.createMarker(updated, null);
420-
if (newMarker != null) {
421-
updated = updated.withMarkers(updated.getMarkers().setByType(newMarker.withId(marker.getId())));
422-
}
423-
}
424-
425-
return updated;
426-
}
427-
428-
/**
429-
* After modifying a Pipfile document, regenerate the Pipfile.lock file and
430-
* refresh the {@link PythonResolutionResult} marker. Returns the updated document.
431-
* <p>
432-
* The {@code markerFactory} callback rebuilds the marker from the updated
433-
* Pipfile contents — passed in to avoid coupling this internal class to the
434-
* public {@code PipfileParser}.
435-
*/
436-
/** @deprecated See {@link #regenerateLockAndRefreshMarker}. */
437-
@Deprecated
438-
public static Toml.Document regeneratePipfileLockAndRefreshMarker(
439-
Toml.Document updated,
440-
ExecutionContext ctx,
441-
Function<Toml.Document, PythonResolutionResult> markerFactory) {
442-
PythonDependencyExecutionContextView view = PythonDependencyExecutionContextView.view(ctx);
443-
Map<Path, String> updatedLockFiles = view.getUpdatedLockFiles();
444-
Map<Path, String> existingLockContents = view.getExistingLockContents();
445-
446-
PythonResolutionResult marker = updated.getMarkers()
447-
.findFirst(PythonResolutionResult.class).orElse(null);
448-
449-
Path sourcePath = updated.getSourcePath();
450-
451-
boolean lockKnown = existingLockContents.containsKey(sourcePath) ||
452-
updatedLockFiles.containsKey(sourcePath) ||
453-
(marker != null && !marker.getResolvedDependencies().isEmpty());
454-
455-
if (marker != null && lockKnown) {
456-
String pipfileContent = updated.printAll();
457-
String seedLock = updatedLockFiles.getOrDefault(sourcePath,
458-
existingLockContents.get(sourcePath));
459-
460-
LockFileRegeneration.Result lockResult = LockFileRegeneration.PIPENV.regenerate(pipfileContent, seedLock);
461-
if (lockResult.isSuccess()) {
462-
updatedLockFiles.put(sourcePath, lockResult.getLockFileContent());
463-
existingLockContents.put(sourcePath, lockResult.getLockFileContent());
464-
} else {
465-
updated = Markup.warn(updated, new RuntimeException(
466-
"pipenv lock regeneration failed: " + lockResult.getErrorMessage()));
467-
}
468-
}
469-
470-
if (marker != null) {
471-
PythonResolutionResult newMarker = markerFactory.apply(updated);
472-
if (newMarker != null) {
473-
updated = updated.withMarkers(updated.getMarkers().setByType(newMarker.withId(marker.getId())));
474-
}
475-
}
476-
477-
return updated;
478-
}
479-
480264
/**
481265
* Check whether a cursor path represents a position inside
482266
* the {@code [project].dependencies} array in a pyproject.toml.

rewrite-python/src/main/java/org/openrewrite/python/internal/PythonDependencyExecutionContextView.java

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

0 commit comments

Comments
 (0)