Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

om init does not replace strings under matching directory name #425

Closed
cameronraysmith opened this issue Feb 28, 2025 · 4 comments · Fixed by #435
Closed

om init does not replace strings under matching directory name #425

cameronraysmith opened this issue Feb 28, 2025 · 4 comments · Fixed by #435
Assignees
Labels
bug Something isn't working

Comments

@cameronraysmith
Copy link

cameronraysmith commented Feb 28, 2025

I am not certain the issue title captures the correct condition, but I have noticed in https://github.com/sciexp/python-nix-template/blob/7d17d0dbffe756f1804aa86fe95bf61a1867d4d3/nix/modules/template.nix that when I create new template instances, a directory name that matches a string replacement rule is correctly renamed but all the files below it fail to receive that same string replacement.

See the timestamps in the description of https://asciinema.org/a/WkHfv6v6vd5qUNlCVbbKzbKcp

for an example of this.

In particular the directory here gets replaced as expected

https://github.com/sciexp/python-nix-template/tree/7d17d0dbffe756f1804aa86fe95bf61a1867d4d3/src/python_nix_template

but instances of the same matching string do not get replaced in any of the files within that folder, such as this particular example

https://github.com/sciexp/python-nix-template/blob/7d17d0dbffe756f1804aa86fe95bf61a1867d4d3/src/python_nix_template/tests/test_main.py#L5

example template output
nix --accept-flake-config run github:juspay/omnix -- \
init github:sciexp/python-nix-template/main -o new-python-project

🪃 vscode prune [disabled]
🪃 github-ci prune [disabled]
🪃 nix-template prune [**/template.nix]
   ❌ nix/modules/template.nix
🪃 package-name-kebab-case replace [python-nix-template => new-python-project]
   ✍️ nix/modules/python.nix
   ✍️ nix/modules/devshell.nix
   ✍️ nix/modules/containers.nix
   ✍️ nix/modules/packages.nix
   ✍️ justfile
   ✍️ uv.lock
   ✍️ conda/README.md
   ✍️ pyproject.toml
   ✍️ pixi.lock
   ✍️ README.md
   ✍️ flake.nix
   ✍️ .github/workflows/ci.yaml
   ✍️ .github/ISSUE_TEMPLATE/config.yml
   ✍️ .github/SECURITY.md
   ✍️ .vscode/launch.json
🪃 package-name-snake-case replace [python_nix_template => new_python_project]
   ✍️ nix/modules/python.nix
   ✍️ pyproject.toml
   ✍️ .vscode/launch.json
   ✏️ src/python_nix_template => new_python_project  <====================this replaced the folder name but should've also updated files within that folder
🪃 git-org replace [sciexp => cameronraysmith]
   ✍️ nix/modules/containers.nix
   ✍️ justfile
   ✍️ README.md
   ✍️ flake.nix
   ✍️ .github/workflows/ci.yaml
   ✍️ .github/ISSUE_TEMPLATE/config.yml
   ✍️ .github/SECURITY.md
🪃 author replace [Your Name => Cameron Smith]
   ✍️ pyproject.toml
🪃 author-email replace [[email protected] => [email protected]]
   ✍️ pyproject.toml

┄┄🥳 Initialized template at /Users/user/projects/new-python-project
...

the files that should have received replacement of the same string are

```sh
❯ tree src -I "__pycache__"
src
└── new_python_project
    ├── __init__.py
    ├── main.py
    └── tests
        └── test_main.py

3 directories, 3 files

It's also certainly possible I've misinterpreted the nature and cause of this issue since I haven't reviewed the omnix source.

@srid srid changed the title template string replacement may fail on file trees below replaced directory names om init does not replace strings under maching directory name Mar 10, 2025
@srid srid added the bug Something isn't working label Mar 10, 2025
@srid
Copy link
Member

srid commented Mar 10, 2025

An one-liner repro command is useful for bug reports like this. IIUC:

Current behaviour

❯ rm -rf ./tmp; cargo run -p omnix-cli -- init -o ./tmp github:sciexp/python-nix-template/7d17d0 --non-interactive --params '{"package-name-kebab-case": "foo", "package-name-snake-case": "foo", "git-org": "sciexp", "author": "S", "author-email": "[email protected]"}' 2> /dev/null; rg python_nix_template ./tmp/src/foo
./tmp/src/foo/tests/test_main.py
5:from python_nix_template.main import create_greeting, greet, validate_name

./tmp/src/foo/__init__.py
5:from python_nix_template.main import greet

./tmp/src/foo/main.py
1:"""Main module for python_nix_template demonstrating functional programming patterns."""

Expected behaviour

All those python_nix_template should have be rewritten to foo.

@srid
Copy link
Member

srid commented Mar 10, 2025

With #435

Image
cargo run -p omnix-cli -- init -o ./tmp github:sciexp/python-nix-template/7d17d0 --non-interactive --params '{"package-name-kebab-case": "foo", "package-name-snake-case": "foo", "git-org": "sciexp", "author": "S", "author-email": "[email protected]"}'
Image

@srid srid self-assigned this Mar 10, 2025
@srid
Copy link
Member

srid commented Mar 10, 2025

@cameronraysmith Thanks for these bug reports. We are planning to make a release of omnix next (all the way to nixpkgs; #204). If there's any other issue to address in main branch, let me know.

@srid srid closed this as completed in #435 Mar 10, 2025
@srid srid closed this as completed in 2925afc Mar 10, 2025
@cameronraysmith cameronraysmith changed the title om init does not replace strings under maching directory name om init does not replace strings under matching directory name Mar 10, 2025
@cameronraysmith
Copy link
Author

You covered everything I encountered except for the one you already identified in #428 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants