modelit 0.2.3__tar.gz → 0.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- modelit-0.2.5/CONTRIBUTING.md +53 -0
- modelit-0.2.5/MANIFEST.in +1 -0
- {modelit-0.2.3 → modelit-0.2.5}/PKG-INFO +7 -1
- {modelit-0.2.3 → modelit-0.2.5}/README.md +6 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit/registry.py +29 -9
- modelit-0.2.5/modelit/templates/abstract_factory_pattern/template.java +44 -0
- modelit-0.2.5/modelit/templates/adapter_pattern/template.java +25 -0
- modelit-0.2.5/modelit/templates/bridge_pattern/template.java +54 -0
- modelit-0.2.5/modelit/templates/builder_pattern/template.java +58 -0
- modelit-0.2.5/modelit/templates/cnn/template.py +491 -0
- modelit-0.2.5/modelit/templates/command_pattern/template.java +58 -0
- modelit-0.2.5/modelit/templates/composite_pattern/template.java +53 -0
- modelit-0.2.5/modelit/templates/decorator_pattern/template.java +39 -0
- modelit-0.2.5/modelit/templates/facade_pattern/template.java +42 -0
- modelit-0.2.5/modelit/templates/factory_pattern/template.java +36 -0
- modelit-0.2.5/modelit/templates/flyweight_pattern/template.java +47 -0
- modelit-0.2.5/modelit/templates/interpreter_pattern/template.java +36 -0
- modelit-0.2.5/modelit/templates/mediator_pattern/template.java +62 -0
- modelit-0.2.5/modelit/templates/memento_pattern/template.java +50 -0
- modelit-0.2.5/modelit/templates/observer_pattern/template.java +47 -0
- modelit-0.2.5/modelit/templates/prototype_pattern/template.java +38 -0
- modelit-0.2.5/modelit/templates/proxy_pattern/template.java +48 -0
- modelit-0.2.5/modelit/templates/state_pattern/template.java +40 -0
- modelit-0.2.5/modelit/templates/template_pattern/template.java +40 -0
- modelit-0.2.5/modelit/templates/visitor_pattern/template.java +42 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit.egg-info/PKG-INFO +7 -1
- modelit-0.2.5/modelit.egg-info/SOURCES.txt +39 -0
- {modelit-0.2.3 → modelit-0.2.5}/pyproject.toml +1 -1
- modelit-0.2.3/MANIFEST.in +0 -1
- modelit-0.2.3/modelit.egg-info/SOURCES.txt +0 -18
- {modelit-0.2.3 → modelit-0.2.5}/.github/workflows/publish.yml +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/.github/workflows/test.yml +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/.gitignore +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/LICENSE +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit/__init__.py +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit/__main__.py +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit/cli.py +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit/templates/backpropagation/template.py +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit/templates/perceptron/template.py +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit.egg-info/dependency_links.txt +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit.egg-info/entry_points.txt +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/modelit.egg-info/top_level.txt +0 -0
- {modelit-0.2.3 → modelit-0.2.5}/setup.cfg +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Contributing to ModelIt
|
|
2
|
+
|
|
3
|
+
Thanks for helping improve ModelIt.
|
|
4
|
+
|
|
5
|
+
## Add a new template
|
|
6
|
+
|
|
7
|
+
1. Fork this repo.
|
|
8
|
+
2. Create a new folder:
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
modelit/templates/<name>/
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
3. Add your code in:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
modelit/templates/<name>/template.py
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
4. Make sure the folder name is the function name.
|
|
21
|
+
5. Test it locally:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from modelit import <name>
|
|
25
|
+
|
|
26
|
+
<name>()
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
modelit create <name>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Rules
|
|
36
|
+
|
|
37
|
+
- Keep templates simple and runnable.
|
|
38
|
+
- Avoid internet-only dependencies.
|
|
39
|
+
- Do not add `metadata.json`.
|
|
40
|
+
- Keep file names lowercase.
|
|
41
|
+
- Prefer clean, beginner-friendly code.
|
|
42
|
+
|
|
43
|
+
## Pull request flow
|
|
44
|
+
|
|
45
|
+
1. Fork the repo.
|
|
46
|
+
2. Create a branch.
|
|
47
|
+
3. Add your template.
|
|
48
|
+
4. Commit and push.
|
|
49
|
+
5. Open a pull request.
|
|
50
|
+
|
|
51
|
+
## Maintainer notes
|
|
52
|
+
|
|
53
|
+
I will review templates for clarity, correctness, and portability before merging.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include modelit/templates *.py *.java *.json
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modelit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: Local-first ML starter templates you can print or save
|
|
5
5
|
Author: Yashsmith
|
|
6
6
|
License-Expression: MIT
|
|
@@ -86,6 +86,12 @@ modelit/templates/mycode/
|
|
|
86
86
|
modelit/templates/mycode/template.py
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
For Java, use:
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
modelit/templates/mycode/template.java
|
|
93
|
+
```
|
|
94
|
+
|
|
89
95
|
3. Done. The folder name becomes the function name.
|
|
90
96
|
|
|
91
97
|
That means this will work automatically:
|
|
@@ -66,6 +66,12 @@ modelit/templates/mycode/
|
|
|
66
66
|
modelit/templates/mycode/template.py
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
For Java, use:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
modelit/templates/mycode/template.java
|
|
73
|
+
```
|
|
74
|
+
|
|
69
75
|
3. Done. The folder name becomes the function name.
|
|
70
76
|
|
|
71
77
|
That means this will work automatically:
|
|
@@ -9,7 +9,6 @@ from pathlib import Path
|
|
|
9
9
|
|
|
10
10
|
PACKAGE_NAME = "modelit"
|
|
11
11
|
TEMPLATES_DIR = "templates"
|
|
12
|
-
TEMPLATE_FILENAME = "template.py"
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
@dataclass(frozen=True)
|
|
@@ -25,6 +24,19 @@ def _template_dir(name: str):
|
|
|
25
24
|
return _templates_root().joinpath(name)
|
|
26
25
|
|
|
27
26
|
|
|
27
|
+
def _get_template_file(name_or_dir):
|
|
28
|
+
target_dir = _template_dir(name_or_dir) if isinstance(name_or_dir, str) else name_or_dir
|
|
29
|
+
|
|
30
|
+
if not target_dir.is_dir():
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
for child in target_dir.iterdir():
|
|
34
|
+
if child.is_file() and child.name.startswith("template."):
|
|
35
|
+
return child
|
|
36
|
+
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
|
|
28
40
|
def available_models() -> tuple[str, ...]:
|
|
29
41
|
root = _templates_root()
|
|
30
42
|
if not root.is_dir():
|
|
@@ -32,7 +44,7 @@ def available_models() -> tuple[str, ...]:
|
|
|
32
44
|
|
|
33
45
|
names: list[str] = []
|
|
34
46
|
for child in root.iterdir():
|
|
35
|
-
if child.is_dir() and child
|
|
47
|
+
if child.is_dir() and _get_template_file(child) is not None:
|
|
36
48
|
names.append(child.name)
|
|
37
49
|
return tuple(sorted(names))
|
|
38
50
|
|
|
@@ -41,17 +53,25 @@ def load_metadata(name: str) -> TemplateInfo:
|
|
|
41
53
|
return TemplateInfo(name=name)
|
|
42
54
|
|
|
43
55
|
|
|
44
|
-
def
|
|
45
|
-
|
|
46
|
-
if
|
|
56
|
+
def load_source_and_ext(name: str) -> tuple[str, str]:
|
|
57
|
+
template_file = _get_template_file(name)
|
|
58
|
+
if template_file is None:
|
|
47
59
|
raise FileNotFoundError(f"Missing template source for {name!r}")
|
|
48
|
-
|
|
60
|
+
|
|
61
|
+
ext = Path(template_file.name).suffix
|
|
62
|
+
return template_file.read_text(encoding="utf-8"), ext
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def load_source(name: str) -> str:
|
|
66
|
+
source, _ = load_source_and_ext(name)
|
|
67
|
+
return source
|
|
49
68
|
|
|
50
69
|
|
|
51
70
|
def build_template_callable(name: str):
|
|
52
|
-
source =
|
|
71
|
+
source, ext = load_source_and_ext(name)
|
|
53
72
|
info = load_metadata(name)
|
|
54
|
-
|
|
73
|
+
|
|
74
|
+
output_file = f"{name}{ext}"
|
|
55
75
|
|
|
56
76
|
def runner(output: str | None = None) -> None:
|
|
57
77
|
if output:
|
|
@@ -71,4 +91,4 @@ def build_template_callable(name: str):
|
|
|
71
91
|
runner.__doc__ = f"Print or save the {name} template."
|
|
72
92
|
runner.output_file = output_file # type: ignore[attr-defined]
|
|
73
93
|
runner.template_info = info # type: ignore[attr-defined]
|
|
74
|
-
return runner
|
|
94
|
+
return runner
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
interface Button { void render(); }
|
|
2
|
+
interface Checkbox { void render(); }
|
|
3
|
+
|
|
4
|
+
class WinButton implements Button {
|
|
5
|
+
public void render() { System.out.println("Rendering Windows Button"); }
|
|
6
|
+
}
|
|
7
|
+
class MacButton implements Button {
|
|
8
|
+
public void render() { System.out.println("Rendering macOS Button"); }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class WinCheckbox implements Checkbox {
|
|
12
|
+
public void render() { System.out.println("Rendering Windows Checkbox"); }
|
|
13
|
+
}
|
|
14
|
+
class MacCheckbox implements Checkbox {
|
|
15
|
+
public void render() { System.out.println("Rendering macOS Checkbox"); }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface GUIFactory {
|
|
19
|
+
Button createButton();
|
|
20
|
+
Checkbox createCheckbox();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class WindowsFactory implements GUIFactory {
|
|
24
|
+
public Button createButton() { return new WinButton(); }
|
|
25
|
+
public Checkbox createCheckbox() { return new WinCheckbox(); }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class MacOSFactory implements GUIFactory {
|
|
29
|
+
public Button createButton() { return new MacButton(); }
|
|
30
|
+
public Checkbox createCheckbox() { return new MacCheckbox(); }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public class AbstractFactoryDemo {
|
|
34
|
+
public static void main(String[] args) {
|
|
35
|
+
String os = "Mac";
|
|
36
|
+
GUIFactory factory = os.equals("Mac") ? new MacOSFactory() : new WindowsFactory();
|
|
37
|
+
|
|
38
|
+
Button button = factory.createButton();
|
|
39
|
+
Checkbox checkbox = factory.createCheckbox();
|
|
40
|
+
|
|
41
|
+
button.render();
|
|
42
|
+
checkbox.render();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface PaymentProcessor {
|
|
2
|
+
void processPayment(double amount);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
class StripeService {
|
|
6
|
+
public void makePayment(double amountInCents) {
|
|
7
|
+
System.out.println("Stripe: Processing payment of " + amountInCents + " cents successfully.");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class StripeAdapter implements PaymentProcessor {
|
|
12
|
+
private StripeService stripeService = new StripeService();
|
|
13
|
+
|
|
14
|
+
public void processPayment(double amount) {
|
|
15
|
+
double amountInCents = amount * 100;
|
|
16
|
+
stripeService.makePayment(amountInCents);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public class AdapterDemo {
|
|
21
|
+
public static void main(String[] args) {
|
|
22
|
+
PaymentProcessor processor = new StripeAdapter();
|
|
23
|
+
processor.processPayment(50.00);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
interface Device {
|
|
2
|
+
void turnOn();
|
|
3
|
+
void turnOff();
|
|
4
|
+
void setVolume(int percent);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
class SmartTV implements Device {
|
|
8
|
+
private int volume = 30;
|
|
9
|
+
public void turnOn() { System.out.println("Smart TV is ON"); }
|
|
10
|
+
public void turnOff() { System.out.println("Smart TV is OFF"); }
|
|
11
|
+
public void setVolume(int percent) {
|
|
12
|
+
volume = percent;
|
|
13
|
+
System.out.println("Smart TV Volume set to " + volume);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
abstract class RemoteControl {
|
|
18
|
+
protected Device device;
|
|
19
|
+
public RemoteControl(Device device) { this.device = device; }
|
|
20
|
+
public abstract void togglePower();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class BasicRemote extends RemoteControl {
|
|
24
|
+
public BasicRemote(Device device) { super(device); }
|
|
25
|
+
public void togglePower() {
|
|
26
|
+
System.out.println("\n[Basic Remote Used]");
|
|
27
|
+
device.turnOn();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class AdvancedRemote extends RemoteControl {
|
|
32
|
+
public AdvancedRemote(Device device) { super(device); }
|
|
33
|
+
public void togglePower() {
|
|
34
|
+
System.out.println("\n[Advanced Remote Used]");
|
|
35
|
+
device.turnOn();
|
|
36
|
+
}
|
|
37
|
+
public void mute() {
|
|
38
|
+
System.out.println("Muting Device...");
|
|
39
|
+
device.setVolume(0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public class BridgeDemo {
|
|
44
|
+
public static void main(String[] args) {
|
|
45
|
+
Device tv = new SmartTV();
|
|
46
|
+
|
|
47
|
+
BasicRemote basicRemote = new BasicRemote(tv);
|
|
48
|
+
basicRemote.togglePower();
|
|
49
|
+
|
|
50
|
+
AdvancedRemote advancedRemote = new AdvancedRemote(tv);
|
|
51
|
+
advancedRemote.togglePower();
|
|
52
|
+
advancedRemote.mute();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
class UserProfile {
|
|
2
|
+
private final String username;
|
|
3
|
+
private final String email;
|
|
4
|
+
private final int age;
|
|
5
|
+
private final String phone;
|
|
6
|
+
|
|
7
|
+
private UserProfile(Builder builder) {
|
|
8
|
+
this.username = builder.username;
|
|
9
|
+
this.email = builder.email;
|
|
10
|
+
this.age = builder.age;
|
|
11
|
+
this.phone = builder.phone;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public void showProfile() {
|
|
15
|
+
System.out.println("User: " + username + " | Email: " + email + " | Age: " + age + " | Phone: " + phone);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static class Builder {
|
|
19
|
+
private String username;
|
|
20
|
+
private String email;
|
|
21
|
+
private int age = 0;
|
|
22
|
+
private String phone = "N/A";
|
|
23
|
+
|
|
24
|
+
public Builder(String username, String email) {
|
|
25
|
+
this.username = username;
|
|
26
|
+
this.email = email;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public Builder setAge(int age) {
|
|
30
|
+
this.age = age;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public Builder setPhone(String phone) {
|
|
35
|
+
this.phone = phone;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public UserProfile build() {
|
|
40
|
+
return new UserProfile(this);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public class BuilderDemo {
|
|
46
|
+
public static void main(String[] args) {
|
|
47
|
+
UserProfile user1 = new UserProfile.Builder("user", "user@example.com")
|
|
48
|
+
.setAge(21)
|
|
49
|
+
.build();
|
|
50
|
+
|
|
51
|
+
UserProfile user2 = new UserProfile.Builder("admin_user", "admin@sys.com")
|
|
52
|
+
.setPhone("+91-9876543210")
|
|
53
|
+
.build();
|
|
54
|
+
|
|
55
|
+
user1.showProfile();
|
|
56
|
+
user2.showProfile();
|
|
57
|
+
}
|
|
58
|
+
}
|