Repository navigation
Description
Problem
Originally reported by @Adebowale-Morakinyo while working on #62. Confirmed against the CLI/config code on current main (v0.42.0), which is unchanged in pending PR #86.
All 53 entries in config._JAVA_KEYWORDS pass _NAME_RE. For example:
pn init class # exits 0 and creates the project
cd class
pn app-id android # exits 1: app id segment 'class' is a reserved word
The generated pythonnative.toml contains id = "com.example.class", which the configuration validator rejects. Checking only the raw name isn't enough: pn init cla-ss derives the same ID. No-name pn init in directories named Class, CLASS, or cl.ass also creates the invalid ID because derivation lowercases and removes punctuation. Uppercase and dotted names are examples of the no-name directory path, not valid explicit pn init <name> arguments.
Decision and scope
Reject the project at initialization if its derived app ID is invalid, before creating directories or writing or overwriting any scaffold files. Use an actionable error rather than silently changing the app ID with a suffix or prefix.
This is assigned to @be-student, who requested it in the comments. The behavior change was deliberately excluded from #62 / #79 and belongs here.
Requested change
- Derive the app ID once in
init_project()insrc/pythonnative/cli/pn.py, then validate it using the existing app-ID validation rules fromsrc/pythonnative/project/config.py. Reuse the validator or a narrowly factored helper; don't duplicate the Java keyword set. - Apply the check to both
pn init <name>and no-namepn init, after determining the project name and before the first filesystem mutation.--forcemust not bypass it. - Exit nonzero with a concise message that identifies the project name and offending derived ID/segment and suggests a valid next step, such as
pn init class_app. In the no-name case, explain that the current directory name produced the invalid ID. - Preserve
_app_id_from_name()output for valid names and the existing character/path/overwrite rules. No broader name-policy changes, app-ID collision scheme, automatic rewriting of existing projects, or native build changes. - Update
init_project()documentation and the name guidance indocs/getting-started.md/docs/api/cli.mdto describe this rejection. Coordinate with Align the getting-started and examples docs with the currentpn initscaffold #58 if both changes touch the getting-started page.
Acceptance criteria
- Explicit keyword names are rejected; parameterize over the existing
_JAVA_KEYWORDSset (53 entries today). - A normalized collision such as explicit
cla-ssis rejected too. - No-name initialization in
Class,CLASS, andcl.assdirectories is rejected. Use a separate parent directory for each case so the tests work on case-insensitive filesystems. - Rejection leaves a new target absent, an existing empty target empty, and existing scaffold files unchanged when
--forceis passed. Cover the no-name path as well. - A valid name such as
class_appstill initializes successfully and its generated configuration loads;pn app-id androidandpn app-id iosreturn its expected ID. - Existing valid-name derivation tests from test(cli): cover app id derivation from project names #79 continue to pass. Add focused CLI regression tests in
tests/test_cli.py; no Android SDK, Xcode, device, or network is needed for these cases.
Verification
uv run pytest tests/test_cli.py tests/project/test_config.py -q
./scripts/check.shSuggested commit message
fix(cli): reject invalid derived app ids before scaffolding
Activity
be-student commentedon Sep 6, 2026
I'd like to work on this. I plan to reject project names whose derived app-id segment is a Java keyword, with focused CLI tests. Could you assign it to me?
[-]pn init accepts Java reserved words, producing a project that no command can build[/-][+]`pn init` must reject names whose derived app ID contains a reserved word before writing files[/+]owenthcarey commentedon Sep 9, 2026
@be-student, assigned to you. Your proposed rejection approach is the right scope. I reproduced the failure with
class, explicitcla-ss, and no-name initialization inClass,CLASS, andcl.assdirectories. All 53 reserved words still produce invalid derived IDs.I've updated the issue with the decision and acceptance criteria: validate the derived ID using the existing config rules, cover both initialization paths, and fail before any directory creation or file writes, including with
--force. Keep valid-name derivation unchanged. This clears the product decision so you can proceed with the fix and focused tests.@Adebowale-Morakinyo, thanks for finding this and keeping the behavior change separate from #62 / #79.