nex-cli 0.2.1__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.
- nex/__init__.py +3 -0
- nex/cli.py +94 -0
- nex/config.py +95 -0
- nex/detection.py +61 -0
- nex_cli-0.2.1.dist-info/METADATA +51 -0
- nex_cli-0.2.1.dist-info/RECORD +9 -0
- nex_cli-0.2.1.dist-info/WHEEL +4 -0
- nex_cli-0.2.1.dist-info/entry_points.txt +2 -0
- nex_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
nex/__init__.py
ADDED
nex/cli.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Command-line entry point for Nex."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.panel import Panel
|
|
8
|
+
from rich.table import Table
|
|
9
|
+
|
|
10
|
+
from nex import __version__
|
|
11
|
+
from nex.config import ConfigAlreadyExistsError, build_learn_config, write_learn_config
|
|
12
|
+
from nex.detection import detect_project
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def version_callback(value: bool) -> None:
|
|
16
|
+
"""Print the installed Nex CLI version and exit."""
|
|
17
|
+
if value:
|
|
18
|
+
typer.echo(f"nex {__version__}")
|
|
19
|
+
raise typer.Exit()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
app = typer.Typer(
|
|
23
|
+
add_completion=False,
|
|
24
|
+
no_args_is_help=False,
|
|
25
|
+
invoke_without_command=True,
|
|
26
|
+
help="Command-line interface for Nex.",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@app.callback()
|
|
31
|
+
def main(
|
|
32
|
+
ctx: typer.Context,
|
|
33
|
+
version: bool = typer.Option(
|
|
34
|
+
False,
|
|
35
|
+
"--version",
|
|
36
|
+
callback=version_callback,
|
|
37
|
+
is_eager=True,
|
|
38
|
+
help="Show the Nex version and exit.",
|
|
39
|
+
),
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Nex command-line interface."""
|
|
42
|
+
if ctx.invoked_subcommand is None and not version:
|
|
43
|
+
typer.echo(ctx.get_help())
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@app.command()
|
|
47
|
+
def learn(
|
|
48
|
+
force: bool = typer.Option(
|
|
49
|
+
False,
|
|
50
|
+
"--force",
|
|
51
|
+
help="Overwrite an existing .nex/config.toml file.",
|
|
52
|
+
),
|
|
53
|
+
) -> None:
|
|
54
|
+
"""Detect project signals and save them to .nex/config.toml."""
|
|
55
|
+
root = Path.cwd().resolve()
|
|
56
|
+
detection = detect_project(directory=root)
|
|
57
|
+
console = Console()
|
|
58
|
+
|
|
59
|
+
if not detection.found_anything:
|
|
60
|
+
console.print(
|
|
61
|
+
Panel("No supported project signals found in this directory.", title="Nex learn")
|
|
62
|
+
)
|
|
63
|
+
else:
|
|
64
|
+
table = Table(title="Nex learn", show_header=True)
|
|
65
|
+
table.add_column("Type", style="bold")
|
|
66
|
+
table.add_column("Detected")
|
|
67
|
+
|
|
68
|
+
if detection.frontend:
|
|
69
|
+
scripts = ", ".join(detection.frontend.scripts) or "no dev/start script"
|
|
70
|
+
table.add_row("Frontend", f"package.json ({scripts})")
|
|
71
|
+
if detection.python_files:
|
|
72
|
+
table.add_row("Python backend", ", ".join(detection.python_files))
|
|
73
|
+
if detection.docker_compose:
|
|
74
|
+
table.add_row("Services", "docker-compose.yml")
|
|
75
|
+
|
|
76
|
+
console.print(table)
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
config_path = write_learn_config(
|
|
80
|
+
build_learn_config(root, detection), force=force
|
|
81
|
+
)
|
|
82
|
+
except ConfigAlreadyExistsError as error:
|
|
83
|
+
console.print(
|
|
84
|
+
f"[yellow]Nex config already exists at {error.filename}. "
|
|
85
|
+
"Use --force to overwrite it.[/yellow]"
|
|
86
|
+
)
|
|
87
|
+
raise typer.Exit(code=1) from None
|
|
88
|
+
|
|
89
|
+
console.print(f"[green]Saved Nex config to {config_path}[/green]")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def run() -> None:
|
|
93
|
+
"""Run the Nex CLI."""
|
|
94
|
+
app()
|
nex/config.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Persistence for the project signals learned by Nex."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from nex.detection import ProjectDetection
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
CONFIG_DIRECTORY = ".nex"
|
|
13
|
+
CONFIG_FILENAME = "config.toml"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ConfigAlreadyExistsError(FileExistsError):
|
|
17
|
+
"""Raised when saving would overwrite an existing Nex config."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class LearnConfig:
|
|
22
|
+
"""The stable, persisted representation of a detection result."""
|
|
23
|
+
|
|
24
|
+
root: Path
|
|
25
|
+
frontend_script: str | None
|
|
26
|
+
backend_signals: tuple[str, ...]
|
|
27
|
+
docker_compose: bool
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def build_learn_config(root: Path, detection: ProjectDetection) -> LearnConfig:
|
|
31
|
+
"""Convert a project detection result into Nex's persisted configuration."""
|
|
32
|
+
frontend_script = None
|
|
33
|
+
if detection.frontend and detection.frontend.scripts:
|
|
34
|
+
frontend_script = detection.frontend.scripts[0]
|
|
35
|
+
|
|
36
|
+
return LearnConfig(
|
|
37
|
+
root=root.resolve(),
|
|
38
|
+
frontend_script=frontend_script,
|
|
39
|
+
backend_signals=detection.python_files,
|
|
40
|
+
docker_compose=detection.docker_compose,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def write_learn_config(config: LearnConfig, *, force: bool = False) -> Path:
|
|
45
|
+
"""Write a learned config, refusing to replace an existing file by default."""
|
|
46
|
+
config_path = config.root / CONFIG_DIRECTORY / CONFIG_FILENAME
|
|
47
|
+
if config_path.exists() and not force:
|
|
48
|
+
raise ConfigAlreadyExistsError(config_path)
|
|
49
|
+
|
|
50
|
+
config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
51
|
+
config_path.write_text(render_learn_config(config), encoding="utf-8")
|
|
52
|
+
return config_path
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def render_learn_config(config: LearnConfig) -> str:
|
|
56
|
+
"""Render the fixed v1 configuration schema as TOML."""
|
|
57
|
+
lines = [
|
|
58
|
+
"schema_version = 1",
|
|
59
|
+
"",
|
|
60
|
+
"[project]",
|
|
61
|
+
f"name = {_toml_string(config.root.name)}",
|
|
62
|
+
f"root = {_toml_string(str(config.root))}",
|
|
63
|
+
"",
|
|
64
|
+
"[frontend]",
|
|
65
|
+
f"detected = {'true' if config.frontend_script is not None else 'false'}",
|
|
66
|
+
]
|
|
67
|
+
if config.frontend_script is not None:
|
|
68
|
+
lines.extend(
|
|
69
|
+
(
|
|
70
|
+
f"script = {_toml_string(config.frontend_script)}",
|
|
71
|
+
f"command = {_toml_string(f'npm run {config.frontend_script}')}",
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
lines.extend(
|
|
76
|
+
(
|
|
77
|
+
"",
|
|
78
|
+
"[backend]",
|
|
79
|
+
f"signals = {_toml_string_array(config.backend_signals)}",
|
|
80
|
+
"",
|
|
81
|
+
"[services]",
|
|
82
|
+
f"docker_compose = {'true' if config.docker_compose else 'false'}",
|
|
83
|
+
"",
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
return "\n".join(lines)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _toml_string(value: str) -> str:
|
|
90
|
+
"""Encode a string using TOML's JSON-compatible basic-string syntax."""
|
|
91
|
+
return json.dumps(value)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _toml_string_array(values: tuple[str, ...]) -> str:
|
|
95
|
+
return f"[{', '.join(_toml_string(value) for value in values)}]"
|
nex/detection.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Read-only project signal detection for Nex."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class FrontendDetection:
|
|
12
|
+
"""A JavaScript project and the conventional start scripts it exposes."""
|
|
13
|
+
|
|
14
|
+
scripts: tuple[str, ...]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class ProjectDetection:
|
|
19
|
+
"""Common project signals found in a directory."""
|
|
20
|
+
|
|
21
|
+
frontend: FrontendDetection | None
|
|
22
|
+
python_files: tuple[str, ...]
|
|
23
|
+
docker_compose: bool
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def found_anything(self) -> bool:
|
|
27
|
+
"""Whether any supported signal was found."""
|
|
28
|
+
return bool(self.frontend or self.python_files or self.docker_compose)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def detect_project(directory: Path) -> ProjectDetection:
|
|
32
|
+
"""Inspect *directory* without modifying it or traversing subdirectories."""
|
|
33
|
+
package_json = directory / "package.json"
|
|
34
|
+
frontend = _detect_frontend(package_json) if package_json.is_file() else None
|
|
35
|
+
python_files = tuple(
|
|
36
|
+
filename
|
|
37
|
+
for filename in ("requirements.txt", "pyproject.toml")
|
|
38
|
+
if (directory / filename).is_file()
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return ProjectDetection(
|
|
42
|
+
frontend=frontend,
|
|
43
|
+
python_files=python_files,
|
|
44
|
+
docker_compose=(directory / "docker-compose.yml").is_file(),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _detect_frontend(package_json: Path) -> FrontendDetection:
|
|
49
|
+
"""Read known npm scripts, tolerating malformed package metadata."""
|
|
50
|
+
try:
|
|
51
|
+
package_data = json.loads(package_json.read_text(encoding="utf-8"))
|
|
52
|
+
except (OSError, json.JSONDecodeError):
|
|
53
|
+
return FrontendDetection(scripts=())
|
|
54
|
+
|
|
55
|
+
scripts = package_data.get("scripts", {})
|
|
56
|
+
if not isinstance(scripts, dict):
|
|
57
|
+
return FrontendDetection(scripts=())
|
|
58
|
+
|
|
59
|
+
return FrontendDetection(
|
|
60
|
+
scripts=tuple(name for name in ("dev", "start") if name in scripts),
|
|
61
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nex-cli
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: A command-line interface for Nex.
|
|
5
|
+
Author: Nex contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: rich>=13
|
|
10
|
+
Requires-Dist: typer>=0.12
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# nex-cli
|
|
16
|
+
|
|
17
|
+
`nex-cli` is the command-line interface for Nex.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install the project in editable mode:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install -e .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
nex --help
|
|
31
|
+
nex --version
|
|
32
|
+
nex learn # Detect and save project signals
|
|
33
|
+
nex learn --force # Replace an existing Nex config
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Running `nex` without arguments displays help and exits successfully.
|
|
37
|
+
|
|
38
|
+
`nex learn` inspects the current directory, reports common project signals, and
|
|
39
|
+
saves them to `.nex/config.toml`. It detects:
|
|
40
|
+
`package.json` (including `dev` and `start` scripts), `requirements.txt`,
|
|
41
|
+
`pyproject.toml`, and `docker-compose.yml`.
|
|
42
|
+
|
|
43
|
+
The config records the project root, a future-ready frontend command such as
|
|
44
|
+
`npm run dev`, backend file signals, and Docker Compose presence. Nex refuses
|
|
45
|
+
to replace an existing config unless you pass `--force`.
|
|
46
|
+
|
|
47
|
+
## Not yet
|
|
48
|
+
|
|
49
|
+
- Running or supervising development processes
|
|
50
|
+
- Automatic workflow detection beyond the reported file signals
|
|
51
|
+
- Reading saved configuration to start a project
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
nex/__init__.py,sha256=jR_zLGnaVPA-KN0UDFMGZt1kTsNO0jqL5VtGLy7E2yM,57
|
|
2
|
+
nex/cli.py,sha256=QaG9DzstUjiZYAKrKJ6ttF1n-QmZ8YmhHZdOYHrn7lo,2623
|
|
3
|
+
nex/config.py,sha256=zF_wM1I_h8CVcZxl8OnihpfvQM8o85a2anQL3wsPk-E,2863
|
|
4
|
+
nex/detection.py,sha256=kjptuoEqfPXvW5SQIwBcXJsUPxB6a74jY8B6bbFB-gw,1854
|
|
5
|
+
nex_cli-0.2.1.dist-info/METADATA,sha256=z4FB53F2A-09Nvt_SqkjGWUf_GkRY8HCnloCuBqJg1o,1332
|
|
6
|
+
nex_cli-0.2.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
7
|
+
nex_cli-0.2.1.dist-info/entry_points.txt,sha256=gThS-AxsBcWPnHl5VWliYR-u7SuD5fqDfw4dbnyiLDY,36
|
|
8
|
+
nex_cli-0.2.1.dist-info/licenses/LICENSE,sha256=soXbuVf7p3iKj4kBWbL9vlr_-mZiDVbWQ4BBaqOxY-w,1073
|
|
9
|
+
nex_cli-0.2.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nex contributors
|
|
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.
|