Fix usethis tool failing in directories with leading dots#1903
Conversation
…name Pass --name with a sanitized project name to uv init, and fix get_project_name_from_dir() to strip leading/trailing non-alphanumeric characters (dots, dashes, underscores) per PEP packaging spec. Also update poetry init to use get_project_name_from_dir() instead of the raw directory name for consistency. Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/e415c235-da21-4847-b92c-704513c59e6e Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
usethis tool in directory with leading dotusethis tool failing in directories with leading dots
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@copilot there's a test falling in the GitHub logs. Looks flaky. Please fix and make a lesson for how to avoid this flakiness |
The test_only_dots test created a directory named "..." which on Windows is interpreted as parent directory traversal (../..), causing FileExistsError. Since get_project_name_from_dir() only reads Path.name and never accesses the filesystem, all tests now use PurePosixPath synthetic paths instead of creating real directories. Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/b47fb40c-7e7c-44f9-89e3-258b10a5fe34 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Fixed in 220589e. The |
|
@copilot Basedpyright is failing, please fix |
PurePosixPath is not assignable to Path | str | None. Use tmp_path /
"name" (Path without mkdir) for most tests, and string paths for
Windows-problematic names ("..." and "project.") since usethis_config
.set() accepts str and converts to Path internally.
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/06111449-4dd0-43b5-87cf-f13293af9a57
Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Fixed in 42f76be. |
get_project_name_from_dir()insrc/usethis/_file/dir.pyto strip leading/trailing non-alphanumeric characters (.,-,_) since package names must start and end with a letter or digit per PEP specensure_pyproject_toml_via_uv()andopinionated_uv_init()insrc/usethis/_backend/uv/init.pyto pass--namewith the sanitized project name fromget_project_name_from_dir()ensure_pyproject_toml_via_poetry()andopinionated_poetry_init()insrc/usethis/_backend/poetry/init.pyto useget_project_name_from_dir()instead of rawusethis_config.cpd().namePurePosixPathwithPath/str(basedpyright rejectsPurePosixPathforPath | str | None)Skills used:
usethis-file-create,usethis-qa-static-checks,usethis-python-test-full-coverage,usethis-lesson-create,usethis-github-issue-createResolves #1925