Skip to content

Commit b77c0a7

Browse files
committed
fix: Adjust the flit-core support
1 parent 027110f commit b77c0a7

2 files changed

Lines changed: 10 additions & 92 deletions

File tree

src/python/supply/supply.go

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -743,19 +743,6 @@ func (s *Supplier) RunPipVendored() error {
743743
// dependencies - wheel and setuptools. These are packaged by the dependency
744744
// pipeline within the "pip" dependency.
745745
func (s *Supplier) InstallCommonBuildDependencies() error {
746-
// wheel and setuptools are packaged as pip-installable sdists inside the
747-
// "pip" dependency tarball. flit-core is a separate dependency whose
748-
// tarball contains the raw Python source tree (not an sdist/wheel for pip).
749-
//
750-
// Bootstrap strategy:
751-
// 1. Extract the pip tarball → /tmp/common_build_deps (wheel/setuptools sdists land here)
752-
// 2. Extract the flit-core tarball → /tmp/common_build_deps
753-
// → /tmp/common_build_deps/flit_core/ (source) + pyproject.toml
754-
// 3. Set PYTHONPATH=/tmp/common_build_deps so flit_core is importable.
755-
// 4. pip install /tmp/common_build_deps --no-build-isolation
756-
// → builds flit_core wheel using itself from PYTHONPATH and installs it.
757-
// 5. pip install wheel setuptools --no-index --no-build-isolation --find-links=tempPath
758-
// → flit_core is now a real installed package, so wheel's build succeeds.
759746
tempPath := filepath.Join("/tmp", "common_build_deps")
760747
if err := s.Installer.InstallOnlyVersion("pip", tempPath); err != nil {
761748
return err
@@ -764,53 +751,19 @@ func (s *Supplier) InstallCommonBuildDependencies() error {
764751
return err
765752
}
766753

767-
// Step 3: make flit_core source importable.
768-
prevPythonPath := os.Getenv("PYTHONPATH")
769-
newPythonPath := tempPath
770-
if prevPythonPath != "" {
771-
newPythonPath = tempPath + string(os.PathListSeparator) + prevPythonPath
772-
}
773-
os.Setenv("PYTHONPATH", newPythonPath)
774-
defer os.Setenv("PYTHONPATH", prevPythonPath)
775-
776-
// Step 4: install flit_core from its source directory via bootstrap.
777754
s.Log.Info("Installing build-time dependency flit-core (bootstrap)")
778-
if err := s.runPipInstall(tempPath, "--no-build-isolation"); err != nil {
755+
args := []string{tempPath, "--no-build-isolation"}
756+
if err := s.runPipInstall(args...); err != nil {
779757
return fmt.Errorf("could not bootstrap-install flit-core: %v", err)
780758
}
781759

782-
// Step 5: install wheel and setuptools (now flit_core is installed).
783760
for _, dep := range []string{"wheel", "setuptools"} {
784761
s.Log.Info("Installing build-time dependency %s", dep)
785762
args := []string{dep, "--no-index", "--no-build-isolation", "--upgrade-strategy=only-if-needed", fmt.Sprintf("--find-links=%s", tempPath)}
786763
if err := s.runPipInstall(args...); err != nil {
787764
return fmt.Errorf("could not install build-time dependency %s: %v", dep, err)
788765
}
789766
}
790-
791-
// Step 6: install poetry-core.
792-
// poetry-core is bundled in the buildpack under vendor_bundled/poetry-core_2.1.3.tgz.
793-
// Its pyproject.toml declares backend-path = ["src"] and requires = [],
794-
// so it self-bootstraps with --no-build-isolation (no build deps required).
795-
bpDir, err := libbuildpack.GetBuildpackDir()
796-
if err != nil {
797-
return fmt.Errorf("could not determine buildpack dir for poetry-core bootstrap: %v", err)
798-
}
799-
poetryCoreTar := filepath.Join(bpDir, "vendor_bundled", "poetry-core_2.1.3.tgz")
800-
poetryCoreSrc := filepath.Join("/tmp", "poetry_core_src")
801-
if err := os.MkdirAll(poetryCoreSrc, 0755); err != nil {
802-
return fmt.Errorf("could not create poetry-core src dir: %v", err)
803-
}
804-
s.Log.Info("Extracting bundled poetry-core from %s", poetryCoreTar)
805-
if err := s.Command.Execute("/", indentWriter(os.Stdout), indentWriter(os.Stderr),
806-
"tar", "xzf", poetryCoreTar, "-C", poetryCoreSrc); err != nil {
807-
return fmt.Errorf("could not extract poetry-core tarball: %v", err)
808-
}
809-
s.Log.Info("Installing build-time dependency poetry-core (bootstrap)")
810-
if err := s.runPipInstall(poetryCoreSrc, "--no-build-isolation"); err != nil {
811-
return fmt.Errorf("could not bootstrap-install poetry-core: %v", err)
812-
}
813-
814767
return nil
815768
}
816769

src/python/supply/supply_test.go

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -632,47 +632,26 @@ MarkupSafe==2.0.1
632632
})
633633

634634
Describe("InstallCommonBuildDependencies", func() {
635-
var bpDir string
636-
637-
BeforeEach(func() {
638-
bpDir, err = os.MkdirTemp("", "python-buildpack.bp.")
639-
Expect(err).To(BeNil())
640-
DeferCleanup(os.RemoveAll, bpDir)
641-
// Create the vendor_bundled directory with a dummy poetry-core tarball
642-
Expect(os.MkdirAll(filepath.Join(bpDir, "vendor_bundled"), 0755)).To(Succeed())
643-
Expect(os.WriteFile(filepath.Join(bpDir, "vendor_bundled", "poetry-core_2.1.3.tgz"), []byte("dummy"), 0644)).To(Succeed())
644-
// GetBuildpackDir() reads BUILDPACK_DIR env var if set
645-
os.Setenv("BUILDPACK_DIR", bpDir)
646-
DeferCleanup(os.Unsetenv, "BUILDPACK_DIR")
647-
})
648-
649635
Context("successful installation", func() {
650-
It("bootstraps flit-core, wheel, setuptools and poetry-core", func() {
651-
// Step 1+2: install pip and flit-core dependency tarballs
636+
It("bootstraps flit-core, wheel and setuptools", func() {
652637
mockInstaller.EXPECT().InstallOnlyVersion("pip", "/tmp/common_build_deps")
653638
mockInstaller.EXPECT().InstallOnlyVersion("flit-core", "/tmp/common_build_deps")
654-
// Step 4: bootstrap flit_core from source
655639
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "/tmp/common_build_deps", "--no-build-isolation")
656-
// Step 5: install wheel and setuptools
657640
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "wheel", "--no-index", "--no-build-isolation", "--upgrade-strategy=only-if-needed", "--find-links=/tmp/common_build_deps")
658641
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "setuptools", "--no-index", "--no-build-isolation", "--upgrade-strategy=only-if-needed", "--find-links=/tmp/common_build_deps")
659-
// Step 6: extract and bootstrap poetry-core
660-
poetryCoreTar := filepath.Join(bpDir, "vendor_bundled", "poetry-core_2.1.3.tgz")
661-
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), "tar", "xzf", poetryCoreTar, "-C", "/tmp/poetry_core_src")
662-
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "/tmp/poetry_core_src", "--no-build-isolation")
663642

664643
Expect(supplier.InstallCommonBuildDependencies()).To(Succeed())
665644
})
666645
})
667646

668-
Context("flit-core bootstrap fails", func() {
669-
It("returns a useful error message", func() {
670-
mockInstaller.EXPECT().InstallOnlyVersion("pip", "/tmp/common_build_deps")
671-
mockInstaller.EXPECT().InstallOnlyVersion("flit-core", "/tmp/common_build_deps")
672-
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "/tmp/common_build_deps", "--no-build-isolation").Return(fmt.Errorf("bootstrap-error"))
673-
Expect(supplier.InstallCommonBuildDependencies()).To(MatchError("could not bootstrap-install flit-core: bootstrap-error"))
674-
})
647+
Context("flit-core bootstrap fails", func() {
648+
It("returns a useful error message", func() {
649+
mockInstaller.EXPECT().InstallOnlyVersion("pip", "/tmp/common_build_deps")
650+
mockInstaller.EXPECT().InstallOnlyVersion("flit-core", "/tmp/common_build_deps")
651+
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "/tmp/common_build_deps", "--no-build-isolation").Return(fmt.Errorf("bootstrap-error"))
652+
Expect(supplier.InstallCommonBuildDependencies()).To(MatchError("could not bootstrap-install flit-core: bootstrap-error"))
675653
})
654+
})
676655

677656
Context("wheel installation fails", func() {
678657
It("returns a useful error message", func() {
@@ -683,20 +662,6 @@ MarkupSafe==2.0.1
683662
Expect(supplier.InstallCommonBuildDependencies()).To(MatchError("could not install build-time dependency wheel: some-pip-error"))
684663
})
685664
})
686-
687-
Context("poetry-core bootstrap fails", func() {
688-
It("returns a useful error message", func() {
689-
mockInstaller.EXPECT().InstallOnlyVersion("pip", "/tmp/common_build_deps")
690-
mockInstaller.EXPECT().InstallOnlyVersion("flit-core", "/tmp/common_build_deps")
691-
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "/tmp/common_build_deps", "--no-build-isolation")
692-
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "wheel", "--no-index", "--no-build-isolation", "--upgrade-strategy=only-if-needed", "--find-links=/tmp/common_build_deps")
693-
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "setuptools", "--no-index", "--no-build-isolation", "--upgrade-strategy=only-if-needed", "--find-links=/tmp/common_build_deps")
694-
poetryCoreTar := filepath.Join(bpDir, "vendor_bundled", "poetry-core_2.1.3.tgz")
695-
mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), "tar", "xzf", poetryCoreTar, "-C", "/tmp/poetry_core_src")
696-
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "/tmp/poetry_core_src", "--no-build-isolation").Return(fmt.Errorf("poetry-error"))
697-
Expect(supplier.InstallCommonBuildDependencies()).To(MatchError("could not bootstrap-install poetry-core: poetry-error"))
698-
})
699-
})
700665
})
701666

702667
Describe("CreateDefaultEnv", func() {

0 commit comments

Comments
 (0)