Skip to content

Commit 62543ee

Browse files
committed
Added ngit init, closes #9
Signed-off-by: Nyx <189459385+nyx-4@users.noreply.github.com>
1 parent 6cdfee1 commit 62543ee

20 files changed

+522
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ poetry.toml
173173
# LSP config files
174174
pyrightconfig.json
175175

176-
# End of https://www.toptal.com/developers/gitignore/api/python
176+
# End of https://www.toptal.com/developers/gitignore/api/python

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: pytest-collect
5+
name: 🧪 test · Validate test formatting
6+
entry: pytest
7+
language: system
8+
types: [python]
9+
args: ["--collect-only"]
10+
pass_filenames: false
11+
always_run: true
12+
# STRICT
13+
- id: pytest-fast
14+
name: 🧪 test · Run fast tests
15+
entry: pytest
16+
language: system
17+
types: [python]
18+
args: []
19+
pass_filenames: false
20+
always_run: true
21+
- repo: local
22+
hooks:
23+
- id: faq1
24+
name: 🧪 FAQ · Have you updated CHANGELOG?
25+
entry: fish -Nc "for i in (seq 10); sleep 1; end;"
26+
language: system
27+
always_run: true
28+
- id: faq2
29+
name: 🧪 FAQ · Have you updated version in pyproject.toml?
30+
entry: fish -Nc "for i in (seq 10); sleep 1; end;"
31+
language: system
32+
always_run: true
33+
- repo: https://github.com/gitleaks/gitleaks
34+
rev: v8.28.0
35+
hooks:
36+
- id: gitleaks
37+
name: "🔒 security · Detect hardcoded secrets"
38+
- repo: https://github.com/astral-sh/ruff-pre-commit
39+
rev: v0.12.5
40+
hooks:
41+
- id: ruff-format
42+
name: "🐍 python · Format with Ruff"
43+
# STRICT
44+
- id: ruff
45+
args: [ '--fix', '--ignore=F401' ]
46+
- repo: https://github.com/pre-commit/pre-commit-hooks
47+
rev: v5.0.0
48+
hooks:
49+
- id: check-executables-have-shebangs
50+
name: "📁 filesystem/⚙️ exec · Verify shebang presence"
51+
- id: check-shebang-scripts-are-executable
52+
name: "📁 filesystem/⚙️ exec · Verify script permissions"
53+
- id: check-case-conflict
54+
name: "📁 filesystem/📝 names · Check case sensitivity"
55+
- id: check-illegal-windows-names
56+
name: "📁 filesystem/📝 names · Validate Windows filenames"
57+
- id: check-symlinks
58+
name: "📁 filesystem/🔗 symlink · Check symlink validity"
59+
- id: destroyed-symlinks
60+
name: "📁 filesystem/🔗 symlink · Detect broken symlinks"

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Security
1616
-->
1717

18-
## [Unreleased]
18+
## [0.1.1]
19+
20+
### Added
21+
- pre-commit hooks have beed added.
22+
- A new microproject `ngit` is added.
23+
- ArgParser is added for better CLI arguments support.
24+
- Added Sub-ArgParser for `init` sub-command.
25+
- Added `ngit init` that Initializes a new, empty repository.
26+
- Added `GitRepository` and some helper functions to assisst `ngit init`.
27+
- Added ngit/README stub.
28+
29+
### Fixed
30+
- Minor fixes in calc.
31+
32+
33+
## [0.1.0]
1934

2035
### Changed
2136
- The min, max and sum functions are changed to accomodate single argument.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,34 @@ This is a collection of MicroProjects I code for fun..
44
## Table of Content
55
- [MicroProjects](#microprojects)
66
- [Table of Content](#table-of-content)
7+
- [Getting MicroProjects](#getting-microprojects)
8+
- [Source](#source)
9+
- [PyPI (Python)](#pypi-python)
710
- [1. Calculator](#1-calculator)
811
- [Usage:](#usage)
12+
- [2. ngit](#2-ngit)
13+
- [Usage:](#usage-1)
14+
15+
## Getting MicroProjects
16+
17+
### Source
18+
19+
Clone the development version from [MicroProjects - GitHub](https://github.com/nyx-4/MicroProjects.git)
20+
21+
```sh
22+
git clone https://github.com/nyx-4/MicroProjects.git
23+
cd MicroProjects
24+
pip install .
25+
```
26+
27+
### PyPI (Python)
28+
29+
Use the package manager pip to install foobar.
30+
31+
```sh
32+
pip install microprojects
33+
```
34+
935

1036
## 1. [Calculator](https://github.com/nyx-4/MicroProjects/tree/main/microprojects/calc)
1137
A simple calculator written in Python that _just_ works. The source code is available on [nyx-4/MicroProjects/calc - GitHub](https://github.com/nyx-4/MicroProjects/tree/main/microprojects/calc).
@@ -14,3 +40,14 @@ A simple calculator written in Python that _just_ works. The source code is avai
1440
- From CLI: `calc 5 + 10 x 3 - 2`
1541
- As Python module: `python -m microprojects.calc 5 + 10 x 3 - 2`
1642
- From Python source: `microprojects.calc("5 + 10 x 3 - 2")`
43+
44+
45+
## 2. [ngit](https://github.com/nyx-4/MicroProjects/tree/main/microprojects/ngit)
46+
Git re-implementation in Python that is _perfectly compatible_ with with [Git SCM](https://git-scm.com/). The source code is available on [nyx-4/MicroProjects/ngit - GitHub](https://github.com/nyx-4/MicroProjects/tree/main/microprojects/ngit).
47+
48+
### [Usage](https://github.com/nyx-4/MicroProjects/tree/main/microprojects/ngit#usage):
49+
- From CLI:
50+
```sh
51+
ngit init
52+
```
53+

microprojects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from microprojects.calc.calculator import calc_main, calc
22
from microprojects.calc import analyzer
3+
from microprojects.ngit import ngit_main

microprojects/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
def main():
2-
print("Did you mean: python -m microprojects.calc")
2+
"""Running microprojects as a module causes ambuiguity because
3+
we provides multiple executable scripts.
4+
5+
Did you mean:
6+
python -m microprojects.calc
7+
python -m microprojects.ngit
8+
"""
9+
print(main.__doc__)
310

411

512
if __name__ == "__main__":

microprojects/calc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,5 @@ Taken verbatium from [math - perform mathematics calculations](https://fishshell
195195

196196

197197
## License
198-
All the code here is licensed under [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.en.html). The content and tests taken fish-shell are rightfully theirs and covered under [fish license](https://github.com/fish-shell/fish-shell/?tab=License-1-ov-file)
198+
All my code here is licensed under [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.en.html). The content and tests taken fish-shell are rightfully theirs and covered under [fish license](https://github.com/fish-shell/fish-shell/?tab=License-1-ov-file)
199199

microprojects/calc/analyzer.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,8 @@ def is_pop_needed(o1, o2) -> bool:
153153
output.append(operator_stack.pop())
154154
operator_stack.pop()
155155

156-
elif type(token) == str: # v is operator
157-
while len(operator_stack) and is_pop_needed(
158-
token, operator_stack[-1]
159-
):
156+
elif type(token) is str: # v is operator
157+
while len(operator_stack) and is_pop_needed(token, operator_stack[-1]):
160158
output.append(operator_stack.pop())
161159
operator_stack.append(token)
162160

@@ -191,17 +189,15 @@ def solve_rpn(rev_polish: list, precedence: str, known_lexemes: dict):
191189
idx: int = 0
192190

193191
while idx < len(rev_polish):
194-
if type(rev_polish[idx]) == str:
192+
if type(rev_polish[idx]) is str:
195193
op_func = known_lexemes[rev_polish[idx]]
196194
rev_polish[idx - 2 : idx + 1] = [
197195
op_func(rev_polish[idx - 2], rev_polish[idx - 1])
198196
]
199197
idx -= 3 # Because three items are over-written
200198

201-
elif type(rev_polish[idx]) == list:
202-
rev_polish[idx] = solve_func(
203-
rev_polish[idx], precedence, known_lexemes
204-
)
199+
elif type(rev_polish[idx]) is list:
200+
rev_polish[idx] = solve_func(rev_polish[idx], precedence, known_lexemes)
205201
idx += 1
206202

207203
return rev_polish[0]

microprojects/calc/calculator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
def calc(expr, *, scale=6, scale_mode="default") -> int | float:
77
def Min(*args):
8-
return min(args) if type(args) == tuple else args
8+
return min(args) if type(args) is tuple else args
99

1010
def Max(*args):
11-
return max(args) if type(args) == tuple else args
11+
return max(args) if type(args) is tuple else args
1212

1313
def Sum(*args):
14-
return sum(args) if type(args) == tuple else args
14+
return sum(args) if type(args) is tuple else args
1515

1616
lexemes: dict = {
1717
"^": lambda x, y: x**y,
@@ -81,7 +81,6 @@ def Sum(*args):
8181
"tanh": math.tanh,
8282
"gamma": math.gamma,
8383
"lgamma": math.lgamma,
84-
"lgamma": math.lgamma,
8584
}
8685

8786
operators: str = "^%/*+-"

microprojects/ngit/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)