circle-codex-cli-bin 0.154.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,41 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: circle-codex-cli-bin
|
|
3
|
+
Version: 0.154.0
|
|
4
|
+
Summary: Codex CLI runtime (unofficial fork with xAI provider) for the circle-codex Python SDK
|
|
5
|
+
Project-URL: Homepage, https://github.com/ashish447344/codex
|
|
6
|
+
Project-URL: Repository, https://github.com/ashish447344/codex
|
|
7
|
+
Project-URL: Issues, https://github.com/ashish447344/codex/issues
|
|
8
|
+
Author: Ashish Verma
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: certifi>=2024.2.2
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# circle-codex-cli-bin
|
|
22
|
+
|
|
23
|
+
Platform-specific Codex CLI runtime consumed by the `circle-codex` Python SDK.
|
|
24
|
+
Install `circle-codex`; this package is pulled in automatically.
|
|
25
|
+
|
|
26
|
+
This is an unofficial build of the Codex CLI from
|
|
27
|
+
<https://github.com/ashish447344/codex>, a fork of
|
|
28
|
+
<https://github.com/openai/codex> that adds a built-in xAI model provider. It is
|
|
29
|
+
not affiliated with, endorsed by, or supported by OpenAI or xAI.
|
|
30
|
+
|
|
31
|
+
It comes in two forms:
|
|
32
|
+
|
|
33
|
+
- Platform wheels with the Codex binaries inside, attached to the GitHub Release
|
|
34
|
+
`circle-v<version>` of the repository above.
|
|
35
|
+
- A small `py3-none-any` wheel on PyPI that lists those platform wheels with
|
|
36
|
+
their SHA-256 checksums. The first time the runtime is needed it downloads the
|
|
37
|
+
wheel for the current platform, verifies it and unpacks it into a per-user
|
|
38
|
+
cache. `python -m codex_cli_bin download` does this ahead of time.
|
|
39
|
+
|
|
40
|
+
`circle-codex-cli-bin` is intentionally wheel-only. Do not build or publish an
|
|
41
|
+
sdist for this package.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
codex_cli_bin/__init__.py,sha256=4_5TO2Wd3KR_UJNEQPi59WxWeRNFahzLBvQ9Jt8ACiQ,1307
|
|
2
|
+
codex_cli_bin/__main__.py,sha256=RWaiaTW7kFXEJ_SUrQZTYYobIRqtfgu0KOCdGx-3oHQ,646
|
|
3
|
+
codex_cli_bin/_download.py,sha256=G5O85Z3qEmvwAXc91fqGm7Pe_HOuiW9Th1BfbQYyh00,6437
|
|
4
|
+
codex_cli_bin/_manifest.py,sha256=OHKITBAltmpVpWWTaR7IcFJOU0a3H2XdnuEb0QUOa6g,1216
|
|
5
|
+
circle_codex_cli_bin-0.154.0.dist-info/METADATA,sha256=CzNDsElRTZD7EeyKm7A5w46t--lNC4xycoEqqjX0stE,1826
|
|
6
|
+
circle_codex_cli_bin-0.154.0.dist-info/WHEEL,sha256=8GZFvw2qj-I9L8cSd1T8-sNGyxVz7bWB3BKBcWz4104,88
|
|
7
|
+
circle_codex_cli_bin-0.154.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
PACKAGE_NAME = "circle-codex-cli-bin"
|
|
5
|
+
PACKAGE_METADATA_FILENAME = "codex-package.json"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def bundled_package_dir() -> Path:
|
|
9
|
+
path = Path(__file__).resolve().parent
|
|
10
|
+
metadata_path = path / PACKAGE_METADATA_FILENAME
|
|
11
|
+
if metadata_path.is_file():
|
|
12
|
+
# Platform wheel: the runtime ships inside this package.
|
|
13
|
+
return path
|
|
14
|
+
try:
|
|
15
|
+
from ._manifest import MANIFEST
|
|
16
|
+
except ImportError:
|
|
17
|
+
raise FileNotFoundError(
|
|
18
|
+
f"{PACKAGE_NAME} is installed but missing its package metadata at {metadata_path}"
|
|
19
|
+
) from None
|
|
20
|
+
# Small PyPI wheel: download the matching platform wheel on first use.
|
|
21
|
+
from ._download import ensure_runtime
|
|
22
|
+
|
|
23
|
+
return ensure_runtime(MANIFEST)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def bundled_codex_path() -> Path:
|
|
27
|
+
exe = "codex.exe" if os.name == "nt" else "codex"
|
|
28
|
+
path = bundled_package_dir() / "bin" / exe
|
|
29
|
+
if not path.is_file():
|
|
30
|
+
raise FileNotFoundError(
|
|
31
|
+
f"{PACKAGE_NAME} is installed but missing its packaged codex binary at {path}"
|
|
32
|
+
)
|
|
33
|
+
return path
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def bundled_path_dir() -> Path | None:
|
|
37
|
+
path = bundled_package_dir() / "codex-path"
|
|
38
|
+
return path if path.is_dir() else None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"PACKAGE_NAME",
|
|
43
|
+
"bundled_codex_path",
|
|
44
|
+
"bundled_package_dir",
|
|
45
|
+
"bundled_path_dir",
|
|
46
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Command-line helpers for the Codex runtime package.
|
|
2
|
+
|
|
3
|
+
``python -m codex_cli_bin download`` fetches the runtime now (useful while
|
|
4
|
+
building a Docker image) and prints the path of the ``codex`` executable.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from . import bundled_codex_path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main(argv: list[str] | None = None) -> int:
|
|
13
|
+
args = sys.argv[1:] if argv is None else argv
|
|
14
|
+
command = args[0] if args else "download"
|
|
15
|
+
if command not in {"download", "path"}:
|
|
16
|
+
print("usage: python -m codex_cli_bin [download|path]", file=sys.stderr)
|
|
17
|
+
return 2
|
|
18
|
+
print(bundled_codex_path())
|
|
19
|
+
return 0
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Download the Codex runtime on first use.
|
|
2
|
+
|
|
3
|
+
The PyPI release of this package is small: instead of the Codex binaries it
|
|
4
|
+
ships a manifest (``_manifest.py``) listing one platform wheel per supported
|
|
5
|
+
platform, hosted on the project's GitHub Release. The first time the runtime is
|
|
6
|
+
needed, the matching wheel is downloaded, checked against its SHA-256 digest
|
|
7
|
+
and unpacked into a per-user cache. Later calls reuse the cached copy.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import hashlib
|
|
13
|
+
import os
|
|
14
|
+
import platform
|
|
15
|
+
import shutil
|
|
16
|
+
import ssl
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
import urllib.request
|
|
20
|
+
import zipfile
|
|
21
|
+
from pathlib import Path, PurePosixPath
|
|
22
|
+
from typing import Any, Mapping
|
|
23
|
+
|
|
24
|
+
PACKAGE_PREFIX = "codex_cli_bin/"
|
|
25
|
+
PACKAGE_METADATA_FILENAME = "codex-package.json"
|
|
26
|
+
CACHE_DIR_ENV = "CIRCLE_CODEX_CACHE_DIR"
|
|
27
|
+
BASE_URL_ENV = "CIRCLE_CODEX_DOWNLOAD_BASE_URL"
|
|
28
|
+
_EXECUTABLE_DIRS = {"bin", "codex-path", "codex-resources"}
|
|
29
|
+
_CHUNK_SIZE = 1024 * 1024
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class RuntimeDownloadError(OSError):
|
|
33
|
+
"""Raised when the Codex runtime cannot be downloaded or unpacked."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def platform_key() -> str:
|
|
37
|
+
"""Return the manifest key for this machine, for example ``linux-x86_64``."""
|
|
38
|
+
system = platform.system()
|
|
39
|
+
machine = platform.machine().lower()
|
|
40
|
+
if machine in {"arm64", "aarch64"}:
|
|
41
|
+
arch = "arm64" if system == "Darwin" else "aarch64"
|
|
42
|
+
elif machine in {"x86_64", "amd64"}:
|
|
43
|
+
arch = "x86_64"
|
|
44
|
+
else:
|
|
45
|
+
arch = machine
|
|
46
|
+
if system == "Darwin":
|
|
47
|
+
return f"darwin-{arch}"
|
|
48
|
+
if system == "Linux":
|
|
49
|
+
return f"linux-{arch}"
|
|
50
|
+
return f"{system.lower()}-{arch}"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def default_cache_root() -> Path:
|
|
54
|
+
override = os.environ.get(CACHE_DIR_ENV)
|
|
55
|
+
if override:
|
|
56
|
+
return Path(override).expanduser()
|
|
57
|
+
if sys.platform == "darwin":
|
|
58
|
+
return Path.home() / "Library" / "Caches" / "circle-codex"
|
|
59
|
+
xdg_cache = os.environ.get("XDG_CACHE_HOME")
|
|
60
|
+
base = Path(xdg_cache).expanduser() if xdg_cache else Path.home() / ".cache"
|
|
61
|
+
return base / "circle-codex"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def is_runtime_dir(path: Path) -> bool:
|
|
65
|
+
exe = "codex.exe" if os.name == "nt" else "codex"
|
|
66
|
+
return (path / PACKAGE_METADATA_FILENAME).is_file() and (path / "bin" / exe).is_file()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def ensure_runtime(manifest: Mapping[str, Any]) -> Path:
|
|
70
|
+
"""Return a directory holding the runtime, downloading it on first use."""
|
|
71
|
+
key = platform_key()
|
|
72
|
+
files = manifest["files"]
|
|
73
|
+
entry = files.get(key)
|
|
74
|
+
if entry is None:
|
|
75
|
+
supported = ", ".join(sorted(files))
|
|
76
|
+
raise RuntimeDownloadError(
|
|
77
|
+
f"No Codex runtime is published for this platform ({key}). "
|
|
78
|
+
f"Supported platforms: {supported}."
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
target = default_cache_root() / str(manifest["version"]) / key
|
|
82
|
+
if is_runtime_dir(target):
|
|
83
|
+
return target
|
|
84
|
+
|
|
85
|
+
base_url = os.environ.get(BASE_URL_ENV) or manifest["base_url"]
|
|
86
|
+
url = f"{base_url.rstrip('/')}/{entry['filename']}"
|
|
87
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
88
|
+
work_dir = Path(tempfile.mkdtemp(prefix=".download-", dir=target.parent))
|
|
89
|
+
try:
|
|
90
|
+
wheel_path = work_dir / entry["filename"]
|
|
91
|
+
_download(url, wheel_path, expected_sha256=entry["sha256"], size=entry.get("size"))
|
|
92
|
+
unpack_dir = work_dir / "runtime"
|
|
93
|
+
_unpack_runtime(wheel_path, unpack_dir)
|
|
94
|
+
if not is_runtime_dir(unpack_dir):
|
|
95
|
+
raise RuntimeDownloadError(f"{entry['filename']} does not contain a Codex runtime")
|
|
96
|
+
try:
|
|
97
|
+
os.rename(unpack_dir, target)
|
|
98
|
+
except OSError:
|
|
99
|
+
# Another process finished the same download first.
|
|
100
|
+
if not is_runtime_dir(target):
|
|
101
|
+
raise
|
|
102
|
+
return target
|
|
103
|
+
finally:
|
|
104
|
+
shutil.rmtree(work_dir, ignore_errors=True)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _ssl_context() -> ssl.SSLContext:
|
|
108
|
+
try:
|
|
109
|
+
import certifi
|
|
110
|
+
except ImportError:
|
|
111
|
+
return ssl.create_default_context()
|
|
112
|
+
return ssl.create_default_context(cafile=certifi.where())
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _download(url: str, destination: Path, *, expected_sha256: str, size: int | None) -> None:
|
|
116
|
+
size_text = f" ({size / 1024 / 1024:.0f} MB)" if size else ""
|
|
117
|
+
print(
|
|
118
|
+
f"circle-codex: downloading the Codex runtime{size_text} from {url} "
|
|
119
|
+
"(first run only)...",
|
|
120
|
+
file=sys.stderr,
|
|
121
|
+
flush=True,
|
|
122
|
+
)
|
|
123
|
+
digest = hashlib.sha256()
|
|
124
|
+
try:
|
|
125
|
+
request = urllib.request.Request(url, headers={"User-Agent": "circle-codex-cli-bin"})
|
|
126
|
+
with urllib.request.urlopen(request, timeout=60, context=_ssl_context()) as response:
|
|
127
|
+
with destination.open("wb") as output:
|
|
128
|
+
while chunk := response.read(_CHUNK_SIZE):
|
|
129
|
+
digest.update(chunk)
|
|
130
|
+
output.write(chunk)
|
|
131
|
+
except OSError as exc:
|
|
132
|
+
raise RuntimeDownloadError(
|
|
133
|
+
f"Could not download the Codex runtime from {url}: {exc}. "
|
|
134
|
+
f"Check your internet connection or proxy settings, set {BASE_URL_ENV} to a "
|
|
135
|
+
"mirror, or pass CodexConfig(codex_bin=...) to use a local Codex binary."
|
|
136
|
+
) from exc
|
|
137
|
+
if digest.hexdigest() != expected_sha256:
|
|
138
|
+
raise RuntimeDownloadError(
|
|
139
|
+
f"Checksum mismatch for {url}: expected {expected_sha256}, got {digest.hexdigest()}."
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _unpack_runtime(wheel_path: Path, destination: Path) -> None:
|
|
144
|
+
"""Extract the runtime files (not the Python code) from a platform wheel."""
|
|
145
|
+
destination.mkdir(parents=True)
|
|
146
|
+
with zipfile.ZipFile(wheel_path) as archive:
|
|
147
|
+
for info in archive.infolist():
|
|
148
|
+
name = info.filename
|
|
149
|
+
if not name.startswith(PACKAGE_PREFIX) or name.endswith("/"):
|
|
150
|
+
continue
|
|
151
|
+
relative = PurePosixPath(name[len(PACKAGE_PREFIX) :])
|
|
152
|
+
if (
|
|
153
|
+
not relative.parts
|
|
154
|
+
or relative.is_absolute()
|
|
155
|
+
or ".." in relative.parts
|
|
156
|
+
or "__pycache__" in relative.parts
|
|
157
|
+
or relative.suffix == ".py"
|
|
158
|
+
):
|
|
159
|
+
continue
|
|
160
|
+
output_path = destination.joinpath(*relative.parts)
|
|
161
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
162
|
+
with archive.open(info) as source, output_path.open("wb") as output:
|
|
163
|
+
shutil.copyfileobj(source, output, _CHUNK_SIZE)
|
|
164
|
+
mode = (info.external_attr >> 16) & 0o777 or 0o644
|
|
165
|
+
if relative.parts[0] in _EXECUTABLE_DIRS:
|
|
166
|
+
# Programs must stay runnable even if the archive lost their mode bits.
|
|
167
|
+
mode |= 0o755
|
|
168
|
+
output_path.chmod(mode)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Generated at release time: platform wheels to download on first use."""
|
|
2
|
+
|
|
3
|
+
MANIFEST = {
|
|
4
|
+
"base_url": "https://github.com/ashish447344/codex/releases/download/circle-v0.154.0",
|
|
5
|
+
"files": {
|
|
6
|
+
"darwin-arm64": {
|
|
7
|
+
"filename": "circle_codex_cli_bin-0.154.0-py3-none-macosx_11_0_arm64.whl",
|
|
8
|
+
"sha256": "4ea1aaacd8c67f38be6231a1fb54a818e04d043ae16728e8a6a6dc3f08e7efe6",
|
|
9
|
+
"size": 159667185
|
|
10
|
+
},
|
|
11
|
+
"darwin-x86_64": {
|
|
12
|
+
"filename": "circle_codex_cli_bin-0.154.0-py3-none-macosx_10_9_x86_64.whl",
|
|
13
|
+
"sha256": "f482e8d892a17a4ed9420e37c198b4dba7933a9ac417e2557286826f4b0b7842",
|
|
14
|
+
"size": 170318967
|
|
15
|
+
},
|
|
16
|
+
"linux-aarch64": {
|
|
17
|
+
"filename": "circle_codex_cli_bin-0.154.0-py3-none-manylinux_2_17_aarch64.whl",
|
|
18
|
+
"sha256": "a75be70c1b4ee232b5375a09fc8fe53d0e263e463b8b34a3168ba776a0249a53",
|
|
19
|
+
"size": 172767830
|
|
20
|
+
},
|
|
21
|
+
"linux-x86_64": {
|
|
22
|
+
"filename": "circle_codex_cli_bin-0.154.0-py3-none-manylinux_2_17_x86_64.whl",
|
|
23
|
+
"sha256": "9686f929b295664cedd5df1dded19122c912c0918503aec07f4b05bae875f9f6",
|
|
24
|
+
"size": 185292008
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"version": "0.154.0"
|
|
28
|
+
}
|