chipfoundry-cli 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,2 @@
1
+ """ChipFoundry CLI package: Automate project submission to SFTP."""
2
+ __version__ = "0.1.0"
@@ -0,0 +1,173 @@
1
+ import click
2
+ import getpass
3
+ from chipfoundry_cli.utils import (
4
+ collect_project_files, ensure_cf_directory, update_or_create_project_json,
5
+ sftp_connect, upload_with_progress, sftp_ensure_dirs
6
+ )
7
+ import os
8
+ from pathlib import Path
9
+ from rich.console import Console
10
+ from rich.panel import Panel
11
+ from rich.text import Text
12
+
13
+ DEFAULT_SSH_KEY = os.path.expanduser('~/.ssh/id_rsa')
14
+ DEFAULT_SFTP_HOST = 'sftp.chipfoundry.io'
15
+
16
+ GDS_TYPE_MAP = {
17
+ 'user_project_wrapper.gds': 'digital',
18
+ 'user_analog_project_wrapper.gds': 'analog',
19
+ 'openframe_project_wrapper.gds': 'openframe',
20
+ }
21
+
22
+ console = Console()
23
+
24
+ @click.group(help="ChipFoundry CLI: Automate project submission and management.")
25
+ def main():
26
+ pass
27
+
28
+ @main.command('submit')
29
+ @click.option('--project-root', required=True, type=click.Path(exists=True, file_okay=False), help='Path to the local ChipFoundry project directory.')
30
+ @click.option('--sftp-host', default=DEFAULT_SFTP_HOST, show_default=True, help='SFTP server hostname.')
31
+ @click.option('--sftp-username', required=True, help='SFTP username.')
32
+ @click.option('--sftp-key', type=click.Path(exists=True, dir_okay=False), help='Path to SFTP private key file. Defaults to ~/.ssh/id_rsa if it exists.', default=None, show_default=False)
33
+ @click.option('--sftp-password', help='SFTP password. If not provided, will prompt securely.', default=None)
34
+ @click.option('--project-id', help='Project ID (e.g., "user123_proj456"). Overrides project.json if exists.')
35
+ @click.option('--project-name', help='Project name (e.g., "my_project"). Overrides project.json if exists.')
36
+ @click.option('--project-type', help='Project type (auto-detected if not provided).', default=None)
37
+ @click.option('--force-overwrite', is_flag=True, help='Overwrite existing files on SFTP without prompting.')
38
+ @click.option('--dry-run', is_flag=True, help='Preview actions without uploading files.')
39
+ def submit(project_root, sftp_host, sftp_username, sftp_key, sftp_password, project_id, project_name, project_type, force_overwrite, dry_run):
40
+ """Submit a project to the SFTP server."""
41
+ # Determine which authentication method to use
42
+ key_path = sftp_key
43
+ password = sftp_password
44
+ # If neither provided, try default key
45
+ if not key_path and not password:
46
+ if os.path.exists(DEFAULT_SSH_KEY):
47
+ key_path = DEFAULT_SSH_KEY
48
+ console.print(f"[INFO] Using default SSH key: {DEFAULT_SSH_KEY}", style="bold cyan")
49
+ else:
50
+ console.print("[WARN] No SFTP key or password provided, and no default key found at ~/.ssh/id_rsa.", style="bold yellow")
51
+ auth_method = click.prompt("Choose authentication method (key/password)", type=click.Choice(['key', 'password']), show_choices=True)
52
+ if auth_method == 'key':
53
+ key_path = click.prompt("Enter path to SFTP private key", type=click.Path(exists=True, dir_okay=False))
54
+ else:
55
+ password = click.prompt("SFTP Password", hide_input=True)
56
+ elif key_path and password:
57
+ console.print("[ERROR] Options --sftp-password and --sftp-key are mutually exclusive.", style="bold red")
58
+ raise click.UsageError("Options --sftp-password and --sftp-key are mutually exclusive.")
59
+ elif not key_path and password:
60
+ pass # password provided
61
+ elif key_path and not password:
62
+ if not os.path.exists(key_path):
63
+ console.print(f"[ERROR] SFTP key file not found: {key_path}", style="bold red")
64
+ raise click.UsageError(f"SFTP key file not found: {key_path}")
65
+
66
+ console.print(f"[INFO] Collecting project files from: {project_root}", style="bold cyan")
67
+ try:
68
+ collected = collect_project_files(project_root)
69
+ for rel_path, abs_path in collected.items():
70
+ if abs_path:
71
+ console.print(f"[OK] Found: {rel_path} -> {abs_path}", style="green")
72
+ else:
73
+ console.print(f"[INFO] Optional file not found: {rel_path}", style="yellow")
74
+ except FileNotFoundError as e:
75
+ console.print(f"[ERROR] {e}", style="bold red")
76
+ raise click.Abort()
77
+
78
+ # Auto-detect project type from GDS file name if not provided
79
+ gds_dir = Path(project_root) / 'gds'
80
+ found_types = []
81
+ gds_file_path = None
82
+ for gds_name, gds_type in GDS_TYPE_MAP.items():
83
+ candidate = gds_dir / gds_name
84
+ if candidate.exists():
85
+ found_types.append(gds_type)
86
+ gds_file_path = str(candidate)
87
+ if project_type:
88
+ detected_type = project_type
89
+ else:
90
+ if len(found_types) == 0:
91
+ console.print("[ERROR] No recognized GDS file found for project type detection.", style="bold red")
92
+ raise click.Abort()
93
+ elif len(found_types) > 1:
94
+ console.print(f"[ERROR] Multiple GDS types found: {found_types}. Only one project type is allowed per project.", style="bold red")
95
+ raise click.Abort()
96
+ else:
97
+ detected_type = found_types[0]
98
+ console.print(f"[INFO] Detected project type: {detected_type}", style="bold cyan")
99
+ # Use the detected GDS file for upload and hash
100
+ if gds_file_path:
101
+ collected['gds/user_project_wrapper.gds'] = gds_file_path
102
+ # Prepare CLI overrides for project.json
103
+ cli_overrides = {
104
+ "project_id": project_id,
105
+ "project_name": project_name,
106
+ "project_type": detected_type,
107
+ "sftp_username": sftp_username,
108
+ }
109
+ cf_dir = ensure_cf_directory(project_root)
110
+ console.print(f"[INFO] Generating/updating project.json in {cf_dir}", style="bold cyan")
111
+ project_json_path = update_or_create_project_json(
112
+ cf_dir=str(cf_dir),
113
+ gds_path=collected["gds/user_project_wrapper.gds"],
114
+ cli_overrides=cli_overrides,
115
+ existing_json_path=collected.get(".cf/project.json")
116
+ )
117
+ console.print(f"[OK] project.json ready: {project_json_path}", style="green")
118
+
119
+ # SFTP upload or dry-run
120
+ final_project_name = project_name or (
121
+ cli_overrides.get("project_name") or Path(project_root).name
122
+ )
123
+ sftp_base = f"incoming/projects/{final_project_name}"
124
+ upload_map = {
125
+ ".cf/project.json": project_json_path,
126
+ "gds/user_project_wrapper.gds": collected["gds/user_project_wrapper.gds"],
127
+ "verilog/rtl/user_defines.v": collected["verilog/rtl/user_defines.v"],
128
+ }
129
+ if dry_run:
130
+ console.print("[DRY-RUN] The following files would be uploaded:", style="bold magenta")
131
+ for rel_path, local_path in upload_map.items():
132
+ if local_path:
133
+ remote_path = os.path.join(sftp_base, rel_path)
134
+ console.print(f" {local_path} -> {remote_path}", style="magenta")
135
+ console.print("[DRY-RUN] No files were uploaded.", style="bold magenta")
136
+ return
137
+
138
+ console.print(f"[INFO] Connecting to SFTP: {sftp_host} as {sftp_username}", style="bold cyan")
139
+ transport = None
140
+ try:
141
+ sftp, transport = sftp_connect(
142
+ host=sftp_host,
143
+ username=sftp_username,
144
+ password=password,
145
+ key_path=key_path
146
+ )
147
+ # Ensure the project directory exists before uploading
148
+ sftp_project_dir = f"incoming/projects/{final_project_name}"
149
+ sftp_ensure_dirs(sftp, sftp_project_dir)
150
+ except Exception as e:
151
+ console.print(f"[ERROR] Failed to connect to SFTP: {e}", style="bold red")
152
+ raise click.Abort()
153
+ try:
154
+ for rel_path, local_path in upload_map.items():
155
+ if local_path:
156
+ remote_path = os.path.join(sftp_base, rel_path)
157
+ upload_with_progress(
158
+ sftp,
159
+ local_path=local_path,
160
+ remote_path=remote_path,
161
+ force_overwrite=force_overwrite
162
+ )
163
+ console.print(f"[SUCCESS] All files uploaded to {sftp_base}", style="bold green")
164
+ except Exception as e:
165
+ console.print(f"[ERROR] SFTP upload failed: {e}", style="bold red")
166
+ raise click.Abort()
167
+ finally:
168
+ if transport:
169
+ sftp.close()
170
+ transport.close()
171
+
172
+ if __name__ == "__main__":
173
+ main()
@@ -0,0 +1,180 @@
1
+ import os
2
+ import shutil
3
+ from pathlib import Path
4
+ from typing import Dict, Optional
5
+ import json
6
+ import hashlib
7
+ import paramiko
8
+ from rich.progress import Progress, BarColumn, TextColumn, TimeElapsedColumn, TaskProgressColumn
9
+
10
+ REQUIRED_FILES = {
11
+ ".cf/project.json": False, # Optional, may not exist
12
+ "gds/user_project_wrapper.gds": True,
13
+ "verilog/rtl/user_defines.v": True,
14
+ }
15
+
16
+ def collect_project_files(project_root: str) -> Dict[str, Optional[str]]:
17
+ """
18
+ Collect required project files from the given project_root.
19
+ Returns a dict mapping logical names to absolute file paths (or None if not found and optional).
20
+ Raises FileNotFoundError if any required file is missing.
21
+ """
22
+ project_root = Path(project_root)
23
+ collected = {}
24
+ for rel_path, required in REQUIRED_FILES.items():
25
+ abs_path = project_root / rel_path
26
+ if abs_path.exists():
27
+ collected[rel_path] = str(abs_path)
28
+ elif required:
29
+ raise FileNotFoundError(f"Required file not found: {abs_path}")
30
+ else:
31
+ collected[rel_path] = None
32
+ return collected
33
+
34
+ def ensure_cf_directory(target_dir: str):
35
+ """
36
+ Ensure the .cf directory exists in the target directory.
37
+ """
38
+ cf_dir = Path(target_dir) / ".cf"
39
+ cf_dir.mkdir(parents=True, exist_ok=True)
40
+ return cf_dir
41
+
42
+ def copy_files_to_temp(collected: Dict[str, Optional[str]], temp_dir: str):
43
+ """
44
+ Copy collected files to a temporary directory, preserving structure.
45
+ """
46
+ for rel_path, abs_path in collected.items():
47
+ if abs_path:
48
+ dest_path = Path(temp_dir) / rel_path
49
+ dest_path.parent.mkdir(parents=True, exist_ok=True)
50
+ shutil.copy2(abs_path, dest_path)
51
+
52
+ def calculate_sha256(file_path: str) -> str:
53
+ """
54
+ Calculate SHA256 hash of the given file.
55
+ """
56
+ sha256 = hashlib.sha256()
57
+ with open(file_path, 'rb') as f:
58
+ for chunk in iter(lambda: f.read(8192), b''):
59
+ sha256.update(chunk)
60
+ return sha256.hexdigest()
61
+
62
+ def load_project_json(json_path: str) -> dict:
63
+ """
64
+ Load project.json from the given path.
65
+ """
66
+ with open(json_path, 'r') as f:
67
+ return json.load(f)
68
+
69
+ def save_project_json(json_path: str, data: dict):
70
+ """
71
+ Save the project.json to the given path (pretty-printed).
72
+ """
73
+ with open(json_path, 'w') as f:
74
+ json.dump(data, f, indent=2)
75
+
76
+ def update_or_create_project_json(
77
+ cf_dir: str,
78
+ gds_path: str,
79
+ cli_overrides: dict,
80
+ existing_json_path: Optional[str] = None
81
+ ) -> str:
82
+ """
83
+ Update or create project.json in cf_dir. If existing_json_path is given, load and update it.
84
+ Otherwise, create a new one. Always update the user_project_wrapper_hash.
85
+ Returns the path to the updated/created project.json.
86
+ """
87
+ project_json_path = str(Path(cf_dir) / "project.json")
88
+ hash_val = calculate_sha256(gds_path)
89
+ if existing_json_path and Path(existing_json_path).exists():
90
+ data = load_project_json(existing_json_path)
91
+ if "project" not in data:
92
+ data["project"] = {}
93
+ else:
94
+ data = {"project": {}}
95
+ # Required fields with defaults
96
+ data["project"].setdefault("version", "1.0.0")
97
+ data["project"]["user_project_wrapper_hash"] = hash_val
98
+ # Apply CLI overrides
99
+ for key in ["id", "name", "type", "user", "version"]:
100
+ cli_key = f"project_{key}" if key != "user" else "sftp_username"
101
+ if cli_key in cli_overrides and cli_overrides[cli_key] is not None:
102
+ data["project"][key] = cli_overrides[cli_key]
103
+ save_project_json(project_json_path, data)
104
+ return project_json_path
105
+
106
+ def sftp_connect(host: str, username: str, password: str = None, key_path: str = None):
107
+ """
108
+ Establish an SFTP connection using paramiko. Returns an SFTP client.
109
+ """
110
+ transport = paramiko.Transport((host, 22))
111
+ if key_path:
112
+ private_key = paramiko.RSAKey.from_private_key_file(key_path)
113
+ transport.connect(username=username, pkey=private_key)
114
+ else:
115
+ transport.connect(username=username, password=password)
116
+ sftp = paramiko.SFTPClient.from_transport(transport)
117
+ return sftp, transport
118
+
119
+ def sftp_ensure_dirs(sftp, remote_path: str):
120
+ """
121
+ Recursively create directories on the SFTP server if they do not exist.
122
+ """
123
+ dirs = []
124
+ path = remote_path
125
+ while len(path) > 1:
126
+ dirs.append(path)
127
+ path, _ = os.path.split(path)
128
+ dirs = dirs[::-1]
129
+ for d in dirs:
130
+ try:
131
+ sftp.stat(d)
132
+ except FileNotFoundError:
133
+ try:
134
+ sftp.mkdir(d)
135
+ except Exception:
136
+ pass
137
+
138
+ def sftp_upload_file(sftp, local_path: str, remote_path: str, force_overwrite: bool = False, progress_cb=None):
139
+ """
140
+ Upload a file to the SFTP server, optionally overwriting. Optionally report progress via progress_cb(bytes_transferred, total_bytes).
141
+ """
142
+ try:
143
+ if not force_overwrite:
144
+ sftp.stat(remote_path)
145
+ print(f"[WARN] File exists on SFTP: {remote_path}. Skipping (use --force-overwrite to overwrite).")
146
+ return False
147
+ except FileNotFoundError:
148
+ pass # File does not exist, proceed
149
+ sftp_ensure_dirs(sftp, os.path.dirname(remote_path))
150
+ if progress_cb:
151
+ file_size = os.path.getsize(local_path)
152
+ with open(local_path, 'rb') as f:
153
+ def callback(bytes_transferred, total=file_size):
154
+ progress_cb(bytes_transferred, total)
155
+ sftp.putfo(f, remote_path, callback=callback)
156
+ else:
157
+ sftp.put(local_path, remote_path)
158
+ print(f"[OK] Uploaded: {local_path} -> {remote_path}")
159
+ return True
160
+
161
+ def upload_with_progress(sftp, local_path, remote_path, force_overwrite=False):
162
+ """
163
+ Upload a file with a rich progress bar.
164
+ """
165
+ file_size = os.path.getsize(local_path)
166
+ with Progress(
167
+ TextColumn("[progress.description]{task.description}"),
168
+ BarColumn(),
169
+ TaskProgressColumn(),
170
+ TextColumn("{task.percentage:>3.0f}%"),
171
+ TextColumn("•"),
172
+ TextColumn("{task.completed}/{task.total} bytes"),
173
+ TimeElapsedColumn(),
174
+ ) as progress:
175
+ task = progress.add_task(f"Uploading {os.path.basename(local_path)}", total=file_size)
176
+ def progress_cb(bytes_transferred, total):
177
+ progress.update(task, completed=bytes_transferred)
178
+ result = sftp_upload_file(sftp, local_path, remote_path, force_overwrite, progress_cb=progress_cb)
179
+ progress.update(task, completed=file_size)
180
+ return result
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.1
2
+ Name: chipfoundry-cli
3
+ Version: 0.1.0
4
+ Summary: CLI tool to automate ChipFoundry project submission to SFTP server
5
+ Home-page: https://chipfoundry.io
6
+ License: MIT
7
+ Author: ChipFoundry
8
+ Author-email: marwan.abbas@chipfoundry.io
9
+ Requires-Python: >=3.8.0
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Dist: click (>=8.0.0,<9)
19
+ Requires-Dist: paramiko (>=3.0.0,<4)
20
+ Requires-Dist: rich (>=12,<14)
21
+ Project-URL: Repository, https://github.com/chipfoundry/cf-cli
22
+ Description-Content-Type: text/markdown
23
+
24
+ # ChipFoundry CLI (`cf-cli`)
25
+
26
+ A command-line tool to automate the submission of ChipFoundry projects to the SFTP server.
27
+
28
+ ---
29
+
30
+ ## Overview
31
+
32
+ `cf-cli` is a user-friendly command-line tool for securely submitting your ChipFoundry project files to the official SFTP server. It automatically collects the required files, generates or updates your project configuration, and uploads everything to the correct location on the server.
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ Install from PyPI:
39
+
40
+ ```bash
41
+ pip install cf-cli
42
+ cf --help
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Project Structure Requirements
48
+
49
+ Your project directory **must** contain:
50
+
51
+ - `gds/` directory with **one** of the following:
52
+ - `user_project_wrapper.gds` (for digital projects)
53
+ - `user_analog_project_wrapper.gds` (for analog projects)
54
+ - `openframe_project_wrapper.gds` (for openframe projects)
55
+ - `verilog/rtl/user_defines.v` (required for digital/analog)
56
+ - `.cf/project.json` (optional; will be created/updated automatically)
57
+
58
+ **Example:**
59
+ ```
60
+ my_project/
61
+ ├── gds/
62
+ │ └── user_project_wrapper.gds
63
+ ├── verilog/
64
+ │ └── rtl/
65
+ │ └── user_defines.v
66
+ └── .cf/
67
+ └── project.json
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Authentication
73
+
74
+ - By default, the tool will look for an SSH key at `~/.ssh/id_rsa`.
75
+ - You can specify a different key with `--sftp-key`.
76
+ - If no key is found, you will be prompted to enter a key path or your SFTP password.
77
+ - Your SFTP username is required (provided by ChipFoundry).
78
+
79
+ ---
80
+
81
+ ## SFTP Server
82
+
83
+ - The default SFTP server is `sftp.chipfoundry.io` (no need to specify unless you want to override).
84
+
85
+ ---
86
+
87
+ ## Usage
88
+
89
+ ### Basic Submission (Digital Project)
90
+
91
+ ```bash
92
+ cf submit --project-root /path/to/my_project --sftp-username <your_chipfoundry_username>
93
+ ```
94
+
95
+ ### With a Custom SSH Key
96
+
97
+ ```bash
98
+ cf submit --project-root /path/to/my_project --sftp-username <your_chipfoundry_username> --sftp-key /path/to/id_rsa
99
+ ```
100
+
101
+ ### With Password Authentication
102
+
103
+ ```bash
104
+ cf submit --project-root /path/to/my_project --sftp-username <your_chipfoundry_username> --sftp-password <your_password>
105
+ ```
106
+
107
+ ### Dry Run (Preview what will be uploaded)
108
+
109
+ ```bash
110
+ cf submit --project-root /path/to/my_project --sftp-username <your_chipfoundry_username> --dry-run
111
+ ```
112
+
113
+ ### Override Project Name or ID
114
+
115
+ ```bash
116
+ cf submit --project-root /path/to/my_project --sftp-username <your_chipfoundry_username> --project-name my_custom_name --project-id my_custom_id
117
+ ```
118
+
119
+ ---
120
+
121
+ ## What Happens When You Run `cf submit`?
122
+
123
+ 1. **File Collection:**
124
+ - The tool checks for the required GDS and Verilog files.
125
+ - It auto-detects your project type (digital, analog, openframe) based on the GDS file name.
126
+ 2. **Configuration:**
127
+ - If `.cf/project.json` does not exist, it is created.
128
+ - The tool updates the GDS hash and any fields you override via CLI.
129
+ 3. **SFTP Upload:**
130
+ - Connects to the SFTP server as your user.
131
+ - Ensures the directory `incoming/projects/<project_name>` exists.
132
+ - Uploads `.cf/project.json`, the GDS file, and `verilog/rtl/user_defines.v` (if present).
133
+ - Shows a progress bar for each file upload.
134
+ 4. **Success:**
135
+ - You’ll see a green success message when all files are uploaded.
136
+
137
+ ---
138
+
139
+ ## Troubleshooting
140
+
141
+ - **Missing files:**
142
+ - The tool will error out if required files are missing or if more than one GDS type is present.
143
+ - **Authentication errors:**
144
+ - Make sure your SSH key is valid and registered with ChipFoundry, or use your password.
145
+ - **SFTP errors:**
146
+ - Check your network connection and credentials.
147
+ - **Project type detection:**
148
+ - Only one of the recognized GDS files should be present in your `gds/` directory.
149
+
150
+ ---
151
+
152
+ ## Support
153
+
154
+ - For help, contact info@chipfoundry.io or visit [chipfoundry.io](https://chipfoundry.io)
155
+ - For bug reports or feature requests, open an issue on [GitHub](https://github.com/chipfoundry/cf-cli)
156
+
@@ -0,0 +1,8 @@
1
+ chipfoundry_cli/__init__.py,sha256=cYd16oPuk5XKAm2A4g07dAHBwj5DN2wO-PrKXSh6Gpo,90
2
+ chipfoundry_cli/main.py,sha256=AgnJEsLm1CKcZBx81kJlkpsA-EA2V5fxGH6jjo53ya4,8115
3
+ chipfoundry_cli/utils.py,sha256=vWYp7M54PAkqkws5ey_-rZ_8Ibq2JfPO3HN0dCOA2BM,6556
4
+ chipfoundry_cli-0.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
+ chipfoundry_cli-0.1.0.dist-info/METADATA,sha256=FL9y-5JsotOdWldZ4ohh4SctkAbRelam2Yz5reBeUbM,4692
6
+ chipfoundry_cli-0.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ chipfoundry_cli-0.1.0.dist-info/entry_points.txt,sha256=CTRdCwH9q4omjHCNP20NskVw-enR_ThAaPcBltNOFEU,57
8
+ chipfoundry_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ chipfoundry=chipfoundry_cli.main:main
3
+