Cleaning projects

Projects usually become cluttered with obsolete files after some time.

To clean the project, type pytask clean

$ pytask clean
────────────────────────── Start pytask session ─────────────────────────
Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0
Root: C:\Users\pytask-dev\git\my_project
Collected 1 task.

Files which can be removed:

Would remove svgs/obsolete_file_1.md
Would remove svgs/obsolete_folder/obsolete_file_2.md
Would remove svgs/obsolete_folder/obsolete_file_3.md
─────────────────────────────────────────────────────────────────────────

pytask performs a dry-run by default and lists all removable files.

If you want to remove the files, use pytask clean --mode with one of the following modes.

  • force removes all files suggested in the dry-run without any confirmation.

  • interactive allows you to decide for every file whether to keep it or not.

If you want to delete complete folders instead of single files, use pytask clean --directories.

$ pytask clean --directories
────────────────────────── Start pytask session ─────────────────────────
Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0
Root: C:\Users\pytask-dev\git\my_project
Collected 1 task.

Files which can be removed:

Would remove svgs/obsolete_file_1.md
Would remove svgs/obsolete_folder
─────────────────────────────────────────────────────────────────────────

Excluding files

pytask excludes files that are under version control with git.

Use the pytask clean --exclude option or the exclude key in the configuration file to exclude files and directories.

Values can be Unix filename patterns that, for example, support the wildcard character * for any characters. You find the documentation in fnmatch.

Here is an example for excluding a folder.

$ pytask clean --exclude obsolete_folder

or

[tool.pytask.ini_options]
exclude = ["obsolete_folder"]

Further reading