From 78725a4eed2a3cdf5c01047067b1f42187ca123f Mon Sep 17 00:00:00 2001 From: Johan Sandoval Date: Tue, 21 Jul 2026 19:01:11 -0500 Subject: [PATCH] Set up python environment for easier development --- .envrc | 1 + .gitignore | 5 +++++ 1-Two-Sum/Solution.py | 3 --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 18 ++++++++++++++++++ new.sh | 12 ++++++++++++ pyproject.toml | 9 +++++++++ 7 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore delete mode 100644 1-Two-Sum/Solution.py create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 new.sh create mode 100644 pyproject.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f58d9a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.direnv/ +__pycache__/ +.pytest_cache/ +.ruff_cache/ +result diff --git a/1-Two-Sum/Solution.py b/1-Two-Sum/Solution.py deleted file mode 100644 index 33e87dc..0000000 --- a/1-Two-Sum/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def twoSum(self, nums: List[int], target: int) -> List[int]: - diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..fdfbda4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1784497964, + "narHash": "sha256-vlHUuqAcbcH2RKmHbPiuQzbv1pnzzavXnI62RD0bqCU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "241313f4e8e508cb9b13278c2b0fa25b9ca27163", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c3a5247 --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.${system}.default = pkgs.mkShell { + packages = with pkgs; [ + python313 + ruff # lint + format + basedpyright # LSP / type checking + python313Packages.pytest + entr + ]; + }; + }; +} diff --git a/new.sh b/new.sh new file mode 100755 index 0000000..1fd75a7 --- /dev/null +++ b/new.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +d="problems/$1"; mkdir -p "$d" +cat > "$d/solution.py" <<'EOF' +class Solution: + def solve(self): + pass +EOF +cat > "$d/solution_test.py" <<'EOF' +from solution import Solution +def test_solve(): + assert Solution().solve() is None +EOF diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f095949 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[tool.ruff] +line-length = 100 + +[tool.ruff.lint] +select = ["E", "F", "I", "UP", "B", "SIM"] + +[tool.pytest.ini_options] +testpaths = ["."] +python_files = ["*_test.py"]