Skip to content

be-py: put a dashed library's own directory on PYTHONPATH - #614

Open
notactuallytreyanastasio wants to merge 1 commit into
temperlang:mainfrom
notactuallytreyanastasio:fix/py-run-dashed-library
Open

notactuallytreyanastasio wants to merge 1 commit into
temperlang:mainfrom
notactuallytreyanastasio:fix/py-run-dashed-library

Conversation

@notactuallytreyanastasio

Copy link
Copy Markdown
Contributor

temper run -b py on a library named hello-world that only prints
fails:

PYTHONPATH=.../temper.out/py/hello_world:.../temper.out/py/temper-core:.../temper.out/py/deps
ModuleNotFoundError: No module named 'hello_world'

The package is at temper.out/py/hello-world/hello_world/, so the
directory that has to be on the path is hello-world. runPyBestEffort
built the library's path from its Python module name, hello_world,
which names no directory. The dependency paths next to it use the
Temper name, and they cover every library in
transitiveDependencies, so the run worked whenever the build had
recorded a dependency from the library on another one: an Int
addition, which uses temper-core's int_add, was enough. A library
that only calls console.log records none, and a name with no dash
hid the mismatch because the two names are the same.

The library's own path now uses the Temper name too. Its directory is
then also the one the dependency loop skips, so it is listed once.

RunTest.runPyBackendDashedName runs a hello-world library that
prints one line. Before this change it fails with the
ModuleNotFoundError above; after, it prints I ran.

Fixes #609.

Reproduction: 56-py-run-hyphenated-library/ in temper-issue-repros.

🤖 Generated with Claude Code

`temper run -b py` on a library named `hello-world` that only prints
fails:

    PYTHONPATH=.../temper.out/py/hello_world:.../temper.out/py/temper-core:.../temper.out/py/deps
    ModuleNotFoundError: No module named 'hello_world'

The package is at `temper.out/py/hello-world/hello_world/`, so the
directory that has to be on the path is `hello-world`. runPyBestEffort
built the library's path from its Python module name, `hello_world`,
which names no directory. The dependency paths next to it use the
Temper name, and they cover every library in
`transitiveDependencies`, so the run worked whenever the build had
recorded a dependency from the library on another one: an `Int`
addition, which uses temper-core's `int_add`, was enough. A library
that only calls `console.log` records none, and a name with no dash
hid the mismatch because the two names are the same.

The library's own path now uses the Temper name too. Its directory is
then also the one the dependency loop skips, so it is listed once.

RunTest.runPyBackendDashedName runs a `hello-world` library that
prints one line. Before this change it fails with the
ModuleNotFoundError above; after, it prints `I ran`.

Fixes temperlang#609.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Bobby Grayson <bobbbygrayson+github@gmail.com>
@@ -0,0 +1,3 @@
# Test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, we use the header here for the name if it's not specified, so

# Hello World

would be an equivalent config.

val pyLibraryPath = pyLibraryName?.let { pyDir.resolveDir(pyLibraryName.text) }
// The library's directory is named for the Temper library, like its dependencies' below,
// not for its Python module: `hello-world`, not `hello_world`.
val pyLibraryPath = (request as? RunLibraryRequest)?.let { pyDir.resolveDir(it.libraryName.text) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a when (request) instead of using as? so that we explicitly cover the different request cases. It's ok if we're using null for some cases, just it's clearer if we're deriving this that we've covered our bases.

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.

temper run -b py fails with ModuleNotFoundError for a library whose name has a dash, unless the build records a dependency from that library on another

2 participants