diff --git a/README.md b/README.md index defe80b..743df0a 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,33 @@ pip3 install git+https://github.com/Scony/godot-gdscript-toolkit.git pipx install git+https://github.com/Scony/godot-gdscript-toolkit.git ``` +### Using Nix + +If you have [Nix](https://nixos.org/) installed, you can run gdtoolkit tools without installing them: + +```bash +# Show available commands and usage help +nix run github:Scony/godot-gdscript-toolkit + +# Run specific tools +nix run github:Scony/godot-gdscript-toolkit#gdformat -- --help +nix run github:Scony/godot-gdscript-toolkit#gdlint -- myfile.gd +nix run github:Scony/godot-gdscript-toolkit#gdparse -- myfile.gd -p +nix run github:Scony/godot-gdscript-toolkit#gdradon -- cc myfile.gd +``` + +Available commands: +- `gdformat` - Code formatter +- `gdlint` - Static analysis linter +- `gdparse` - Parser for debugging/educational purposes +- `gdradon` - Cyclomatic complexity calculator + +Or enter a development shell with all tools available: + +```bash +nix develop github:Scony/godot-gdscript-toolkit +``` + ## Linting with gdlint [(more)](https://github.com/Scony/godot-gdscript-toolkit/wiki/3.-Linter) To run a linter you need to execute `gdlint` command like: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..304ce35 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1751307573, + "narHash": "sha256-cZWeBKZwU0KkqIXCk2L/1m8A2pH6Pbmrd0FfxY5yKG0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3a1f517d252056955bf79f888da019d99bb719a6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5ce83e8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,149 @@ +{ + description = + "set of tools for working with GDScript: parser, linter, formatter and code analysis"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + pythonWithPkgs = pkgs.python3.withPackages + (ps: with ps; [ lark docopt-ng pyyaml radon setuptools ]); + + appVersion = "4.3.4"; + + helpScript = pkgs.writeShellScript "gdtoolkit-help" '' + echo "GDScript Toolkit - Available commands:" + echo "" + echo "Usage: nix run github:Scony/godot-gdscript-toolkit# -- [args]" + echo "" + echo "Available commands:" + echo " gdparse - GDScript parser for debugging and educational purposes" + echo " gdlint - GDScript linter that performs static analysis" + echo " gdformat - GDScript formatter that formats code according to predefined rules" + echo " gdradon - GDScript code complexity analysis (calculates cyclomatic complexity)" + echo "" + echo "Examples:" + echo " nix run github:Scony/godot-gdscript-toolkit#gdformat -- --help" + echo " nix run github:Scony/godot-gdscript-toolkit#gdlint -- myfile.gd" + echo " nix run github:Scony/godot-gdscript-toolkit#gdparse -- myfile.gd -p" + echo "" + echo "For local development:" + echo " nix develop # Enter development shell with all tools available" + ''; + in { + packages = { + gdtoolkit = pkgs.python3.pkgs.buildPythonPackage { + pname = "gdtoolkit"; + version = appVersion; + src = self; + + propagatedBuildInputs = with pkgs.python3.pkgs; [ + lark + docopt-ng + pyyaml + radon + setuptools + ]; + + # Create console scripts + postInstall = '' + mkdir -p $out/bin + echo '#!/usr/bin/env python' > $out/bin/gdparse + echo 'import sys; from gdtoolkit.parser.__main__ import main; sys.exit(main())' >> $out/bin/gdparse + echo '#!/usr/bin/env python' > $out/bin/gdlint + echo 'import sys; from gdtoolkit.linter.__main__ import main; sys.exit(main())' >> $out/bin/gdlint + echo '#!/usr/bin/env python' > $out/bin/gdformat + echo 'import sys; from gdtoolkit.formatter.__main__ import main; sys.exit(main())' >> $out/bin/gdformat + echo '#!/usr/bin/env python' > $out/bin/gdradon + echo 'import sys; from gdtoolkit.gdradon.__main__ import main; sys.exit(main())' >> $out/bin/gdradon + chmod +x $out/bin/* + ''; + }; + + default = self.packages.${system}.gdtoolkit; + }; + + apps = { + help = { + type = "app"; + program = "${helpScript}"; + meta = with pkgs.lib; { + description = "Show available GDScript Toolkit commands"; + homepage = "https://github.com/Scony/godot-gdscript-toolkit"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + + gdparse = { + type = "app"; + program = "${self.packages.${system}.gdtoolkit}/bin/gdparse"; + meta = with pkgs.lib; { + description = "GDScript parser"; + homepage = "https://github.com/Scony/godot-gdscript-toolkit"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + + gdlint = { + type = "app"; + program = "${self.packages.${system}.gdtoolkit}/bin/gdlint"; + meta = with pkgs.lib; { + description = "GDScript linter"; + homepage = "https://github.com/Scony/godot-gdscript-toolkit"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + + gdformat = { + type = "app"; + program = "${self.packages.${system}.gdtoolkit}/bin/gdformat"; + meta = with pkgs.lib; { + description = "GDScript formatter"; + homepage = "https://github.com/Scony/godot-gdscript-toolkit"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + + gdradon = { + type = "app"; + program = "${self.packages.${system}.gdtoolkit}/bin/gdradon"; + meta = with pkgs.lib; { + description = "GDScript code complexity analysis"; + homepage = "https://github.com/Scony/godot-gdscript-toolkit"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + + default = self.apps.${system}.help; + }; + + devShells = { + default = pkgs.mkShell { + name = "gdtoolkit-dev-env"; + packages = [ pythonWithPkgs ]; + + shellHook = '' + export HISTFILE=$HOME/.history_nix + export PYTHONPATH=${builtins.toString ./.}:$PYTHONPATH + export PATH=${pythonWithPkgs}/bin:$PATH + alias gdparse="python -m gdtoolkit.parser" + alias gdlint="python -m gdtoolkit.linter" + alias gdformat="python -m gdtoolkit.formatter" + alias gdradon="python -m gdtoolkit.gdradon" + echo "GDScript Toolkit development environment activated" + echo "Available commands: gdparse, gdlint, gdformat, gdradon" + ''; + }; + }; + }); +}