{"id":7565,"library":"pygnuutils","title":"pygnuutils","description":"pygnuutils is a pure Python implementation for various GNU core utilities, aiming to provide similar functionality in a Pythonic way. It is currently at version 0.1.1 and has a moderate release cadence, with the last update over a year ago.","status":"active","version":"0.1.1","language":"en","source_language":"en","source_url":"https://github.com/matan1008/pygnuutils","tags":["cli","utility","gnu","unix-like","coreutils"],"install":[{"cmd":"pip install pygnuutils","lang":"bash","label":"Install latest stable version"}],"dependencies":[],"imports":[{"note":"Utilities are exposed as classes within their respective modules (e.g., 'ls' utility is 'Ls' class in 'pygnuutils.ls').","wrong":"from pygnuutils import ls","symbol":"Ls","correct":"from pygnuutils.ls import Ls"},{"note":"Similar pattern for other utilities like 'Basename', 'Basenc', 'Yes', 'Filevercmp'.","symbol":"Basename","correct":"from pygnuutils.basename import Basename"}],"quickstart":{"code":"from pygnuutils.ls import Ls\n\n# Instantiate the Ls utility\nls = Ls()\n\n# List contents of the current directory, similar to 'ls -a'\nprint(\"Current directory (ls -a):\")\nls('.', all_=True) # Note: 'all_' for '-a' argument\n\n# List contents of a specific directory in long format, similar to 'ls -l /tmp'\nprint(\"\\n/tmp directory (ls -l):\")\nls('/tmp', long=True)\n\n# Example with dependency injection (a key feature mentioned in README)\nimport os\nclass ReadlinkWatch(Ls.stub):\n    def readlink(self, path, dir_fd=None):\n        print(f'Resolving symlink: {path}...')\n        return os.readlink(path, dir_fd=dir_fd)\n\nls_with_watch = Ls(stub=ReadlinkWatch())\nprint(\"\\nListing with symlink watcher:\")\n# This might require creating a symlink in /tmp for demonstration\n# Example: os.symlink('/etc/passwd', '/tmp/mylink')\n# For safe execution, we won't create it here, but demonstrate the call.\ntry:\n    ls_with_watch('/tmp', long=True)\nexcept OSError as e:\n    print(f\"Could not complete symlink watch example: {e}\")\n    print(\"To run, ensure you have symlinks in /tmp or create one, e.g., 'os.symlink('/etc/passwd', '/tmp/mylink')'\")","lang":"python","description":"This quickstart demonstrates how to initialize and use the `Ls` utility to emulate `ls` commands with Pythonic arguments. It also includes an advanced example of dependency injection, a core feature of `pygnuutils`, to customize behavior like symlink resolution."},"warnings":[{"fix":"Always test `pygnuutils` in your environment, particularly when migrating scripts that rely on specific native GNU utility behaviors or performance characteristics.","message":"pygnuutils is a pure Python re-implementation. It may not offer full feature parity, exact behavioral equivalence, or the same performance as the native C-based GNU utilities, especially for edge cases or large-scale I/O.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the source code or specific utility documentation (if available) for the correct Python keyword arguments. Avoid directly passing string flags as you would in a shell.","message":"Command-line arguments are translated to Pythonic keyword arguments (e.g., `-a` becomes `all_=True`, `-l` becomes `long=True`). The exact mapping might not be immediately obvious or cover all native GNU options.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install pygnuutils` to install the library.","cause":"The `pygnuutils` package is not installed in the active Python environment.","error":"ModuleNotFoundError: No module named 'pygnuutils'"},{"fix":"Check the `pygnuutils` source code or documentation for the specific utility to find the correct Python keyword argument. For `Ls`, common arguments include `all_`, `long`, `recursive`, etc.","cause":"You are attempting to pass a command-line style flag (e.g., `-R`) directly as a keyword argument, but the Python wrapper expects a specific Pythonic argument name (e.g., `recursive=True`).","error":"TypeError: Ls() got an unexpected keyword argument 'some_flag'"}]}