instructor-examples 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1 @@
1
+ """Top-level package for Instructor Examples."""
@@ -0,0 +1,4 @@
1
+ from .cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()
@@ -0,0 +1,35 @@
1
+ """Console script for instructor_examples."""
2
+
3
+ import typer
4
+ from rich.console import Console
5
+
6
+ from instructor_examples import utils
7
+
8
+ app = typer.Typer()
9
+ console = Console()
10
+
11
+
12
+ @app.command()
13
+ def main(
14
+ remote_repo_folder: str = typer.Argument(..., help="Input remote_repo_folder path."),
15
+ out_folder: str = typer.Option(None, help="Optional output folder."),
16
+ repo: str = typer.Option(None, help="Optional repo path."),
17
+ ) -> None:
18
+ """Console script for instructor_examples."""
19
+ console.print(f"Input remote_repo_folder: {remote_repo_folder}")
20
+
21
+ if out_folder:
22
+ console.print(f"Output folder: {out_folder}")
23
+ else:
24
+ console.print("No output folder specified. Using current folder.")
25
+
26
+ utils.run(
27
+ remote_repo_folder=remote_repo_folder,
28
+ out_folder=out_folder,
29
+ repo=repo,
30
+ console=console,
31
+ )
32
+
33
+
34
+ if __name__ == "__main__":
35
+ app()
@@ -0,0 +1 @@
1
+ # Marker file for PEP 561
@@ -0,0 +1,164 @@
1
+ import json
2
+ import os
3
+ from urllib.parse import urlparse
4
+
5
+ import requests
6
+ from rich.console import Console
7
+
8
+
9
+ class InstructorExamplesCopier:
10
+ def __init__(
11
+ self,
12
+ remote_repo_folder: str,
13
+ out_folder: str | None = None,
14
+ repo: str | None = None,
15
+ console: Console | None = None,
16
+ ) -> None:
17
+ # clean the remote_repo_folder to remove any non-ASCII characters that might cause issues.
18
+ self.remote_repo_folder = self.clean_remote_repo_folder(remote_repo_folder)
19
+
20
+ if out_folder:
21
+ print(f"Output folder specified: {out_folder}")
22
+ else:
23
+ out_folder = "."
24
+ # get the repository from settings or by the repo command.
25
+ self.out_folder = out_folder
26
+ if self.out_folder is None:
27
+ self.out_folder = os.getcwd()
28
+ self.repo = repo
29
+
30
+ if repo:
31
+ print(f"Repo specified: {repo}")
32
+ else:
33
+ self.settings_file = self.find_settings_file(out_folder)
34
+ if self.settings_file:
35
+ print(f"Found settings file at: {self.settings_file}, parsing...")
36
+ self.settings = self.parse_settings()
37
+ self.repo = self.settings.get("repo")
38
+
39
+ print(repo)
40
+ else:
41
+ print(
42
+ "No settings file found. Please specify the --repo option or ensure "
43
+ "instructor_examples_settings.json file is in the folder tree."
44
+ )
45
+
46
+ # Initialize repo_owner and repo_name to None. They will be set if the repo URL is valid and can be parsed.
47
+ self.repo_owner = None
48
+ self.repo_name = None
49
+ self.parse_repo_url()
50
+
51
+ def clean_remote_repo_folder(self, remote_repo_folder: str) -> str:
52
+ cleaned_remote_repo_folder = "".join(c for c in remote_repo_folder if ord(c) < 128)
53
+
54
+ return cleaned_remote_repo_folder
55
+
56
+ def parse_repo_url(self) -> None:
57
+ """
58
+ Parse the repository URL to extract the owner and repository name.
59
+ This is a placeholder implementation. You can replace it with actual parsing logic.
60
+ """
61
+ if self.repo:
62
+ # this is for github only.
63
+ path = urlparse(self.repo).path.strip("/")
64
+ owner, repo = path.split("/")[:2]
65
+ self.repo_owner = owner
66
+ self.repo_name = repo
67
+ return None
68
+
69
+ def copy_repo_contents(
70
+ self,
71
+ repo_folder: str | None = None,
72
+ folder: str | None = None,
73
+ branch: str | None = None,
74
+ ) -> None:
75
+ """
76
+ Recursively copy all files and folders from the GitHub repo to the output folder.
77
+ """
78
+ if repo_folder is None:
79
+ repo_folder = self.remote_repo_folder
80
+ if folder is None:
81
+ folder = self.out_folder + "/" + repo_folder
82
+ if not os.path.exists(folder):
83
+ os.makedirs(folder, exist_ok=True)
84
+
85
+ api = f"https://api.github.com/repos/{self.repo_owner}/{self.repo_name}/contents/{repo_folder}"
86
+ if branch:
87
+ api += f"?ref={branch}"
88
+
89
+ print(f"Fetching: {api}")
90
+ r = requests.get(api)
91
+ r.raise_for_status()
92
+ contents = r.json()
93
+ # loop through the contents and download files or recurse into directories
94
+ print("Downloading Folder:", repo_folder)
95
+ for item in contents:
96
+ if item["type"] == "file":
97
+ file_url = item["download_url"]
98
+ file_path = os.path.join(folder, item["name"])
99
+
100
+ content = requests.get(file_url).content
101
+ with open(file_path, "wb") as f:
102
+ f.write(content)
103
+ elif item["type"] == "dir":
104
+ subfolder = os.path.join(folder, item["name"])
105
+ self.copy_repo_contents(
106
+ repo_folder=item["path"],
107
+ folder=subfolder,
108
+ branch=branch,
109
+ )
110
+
111
+ def parse_settings(self) -> dict:
112
+ """
113
+ Parse the settings from the found settings file.
114
+ Returns a dictionary of settings if the file is found and valid, else returns an empty dictionary.
115
+ """
116
+ if not hasattr(self, "settings_file") or not self.settings_file:
117
+ print("No settings file to parse.")
118
+ return {}
119
+ try:
120
+ with open(self.settings_file) as f:
121
+ settings = json.load(f)
122
+ print(f"Parsed settings: {settings}")
123
+ return settings
124
+ except Exception as e:
125
+ print(f"Error parsing settings file: {e}")
126
+ return {}
127
+
128
+ def find_settings_file(self, start_path: str | None = None) -> str | None:
129
+ """
130
+ Recursively search up the folder tree for the file instructor_examples_settings.json
131
+ Returns the path to the file if found, else returns None.
132
+ """
133
+ print(
134
+ "Searching for 'instructor_examples_settings.json' starting from:",
135
+ start_path or os.getcwd(),
136
+ )
137
+ if start_path is None:
138
+ start_path = os.getcwd()
139
+ current_dir = os.path.abspath(start_path)
140
+
141
+ while True:
142
+ candidate = os.path.join(current_dir, "instructor_examples_settings.json")
143
+ if os.path.isfile(candidate):
144
+ return candidate
145
+ parent_dir = os.path.dirname(current_dir)
146
+ if parent_dir == current_dir:
147
+ # Reached the root directory
148
+ return None
149
+ current_dir = parent_dir
150
+
151
+
152
+ def run(
153
+ remote_repo_folder: str,
154
+ repo: str,
155
+ console: Console,
156
+ out_folder: str | None = None,
157
+ ) -> None:
158
+ copier = InstructorExamplesCopier(
159
+ remote_repo_folder=remote_repo_folder,
160
+ out_folder=out_folder,
161
+ repo=repo,
162
+ console=console,
163
+ )
164
+ copier.copy_repo_contents()
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: instructor_examples
3
+ Version: 0.1.0
4
+ Summary: Copy github examples to your local envri
5
+ Project-URL: bugs, https://github.com/dgmouris/instructor_examples/issues
6
+ Project-URL: changelog, https://github.com/dgmouris/instructor_examples/blob/main/HISTORY.md
7
+ Project-URL: documentation, https://dgmouris.github.io/instructor_examples/
8
+ Project-URL: homepage, https://github.com/dgmouris/instructor_examples
9
+ Author-email: Daniel Mouris <dgmouris@gmail.com>
10
+ Maintainer-email: Daniel Mouris <dgmouris@gmail.com>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: requests>=2.32.5
16
+ Requires-Dist: rich
17
+ Requires-Dist: typer
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Instructor Examples
21
+
22
+ ![PyPI version](https://img.shields.io/pypi/v/instructor_examples.svg)
23
+
24
+ Copy github examples to your local environment without needing to clone the entire repository.
25
+
26
+ * Created by **[Daniel Mouris](https://github.com/dgmouris)**
27
+ * PyPI: https://pypi.org/user/dgmouris/
28
+ * PyPI package: https://pypi.org/project/instructor_examples/
29
+ * Free software: MIT License
30
+
31
+ ## Features
32
+
33
+ Copies files and folders from GitHub to a local environment.
34
+
35
+ ## Documentation
36
+
37
+ Documentation is built with [Zensical](https://zensical.org/) and deployed to GitHub Pages.
38
+
39
+ * **Live site:** https://dgmouris.github.io/instructor_examples/
40
+ * **Preview locally:** `just docs-serve` (serves at http://localhost:8000)
41
+ * **Build:** `just docs-build`
42
+
43
+ API documentation is auto-generated from docstrings using [mkdocstrings](https://mkdocstrings.github.io/).
44
+
45
+ Docs deploy automatically on push to `main` via GitHub Actions. To enable this, go to your repo's Settings > Pages and set the source to **GitHub Actions**.
46
+
47
+ ## Development
48
+
49
+ To set up for local development:
50
+
51
+ ```bash
52
+ # Clone your fork
53
+ git clone git@github.com:your_username/instructor_examples.git
54
+ cd instructor_examples
55
+
56
+ # Install in editable mode with live updates
57
+ uv tool install --editable .
58
+ ```
59
+
60
+ This installs the CLI globally but with live updates - any changes you make to the source code are immediately available when you run `instructor_examples`.
61
+
62
+ Run tests:
63
+
64
+ ```bash
65
+ uv run pytest
66
+ ```
67
+
68
+ Run quality checks (format, lint, type check, test):
69
+
70
+ ```bash
71
+ just qa
72
+ ```
73
+
74
+ ## Author
75
+
76
+ Instructor Examples was created in 2026 by Daniel Mouris.
77
+
78
+ Built with [Cookiecutter](https://github.com/cookiecutter/cookiecutter) and the [audreyfeldroy/cookiecutter-pypackage](https://github.com/audreyfeldroy/cookiecutter-pypackage) project template.
@@ -0,0 +1,10 @@
1
+ instructor_examples/__init__.py,sha256=MNlPxziqKTbGxSBc8lKtCKYJWhBGQq1tW2oOQyC54OI,49
2
+ instructor_examples/__main__.py,sha256=Qd-f8z2Q2vpiEP2x6PBFsJrpACWDVxFKQk820MhFmHo,59
3
+ instructor_examples/cli.py,sha256=0VUZDVWST8jJUJaoXdZ--CaHReiAg7yKS01u8wd8GLI,900
4
+ instructor_examples/py.typed,sha256=8PjyZ1aVoQpRVvt71muvuq5qE-jTFZkK-GLHkhdebmc,26
5
+ instructor_examples/utils.py,sha256=pNVsEg3jcQtnEwymKF1f7GLYA62EByLqW52eiZ-HI3g,5836
6
+ instructor_examples-0.1.0.dist-info/METADATA,sha256=j20WDA8EIDSUZtQvpJDBF4UGudKUQ4VMCDKESIkniBo,2519
7
+ instructor_examples-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
8
+ instructor_examples-0.1.0.dist-info/entry_points.txt,sha256=4tZyKdROomo2LIPxeU8HBsTKjSIJmZTatE3KaqcZdiI,68
9
+ instructor_examples-0.1.0.dist-info/licenses/LICENSE,sha256=UYMM0dCj9_OYWF9EXqVU-clmaT9n1QWQFYYRl1uGaJI,1071
10
+ instructor_examples-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ instructor_examples = instructor_examples.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026, Daniel Mouris
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.