dystomachina commited on
Commit
286e013
·
1 Parent(s): 203d1e9

chore: fix lint and introduce pre-commit hooks

Browse files
Makefile CHANGED
@@ -9,6 +9,7 @@ LOGS_DIR := logs
9
  SRC_DIR := src.v2
10
  TIMESTAMP := $(shell date +%Y%m%d_%H%M%S)
11
  PORT := 5000
 
12
 
13
  # Default target
14
  .PHONY: help
@@ -17,6 +18,7 @@ help:
17
  @echo " help - Show this help message"
18
  @echo " env - Set up and activate a virtual environment"
19
  @echo " install - Install dependencies and set script permissions"
 
20
  @echo " train - Train the model (use --sample for training with sample data)"
21
  @echo " predict - Run predictions using console app (usage: make predict [NVDA])"
22
  @echo " mlflow - Start the MLflow UI to view training results (optional: make mlflow PORT=5001)"
@@ -71,6 +73,14 @@ install:
71
  chmod +x $(SCRIPTS_DIR)/*.py && \
72
  echo "Installation complete at: $$(date)") | tee $(LOGS_DIR)/install_$(TIMESTAMP).log
73
  @echo "Installation log saved to: $(LOGS_DIR)/install_$(TIMESTAMP).log"
 
 
 
 
 
 
 
 
74
 
75
  # Train the model
76
  .PHONY: train
 
9
  SRC_DIR := src.v2
10
  TIMESTAMP := $(shell date +%Y%m%d_%H%M%S)
11
  PORT := 5000
12
+ HOOKS_DIR := scripts/git-hooks
13
 
14
  # Default target
15
  .PHONY: help
 
18
  @echo " help - Show this help message"
19
  @echo " env - Set up and activate a virtual environment"
20
  @echo " install - Install dependencies and set script permissions"
21
+ @echo " hooks - Install git hooks for pre-commit checks"
22
  @echo " train - Train the model (use --sample for training with sample data)"
23
  @echo " predict - Run predictions using console app (usage: make predict [NVDA])"
24
  @echo " mlflow - Start the MLflow UI to view training results (optional: make mlflow PORT=5001)"
 
73
  chmod +x $(SCRIPTS_DIR)/*.py && \
74
  echo "Installation complete at: $$(date)") | tee $(LOGS_DIR)/install_$(TIMESTAMP).log
75
  @echo "Installation log saved to: $(LOGS_DIR)/install_$(TIMESTAMP).log"
76
+ @echo "To install git hooks, run 'make hooks'"
77
+
78
+ # Install git hooks
79
+ .PHONY: hooks
80
+ hooks:
81
+ @echo "Installing git hooks..."
82
+ @chmod +x $(SCRIPTS_DIR)/install-git-hooks.sh
83
+ @$(SCRIPTS_DIR)/install-git-hooks.sh
84
 
85
  # Train the model
86
  .PHONY: train
docs/ai-rules.md CHANGED
@@ -7,6 +7,7 @@ alwaysApply: true
7
  - Prior to generating any code, carefully read the project conventions
8
  - Read [project-design.md](docs/project-design.md) to understand the codebase
9
  - Read [project-conventions.md](docs/project-conventions.md) to understand _how_ to write code for the codebase
 
10
 
11
  ## Prohibited actions
12
 
 
7
  - Prior to generating any code, carefully read the project conventions
8
  - Read [project-design.md](docs/project-design.md) to understand the codebase
9
  - Read [project-conventions.md](docs/project-conventions.md) to understand _how_ to write code for the codebase
10
+ - Run `make lint` and `make test` after every change. `lint` in particular can be run very frequently.
11
 
12
  ## Prohibited actions
13
 
scripts/git-hooks/pre-commit ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Pre-commit hook to run linting and tests before allowing a commit
4
+
5
+ echo "Running pre-commit checks..."
6
+
7
+ # Run linting
8
+ echo "Running linter..."
9
+ make lint
10
+ LINT_RESULT=$?
11
+
12
+ if [ $LINT_RESULT -ne 0 ]; then
13
+ echo "Linting failed. Please fix the issues before committing."
14
+ exit 1
15
+ fi
16
+
17
+ # Run tests
18
+ echo "Running tests..."
19
+ make test
20
+ TEST_RESULT=$?
21
+
22
+ if [ $TEST_RESULT -ne 0 ]; then
23
+ echo "Tests failed. Please fix the issues before committing."
24
+ exit 1
25
+ fi
26
+
27
+ echo "All pre-commit checks passed!"
28
+ exit 0
scripts/install-git-hooks.sh ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Script to install git hooks
4
+
5
+ HOOK_DIR=$(git rev-parse --git-dir)/hooks
6
+ PROJECT_HOOK_DIR=scripts/git-hooks
7
+
8
+ echo "Installing git hooks..."
9
+
10
+ # Make sure the hooks directory exists
11
+ mkdir -p $HOOK_DIR
12
+
13
+ # Copy each hook from the project hooks directory to the git hooks directory
14
+ for hook in $PROJECT_HOOK_DIR/*; do
15
+ if [ -f "$hook" ]; then
16
+ hook_name=$(basename $hook)
17
+ echo "Installing $hook_name hook..."
18
+ cp "$hook" "$HOOK_DIR/$hook_name"
19
+ chmod +x "$HOOK_DIR/$hook_name"
20
+ fi
21
+ done
22
+
23
+ echo "Git hooks installed successfully!"
src/stockdata.py CHANGED
@@ -136,7 +136,7 @@ class DataFetcherSingleton:
136
 
137
 
138
  # Convenience function to maintain backward compatibility
139
- def get_data_fetcher(cache_dir=None, **kwargs):
140
  """
141
  Get the singleton instance of the data fetcher.
142
 
@@ -145,7 +145,6 @@ def get_data_fetcher(cache_dir=None, **kwargs):
145
 
146
  Args:
147
  cache_dir (str, optional): Cache directory. If None, uses default.
148
- **kwargs: Additional arguments that are ignored (for backward compatibility)
149
 
150
  Returns:
151
  DataFetcherInterface: The singleton data fetcher instance.
 
136
 
137
 
138
  # Convenience function to maintain backward compatibility
139
+ def get_data_fetcher(cache_dir=None):
140
  """
141
  Get the singleton instance of the data fetcher.
142
 
 
145
 
146
  Args:
147
  cache_dir (str, optional): Cache directory. If None, uses default.
 
148
 
149
  Returns:
150
  DataFetcherInterface: The singleton data fetcher instance.