Skip to content

Commit 446a1c6

Browse files
committed
added testing, removed old implementation ref, made local dev friendlier
1 parent 8e1041c commit 446a1c6

File tree

9 files changed

+365
-919
lines changed

9 files changed

+365
-919
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11.10
1+
3.11

Makefile

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
1-
.PHONY: sync-deps test lint
1+
.PHONY: setup compile-deps sync-deps clean test lint init-tools local-dev first-time-setup update-deps dev-setup sync-all first-time-local-setup
22

3+
# Environment variable for local SDK path (optional)
4+
SOCKET_SDK_PATH ?= ../socket-sdk-python
5+
6+
# Environment variable to control local development mode
7+
USE_LOCAL_SDK ?= false
8+
9+
# === High-level workflow targets ===
10+
11+
# First-time repo setup after cloning (using PyPI packages)
12+
first-time-setup: clean setup
13+
14+
# First-time setup for local development (using local SDK)
15+
first-time-local-setup:
16+
$(MAKE) clean
17+
$(MAKE) USE_LOCAL_SDK=true dev-setup
18+
19+
# Update dependencies after changing pyproject.toml
20+
update-deps: compile-deps sync-deps
21+
22+
# Setup for local development
23+
dev-setup: clean local-dev setup
24+
25+
# Sync all dependencies after pulling changes
26+
sync-all: sync-deps
27+
28+
# === Implementation targets ===
29+
30+
# Creates virtual environment and installs pip-tools
31+
init-tools:
32+
python -m venv .venv
33+
. .venv/bin/activate && pip install pip-tools
34+
35+
# Installs dependencies needed for local development
36+
# Currently: socket-sdk-python from test PyPI or local path
37+
local-dev: init-tools
38+
ifeq ($(USE_LOCAL_SDK),true)
39+
. .venv/bin/activate && pip install -e $(SOCKET_SDK_PATH)
40+
endif
41+
42+
# Creates/updates requirements.txt files with locked versions based on pyproject.toml
43+
compile-deps: local-dev
44+
. .venv/bin/activate && pip-compile --output-file=requirements.txt pyproject.toml
45+
. .venv/bin/activate && pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml
46+
. .venv/bin/activate && pip-compile --extra=test --output-file=requirements-test.txt pyproject.toml
47+
48+
# Creates virtual environment and installs dependencies from pyproject.toml
49+
setup: compile-deps
50+
. .venv/bin/activate && pip install -e ".[dev,test]"
51+
52+
# Installs exact versions from requirements.txt into your virtual environment
353
sync-deps:
4-
pip-compile pyproject.toml -o requirements.txt
54+
. .venv/bin/activate && pip-sync requirements.txt requirements-dev.txt requirements-test.txt
55+
ifeq ($(USE_LOCAL_SDK),true)
56+
. .venv/bin/activate && pip install -e $(SOCKET_SDK_PATH)
57+
endif
58+
59+
# Removes virtual environment and cache files
60+
clean:
61+
rm -rf .venv
62+
find . -type d -name "__pycache__" -exec rm -rf {} +
563

664
test:
765
pytest

README.md

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,61 @@ If you don't want to provide the Socket API Token every time then you can use th
4545

4646
This project uses `pyproject.toml` as the primary dependency specification.
4747

48-
### Installing dependencies with your preferred tool:
49-
- **pip**:
50-
```bash
51-
pip install -r requirements.txt # Install main dependencies
52-
pip install -e ".[dev,test]" # Install development and test dependencies
53-
```
54-
- **poetry**:
55-
```bash
56-
poetry install --all-extras # Installs all dependencies including dev and test
57-
```
58-
- **Rye**:
59-
```bash
60-
rye sync --all-features # Installs all dependencies including dev and test
61-
```
62-
63-
### Changing dependencies:
64-
65-
1. Update `pyproject.toml` with dependency changes
66-
2. Run `make sync-deps` to update `requirements.txt`
67-
- Note: Requires dev dependencies to be installed (`pip-tools`)
48+
### Development Workflows
6849

69-
### Running tests:
50+
The following Make targets provide streamlined workflows for common development tasks:
7051

71-
#### Run all tests:
52+
#### Initial Setup (Choose One)
53+
54+
1. Standard Setup (using PyPI packages):
7255
```bash
73-
make test # Requires dev dependencies to be installed (`pytest`)
56+
pyenv local 3.11 # Ensure correct Python version
57+
make first-time-setup
7458
```
75-
Note: For any of the `pytest` commands below, you can substitute `ptw` for `pytest` to run tests in watch mode.
7659

77-
#### Run specific tests:
60+
2. Local Development Setup (for SDK development):
7861
```bash
79-
# Run all tests in a file
80-
pytest tests/test_socketcli.py
81-
82-
# Run all tests in a directory
83-
pytest tests/core
62+
pyenv local 3.11 # Ensure correct Python version
63+
SOCKET_SDK_PATH=~/path/to/socket-sdk-python make first-time-local-setup
8464
```
65+
The default SDK path is `../socket-sdk-python` if not specified.
8566

67+
#### Ongoing Development Tasks
8668

87-
### Linting:
69+
After changing dependencies in pyproject.toml:
8870
```bash
89-
make lint # Requires dev dependencies to be installed (`ruff`)
71+
make update-deps
72+
```
73+
74+
After pulling changes:
75+
```bash
76+
make sync-all
77+
```
78+
79+
### Available Make targets:
80+
81+
High-level workflows:
82+
- `make first-time-setup`: Complete setup using PyPI packages
83+
- `make first-time-local-setup`: Complete setup for local SDK development
84+
- `make update-deps`: Update requirements.txt files and sync dependencies
85+
- `make sync-all`: Sync dependencies after pulling changes
86+
- `make dev-setup`: Setup for local development (included in first-time-local-setup)
87+
88+
Implementation targets:
89+
- `make init-tools`: Creates virtual environment and installs pip-tools
90+
- `make local-dev`: Installs dependencies needed for local development
91+
- `make compile-deps`: Generates requirements.txt files with locked versions
92+
- `make setup`: Creates virtual environment and installs dependencies
93+
- `make sync-deps`: Installs exact versions from requirements.txt
94+
- `make clean`: Removes virtual environment and cache files
95+
- `make test`: Runs pytest suite
96+
- `make lint`: Runs ruff for code formatting and linting
97+
98+
### Environment Variables
99+
100+
- `SOCKET_SDK_PATH`: Path to local socket-sdk-python repository (default: ../socket-sdk-python)
101+
102+
### Running tests:
103+
104+
#### Run all tests:
90105
```

pyproject.toml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ dependencies = [
1313
'argparse',
1414
'GitPython',
1515
'packaging',
16-
'python-dotenv', # Add this
17-
'socket-sdk-python>=2.0.0'
16+
'python-dotenv',
17+
'socket-sdk-python>=2.0.1'
1818
]
1919
readme = "README.md"
2020
description = "Socket Security CLI for CI/CD"
@@ -64,7 +64,15 @@ version = {attr = "socketsecurity.__version__"}
6464

6565
[tool.coverage.run]
6666
source = ["socketsecurity"]
67-
omit = ["tests/*", "**/__init__.py"]
67+
branch = true
68+
include = [
69+
"socketsecurity/**/*.py",
70+
"socketsecurity/**/__init__.py"
71+
]
72+
omit = [
73+
"socketsecurity/core/issues.py", # Large data file
74+
"socketsecurity/core/licenses.py" # Large data file
75+
]
6876

6977
[tool.coverage.report]
7078
exclude_lines = [
@@ -74,6 +82,8 @@ exclude_lines = [
7482
"raise NotImplementedError",
7583
"if TYPE_CHECKING:",
7684
]
85+
show_missing = true
86+
skip_empty = true
7787

7888
[tool.ruff]
7989
# Exclude a variety of commonly ignored directories.

pytest.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[pytest]
22
testpaths = tests/unit
3-
addopts = -vv --no-cov --tb=short -ra
3+
; addopts = -vv --no-cov --tb=short -ra
4+
addopts = -vv --tb=short -ra --cov=socketsecurity --cov-report=term-missing
45
python_files = test_*.py
6+
asyncio_mode = strict
7+
asyncio_default_fixture_loop_scope = function

0 commit comments

Comments
 (0)