Skip to content

Commit 6393295

Browse files
Amin Jamalincludeamin
authored andcommitted
Merge pull request #1 from includeamin/init
feat: add first version with green tests
2 parents e1f5c8f + 8db6ec0 commit 6393295

19 files changed

Lines changed: 1880 additions & 1 deletion

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
# Apply unified ruleset for these file endings
13+
[*.{json,yml,yaml,jsonc,jsonschema}]
14+
indent_style = space
15+
indent_size = 2
16+
17+
# Tab indentation
18+
[Makefile]
19+
indent_style = tab

.github/workflows/quality.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Lint and Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
ci:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
python-version: [ "3.11", "3.12", "3.13"]
15+
poetry-version: ["latest"]
16+
os: [ubuntu-22.04, macos-latest, windows-latest]
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v5
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Run image
24+
uses: abatilo/actions-poetry@v3
25+
with:
26+
poetry-version: ${{ matrix.poetry-version }}
27+
- name: install dependencies
28+
run: poetry install
29+
- name: lint
30+
run: make lint
31+
- name: test
32+
run: make test

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Tag and Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
tag-and-release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Required for full git history
17+
18+
- name: Set up Git user
19+
run: |
20+
git config user.name "GitHub Actions"
21+
git config user.email "actions@github.com"
22+
23+
- name: Install git-cliff
24+
run: |
25+
curl -sSL https://github.com/orhun/git-cliff/releases/latest/download/git-cliff-linux-x86_64.tar.gz | tar -xz
26+
sudo mv git-cliff /usr/local/bin/
27+
28+
- name: Get latest tag
29+
id: get_tag
30+
run: |
31+
latest_tag=$(git describe --tags --abbrev=0)
32+
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
33+
34+
- name: Bump version and create new tag
35+
id: new_tag
36+
run: |
37+
# Example: bump patch version (customize as needed)
38+
IFS='.' read -r major minor patch <<< "${{ steps.get_tag.outputs.latest_tag }}"
39+
new_tag="v$major.$minor.$((patch + 1))"
40+
git tag "$new_tag"
41+
git push origin "$new_tag"
42+
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
43+
44+
- name: Generate changelog
45+
run: |
46+
git-cliff -c cliff.toml -t ${{ steps.new_tag.outputs.new_tag }} -o CHANGELOG.md
47+
48+
- name: Create GitHub Release
49+
uses: softprops/action-gh-release@v1
50+
with:
51+
tag_name: ${{ steps.new_tag.outputs.new_tag }}
52+
name: Release ${{ steps.new_tag.outputs.new_tag }}
53+
body_path: CHANGELOG.md
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

.pre-commit-config.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
repos:
2+
- repo: local
3+
# Pre-built hooks for all these "local" checks are available as well. We rather
4+
# define our own to ensure their version matches the one in pyproject.toml/poetry.lock
5+
hooks:
6+
# python code linters
7+
- id: ruff-format
8+
name: ruff-format
9+
language: system
10+
entry: poetry run ruff format
11+
types: [ python ]
12+
- id: ruff-check
13+
name: ruff-check
14+
language: system
15+
entry: poetry run ruff check
16+
types: [ python ]
17+
args: [ --exit-non-zero-on-fix ]
18+
files: .
19+
- id: mypy
20+
name: mypy
21+
language: system
22+
entry: poetry run mypy
23+
types: [ python ]
24+
# poetry checks
25+
- id: poetry-check
26+
name: poetry-check
27+
language: system
28+
entry: poetry check
29+
files: ^pyproject.toml$
30+
pass_filenames: false
31+
- id: poetry-check-lock
32+
name: poetry-check-lock
33+
entry: poetry check
34+
language: system
35+
pass_filenames: false
36+
args: [ "--lock" ]
37+
files: |
38+
(?x)^(
39+
pyproject.toml|
40+
poetry.lock
41+
)$
42+
43+
# common checks that aren't supported by the linters we use in this service
44+
# i.e. in a project that uses prettier, you don't need the json checks
45+
- repo: https://github.com/pre-commit/pre-commit-hooks
46+
rev: v5.0.0
47+
hooks:
48+
- id: check-added-large-files
49+
- id: check-json
50+
- id: check-toml
51+
- id: check-xml
52+
53+
- repo: https://github.com/antonbabenko/pre-commit-terraform
54+
rev: v1.90.0
55+
hooks:
56+
- id: terraform_fmt
57+
- id: terraform_validate # this step might take a minute the first time it runs
58+
59+
- repo: https://github.com/compilerla/conventional-pre-commit
60+
rev: v3.2.0
61+
hooks:
62+
- id: conventional-pre-commit
63+
stages: [ commit-msg ]

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ------------------------------------------------------
2+
# HELP
3+
# ------------------------------------------------------
4+
.PHONY: help
5+
help:
6+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
7+
8+
# ------------------------------------------------------
9+
# LOCAL COMMANDS
10+
# ------------------------------------------------------
11+
.PHONY: test_unit
12+
test: ## Run unit tests
13+
@poetry run pytest ./tests
14+
15+
16+
# this linter just lints src/services/notification/ and tests folders.
17+
# it should gradually covers all other parts of the code as soon all errors have been fixed
18+
.PHONY: lint
19+
lint: ## Run linters with auto-fix.
20+
@poetry run pre-commit run --all-files

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# diff
2-
A library to calculate structured data
2+
3+
Diff is a library to calculate deltas between structured data.
4+
5+
## Features
6+
7+
- Calculate detlas
8+
- Rebuild via deltas
9+
10+
## Supported Formats
11+
12+
- [x] JSON
13+
- [ ] YAML
14+
- [ ] XML
15+
- [ ] TOML
16+
17+
## Usage
18+
19+
### Diff
20+
21+
```python
22+
import diff
23+
24+
old = {"name": "David"}
25+
new = {"name": "Alex"}
26+
deltas = diff.diff(new=new, old=old)
27+
28+
for delta in deltas:
29+
print(delta)
30+
31+
```
32+
33+
Output
34+
35+
```text
36+
Operation(op='modified', path='$.name', new_value='Alex', old_value='David')
37+
```
38+
39+
### Rebuild
40+
41+
```python
42+
import diff
43+
44+
old = {"name": "David"}
45+
new = {"name": "Alex"}
46+
deltas = diff.diff(new=new, old=old)
47+
48+
rebuild_new = diff.patch(base=old, deltas=deltas)
49+
50+
assert rebuild_new == old
51+
```

mypy.ini

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# docs: https://mypy.readthedocs.io/en/stable/config_file.html
2+
[mypy]
3+
python_version = 3.11
4+
allow_redefinition = False
5+
check_untyped_defs = True
6+
disallow_untyped_decorators = True
7+
disallow_any_explicit = False
8+
disallow_any_generics = False
9+
disallow_untyped_calls = True
10+
ignore_errors = False
11+
ignore_missing_imports = True
12+
implicit_reexport = False
13+
strict_optional = True
14+
strict_equality = True
15+
show_traceback = True
16+
no_implicit_optional = True
17+
warn_unused_ignores = True
18+
warn_redundant_casts = True
19+
warn_unused_configs = True
20+
warn_unreachable = True
21+
warn_no_return = True
22+
; plugins =
23+
exclude =
24+
build
25+
.venv

0 commit comments

Comments
 (0)