Skip to content

fix: keep the working directory after gopy pkg & gopy exe - #416

Merged
b-long merged 4 commits into
masterfrom
split/2-fix-exe-pkg
Nov 5, 2026
Merged

b-long merged 4 commits into
masterfrom
split/2-fix-exe-pkg

Conversation

@b-long

@b-long b-long commented Nov 5, 2026

Copy link
Copy Markdown
Member
  • ci: harden the main test job
  • test: run gopy as a subprocess, so tests can run in parallel
  • fix: build the executable gopy exe is asked for
  • fix: restore the working directory after gopy pkg and exe

Closes: #414

GenPyPkgSetup chdirs into the output directory, and neither command
changed back, so a caller running gopy in-process (as main_test.go does)
was left in the output directory, or in no directory at all once that
was removed: every later build then failed with

    getwd: no such file or directory

TestPkg builds _examples/simple with gopy pkg and runs its test.py.
gopy exe printed `go build -o py<pkg>` but ran `go build -mod=mod` alone:
the -o and -tags it appended went to an unused slice, so the executable
was named after the directory and built without the requested tags.  It
now runs the command it prints, adding Windows' .exe suffix.

The build that only writes <pkg>_go.h for the second build.py run was a
c-shared link of a .c file compiled against the placeholder header, which
macOS and Windows refuse when it calls functions (such as the static
_gopy_clear_go_tls) it can't link to yet.  It is now a c-archive, which
writes the header without linking, both in gopy exe and in the Makefile
it generates.

The BuildMode constants other than ModeGen were untyped strings; they
are now typed, and runBuild is passed bind.ModeBuild.

TestExe checks that gopy exe writes setup.py and the executable.
The generator keeps its state in package variables and gopy changes the
process's working directory, so main_test.go ran every gopy command
in-process and in sequence.  TestMain now builds the gopy binary once and
the tests run it as a separate process, which lets them call t.Parallel().

`make cover` collects coverage from those gopy processes too: the test
binaries and gopy write raw coverage data to covdata/, which is merged
into coverage.out.  codecov.yml counts Go's "partial" lines as hits, as
`go tool cover` does.

Also ignore Python bytecode caches, and remove the one that was committed
under _examples/funcs.
- Pin goimports to v0.29.0 instead of @latest, so the tool TestGofmt
  checks against doesn't change from one run to the next.
- Drop the apt-get step: none of the packages it installed are used.
- Disable Windows Defender real-time scanning, which slows every
  compile, link and pip install on windows-latest.
- Give the job a 20-minute timeout, rather than GitHub's 6h default.
- Cancel a pull request's previous run when it is pushed to again, and
  let the matrix fail fast.
@b-long
b-long force-pushed the split/2-fix-exe-pkg branch from 6a08e53 to 2a2884e Compare November 5, 2026 02:36
@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.61%. Comparing base (d81ecee) to head (2a2884e).

Files with missing lines Patch % Lines
cmd_build.go 91.66% 1 Missing ⚠️
cmd_exe.go 75.00% 1 Missing ⚠️
cmd_pkg.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #416       +/-   ##
===========================================
+ Coverage   74.79%   85.61%   +10.82%     
===========================================
  Files          25       24        -1     
  Lines        4658     4568       -90     
===========================================
+ Hits         3484     3911      +427     
+ Misses        934      657      -277     
+ Partials      240        0      -240     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@b-long
b-long merged commit af0b230 into master Nov 5, 2026
26 checks passed
b-long added a commit that referenced this pull request Nov 7, 2026
Master's main_test.go now builds the gopy binary once in TestMain and has
tests run it through runGopy, so they can call t.Parallel() (#416). Running
gopy in-process is unsafe there, because the generator keeps its state in
package variables. Move TestComplexGILStress to runGopy and t.Parallel(),
like TestGilString, and drop its bind.ResetPackages(), which only cleaned
up the in-process run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The gopy pkg and gopy exe commands change (and do not restore) the working directory

1 participant