Skip to content

be-py, be-rust: name a library with a digit the way python and cargo do - #616

Open
notactuallytreyanastasio wants to merge 1 commit into
temperlang:mainfrom
notactuallytreyanastasio:fix/library-name-digits
Open

notactuallytreyanastasio wants to merge 1 commit into
temperlang:mainfrom
notactuallytreyanastasio:fix/library-name-digits

Conversation

@notactuallytreyanastasio

Copy link
Copy Markdown
Contributor

A library named f64str or radix-36 builds on py and rust, then
fails to run, because each backend refers to it by a name nothing
defines:

import f64_str as module
ModuleNotFoundError: No module named 'f64_str'

error[E0433]: cannot find module or crate `radix36` in this scope
2 |     radix36::init(None).unwrap().run_all_blocking();

Both names came from IdentStyle.Dash.convertTo(IdentStyle.Snake, ..).
That conversion re-splits the name into words, and it puts _ after a
run of digits but never before one, so f64str becomes f64_str and
radix-36 becomes radix36. It is the right tool for turning a
Temper identifier into a Python or Rust one, and the wrong one here,
where the name has to match what another tool already made of it.

py writes the package to a directory named by toModuleFileName
(f64str, radix_36), and imports of it from other libraries use
that too; only the PyLibraryName metadata, which top.py and the
REPL import, used IdentStyle. pyDirToLibraryName now uses
toModuleFileName.

cargo names a package's library crate by replacing each - with _.
PackageNaming.crateName now does exactly that. It is used for
main.rs and for paths into other crates, so a library that imports
from radix-36 failed on rust the same way, with radix36::, and now
prints its result too. Module paths inside a crate still use
dashToSnake; they are declared and referred to by the same function.

Names with no digit come out as before: both conversions give
hello_world for hello-world.

PyIdentifierTest.libraryNameIsItsPackageDirectory and
RustNamesTest.crateNameIsCargos fail before this change on f64str
(f64_str) and pass after. temper run of f64str, radix-36, and a
library importing from radix-36, prints the expected lines on py and
rust.

Fixes #610.

Reproduction: 57-library-name-with-digit/ in temper-issue-repros.

🤖 Generated with Claude Code

A library named `f64str` or `radix-36` builds on py and rust, then
fails to run, because each backend refers to it by a name nothing
defines:

    import f64_str as module
    ModuleNotFoundError: No module named 'f64_str'

    error[E0433]: cannot find module or crate `radix36` in this scope
    2 |     radix36::init(None).unwrap().run_all_blocking();

Both names came from `IdentStyle.Dash.convertTo(IdentStyle.Snake, ..)`.
That conversion re-splits the name into words, and it puts `_` after a
run of digits but never before one, so `f64str` becomes `f64_str` and
`radix-36` becomes `radix36`. It is the right tool for turning a
Temper identifier into a Python or Rust one, and the wrong one here,
where the name has to match what another tool already made of it.

py writes the package to a directory named by `toModuleFileName`
(`f64str`, `radix_36`), and imports of it from other libraries use
that too; only the `PyLibraryName` metadata, which `top.py` and the
REPL import, used `IdentStyle`. pyDirToLibraryName now uses
`toModuleFileName`.

cargo names a package's library crate by replacing each `-` with `_`.
`PackageNaming.crateName` now does exactly that. It is used for
`main.rs` and for paths into other crates, so a library that imports
from `radix-36` failed on rust the same way, with `radix36::`, and now
prints its result too. Module paths inside a crate still use
`dashToSnake`; they are declared and referred to by the same function.

Names with no digit come out as before: both conversions give
`hello_world` for `hello-world`.

PyIdentifierTest.libraryNameIsItsPackageDirectory and
RustNamesTest.crateNameIsCargos fail before this change on `f64str`
(`f64_str`) and pass after. `temper run` of `f64str`, `radix-36`, and a
library importing from `radix-36`, prints the expected lines on py and
rust.

Fixes temperlang#610.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Bobby Grayson <bobbbygrayson+github@gmail.com>
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.

A library name with a digit is imported under a different name on py and rust, so temper run fails: f64str as f64_str, radix-36 as radix36

2 participants