Skip to content

pn init must reject names whose derived app ID contains a reserved word before writing files #78

Open

Description

@Adebowale-Morakinyo

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() in src/pythonnative/cli/pn.py, then validate it using the existing app-ID validation rules from src/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-name pn init, after determining the project name and before the first filesystem mutation. --force must 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 in docs/getting-started.md / docs/api/cli.md to describe this rejection. Coordinate with Align the getting-started and examples docs with the current pn init scaffold #58 if both changes touch the getting-started page.

Acceptance criteria

  • Explicit keyword names are rejected; parameterize over the existing _JAVA_KEYWORDS set (53 entries today).
  • A normalized collision such as explicit cla-ss is rejected too.
  • No-name initialization in Class, CLASS, and cl.ass directories 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 --force is passed. Cover the no-name path as well.
  • A valid name such as class_app still initializes successfully and its generated configuration loads; pn app-id android and pn app-id ios return 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.sh

Suggested commit message

fix(cli): reject invalid derived app ids before scaffolding

Activity

  1. be-student commented on Sep 6, 2026

    @be-student

    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?

  2. changed the title [-]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[/+] on Sep 9, 2026
  3. added
    bug
    good first issue
    on Sep 9, 2026
  4. owenthcarey commented on Sep 9, 2026

    @owenthcarey
    Contributor

    @be-student, assigned to you. Your proposed rejection approach is the right scope. I reproduced the failure with class, explicit cla-ss, and no-name initialization in Class, CLASS, and cl.ass directories. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions