nex-cli 0.2.1__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.
@@ -0,0 +1,54 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build:
13
+ name: Build distributions
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Check out repository
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.12"
23
+
24
+ - name: Build package
25
+ run: |
26
+ python -m pip install --upgrade build
27
+ python -m build
28
+
29
+ - name: Upload distributions
30
+ uses: actions/upload-artifact@v4
31
+ with:
32
+ name: distributions
33
+ path: dist/
34
+
35
+ publish:
36
+ name: Publish distributions to PyPI
37
+ needs: build
38
+ runs-on: ubuntu-latest
39
+ environment:
40
+ name: pypi
41
+ url: https://pypi.org/p/nex-cli
42
+ permissions:
43
+ id-token: write
44
+ steps:
45
+ - name: Download distributions
46
+ uses: actions/download-artifact@v4
47
+ with:
48
+ name: distributions
49
+ path: dist/
50
+
51
+ - name: Publish package distributions to PyPI
52
+ uses: pypa/gh-action-pypi-publish@release/v1
53
+ with:
54
+ packages-dir: dist/
@@ -0,0 +1,5 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ .venv/
5
+ *.egg-info/
nex_cli-0.2.1/LICENSE ADDED
@@ -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.
nex_cli-0.2.1/PKG-INFO ADDED
@@ -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,37 @@
1
+ # nex-cli
2
+
3
+ `nex-cli` is the command-line interface for Nex.
4
+
5
+ ## Installation
6
+
7
+ Install the project in editable mode:
8
+
9
+ ```bash
10
+ pip install -e .
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ nex --help
17
+ nex --version
18
+ nex learn # Detect and save project signals
19
+ nex learn --force # Replace an existing Nex config
20
+ ```
21
+
22
+ Running `nex` without arguments displays help and exits successfully.
23
+
24
+ `nex learn` inspects the current directory, reports common project signals, and
25
+ saves them to `.nex/config.toml`. It detects:
26
+ `package.json` (including `dev` and `start` scripts), `requirements.txt`,
27
+ `pyproject.toml`, and `docker-compose.yml`.
28
+
29
+ The config records the project root, a future-ready frontend command such as
30
+ `npm run dev`, backend file signals, and Docker Compose presence. Nex refuses
31
+ to replace an existing config unless you pass `--force`.
32
+
33
+ ## Not yet
34
+
35
+ - Running or supervising development processes
36
+ - Automatic workflow detection beyond the reported file signals
37
+ - Reading saved configuration to start a project
nex_cli-0.2.1/docs ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ """Nex command-line interface."""
2
+
3
+ __version__ = "0.2.1"
@@ -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()
@@ -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)}]"
@@ -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,25 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "nex-cli"
7
+ version = "0.2.1"
8
+ description = "A command-line interface for Nex."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Nex contributors" }]
13
+ dependencies = ["rich>=13", "typer>=0.12"]
14
+
15
+ [project.optional-dependencies]
16
+ dev = ["pytest>=7"]
17
+
18
+ [project.scripts]
19
+ nex = "nex.cli:run"
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ packages = ["nex"]
23
+
24
+ [tool.pytest.ini_options]
25
+ testpaths = ["tests"]
File without changes
@@ -0,0 +1,72 @@
1
+ import json
2
+
3
+ from typer.testing import CliRunner
4
+
5
+ from nex.cli import app
6
+
7
+
8
+ runner = CliRunner()
9
+
10
+
11
+ def test_help() -> None:
12
+ result = runner.invoke(app, ["--help"])
13
+
14
+ assert result.exit_code == 0
15
+ assert "Usage:" in result.output
16
+
17
+
18
+ def test_version() -> None:
19
+ result = runner.invoke(app, ["--version"])
20
+
21
+ assert result.exit_code == 0
22
+ assert result.output == "nex 0.2.1\n"
23
+
24
+
25
+ def test_no_arguments_shows_help() -> None:
26
+ result = runner.invoke(app)
27
+
28
+ assert result.exit_code == 0
29
+ assert "Usage:" in result.output
30
+
31
+
32
+ def test_learn_reports_detected_project_signals(tmp_path, monkeypatch) -> None:
33
+ (tmp_path / "package.json").write_text(
34
+ json.dumps({"scripts": {"dev": "vite"}}), encoding="utf-8"
35
+ )
36
+ (tmp_path / "requirements.txt").write_text("fastapi\n", encoding="utf-8")
37
+ monkeypatch.chdir(tmp_path)
38
+
39
+ result = runner.invoke(app, ["learn"])
40
+
41
+ assert result.exit_code == 0
42
+ assert "Frontend" in result.output
43
+ assert "package.json (dev)" in result.output
44
+ assert "Python backend" in result.output
45
+ assert "Saved Nex config to" in result.output
46
+ assert (tmp_path / ".nex" / "config.toml").is_file()
47
+
48
+
49
+ def test_learn_refuses_to_overwrite_existing_config(tmp_path, monkeypatch) -> None:
50
+ config_path = tmp_path / ".nex" / "config.toml"
51
+ config_path.parent.mkdir()
52
+ config_path.write_text("keep = true\n", encoding="utf-8")
53
+ monkeypatch.chdir(tmp_path)
54
+
55
+ result = runner.invoke(app, ["learn"])
56
+
57
+ assert result.exit_code == 1
58
+ assert "Use --force to overwrite it." in result.output
59
+ assert config_path.read_text(encoding="utf-8") == "keep = true\n"
60
+
61
+
62
+ def test_learn_force_overwrites_existing_config(tmp_path, monkeypatch) -> None:
63
+ config_path = tmp_path / ".nex" / "config.toml"
64
+ config_path.parent.mkdir()
65
+ config_path.write_text("old = true\n", encoding="utf-8")
66
+ monkeypatch.chdir(tmp_path)
67
+
68
+ result = runner.invoke(app, ["learn", "--force"])
69
+
70
+ assert result.exit_code == 0
71
+ assert "Saved Nex config to" in result.output
72
+ assert "old = true" not in config_path.read_text(encoding="utf-8")
@@ -0,0 +1,73 @@
1
+ import json
2
+ import tomllib
3
+
4
+ import pytest
5
+
6
+ from nex.config import (
7
+ ConfigAlreadyExistsError,
8
+ build_learn_config,
9
+ write_learn_config,
10
+ )
11
+ from nex.detection import detect_project
12
+
13
+
14
+ def test_writes_config_for_a_fresh_project_directory(tmp_path) -> None:
15
+ (tmp_path / "requirements.txt").write_text("fastapi\n", encoding="utf-8")
16
+ config = build_learn_config(tmp_path, detect_project(tmp_path))
17
+
18
+ config_path = write_learn_config(config)
19
+
20
+ assert config_path == tmp_path / ".nex" / "config.toml"
21
+ assert config_path.is_file()
22
+
23
+
24
+ def test_does_not_clobber_an_existing_config(tmp_path) -> None:
25
+ config_path = tmp_path / ".nex" / "config.toml"
26
+ config_path.parent.mkdir()
27
+ config_path.write_text("keep = true\n", encoding="utf-8")
28
+ config = build_learn_config(tmp_path, detect_project(tmp_path))
29
+
30
+ with pytest.raises(ConfigAlreadyExistsError):
31
+ write_learn_config(config)
32
+
33
+ assert config_path.read_text(encoding="utf-8") == "keep = true\n"
34
+
35
+
36
+ def test_force_overwrites_an_existing_config(tmp_path) -> None:
37
+ config_path = tmp_path / ".nex" / "config.toml"
38
+ config_path.parent.mkdir()
39
+ config_path.write_text("old = true\n", encoding="utf-8")
40
+ (tmp_path / "requirements.txt").write_text("fastapi\n", encoding="utf-8")
41
+ config = build_learn_config(tmp_path, detect_project(tmp_path))
42
+
43
+ write_learn_config(config, force=True)
44
+
45
+ assert "old = true" not in config_path.read_text(encoding="utf-8")
46
+ assert tomllib.loads(config_path.read_text(encoding="utf-8"))["backend"] == {
47
+ "signals": ["requirements.txt"]
48
+ }
49
+
50
+
51
+ def test_config_content_captures_a_mixed_project(tmp_path) -> None:
52
+ (tmp_path / "package.json").write_text(
53
+ json.dumps({"scripts": {"start": "next start"}}), encoding="utf-8"
54
+ )
55
+ (tmp_path / "pyproject.toml").write_text("[project]\nname = 'api'\n", encoding="utf-8")
56
+ (tmp_path / "docker-compose.yml").write_text("services: {}\n", encoding="utf-8")
57
+
58
+ config_path = write_learn_config(
59
+ build_learn_config(tmp_path, detect_project(tmp_path))
60
+ )
61
+ content = tomllib.loads(config_path.read_text(encoding="utf-8"))
62
+
63
+ assert content == {
64
+ "schema_version": 1,
65
+ "project": {"name": tmp_path.name, "root": str(tmp_path.resolve())},
66
+ "frontend": {
67
+ "detected": True,
68
+ "script": "start",
69
+ "command": "npm run start",
70
+ },
71
+ "backend": {"signals": ["pyproject.toml"]},
72
+ "services": {"docker_compose": True},
73
+ }
@@ -0,0 +1,47 @@
1
+ import json
2
+
3
+ from nex.detection import detect_project
4
+
5
+
6
+ def test_detects_frontend_project_and_known_scripts(tmp_path) -> None:
7
+ (tmp_path / "package.json").write_text(
8
+ json.dumps({"scripts": {"dev": "vite", "test": "vitest"}}), encoding="utf-8"
9
+ )
10
+
11
+ detection = detect_project(tmp_path)
12
+
13
+ assert detection.frontend is not None
14
+ assert detection.frontend.scripts == ("dev",)
15
+ assert detection.python_files == ()
16
+ assert not detection.docker_compose
17
+
18
+
19
+ def test_detects_python_backend_project(tmp_path) -> None:
20
+ (tmp_path / "requirements.txt").write_text("fastapi\n", encoding="utf-8")
21
+
22
+ detection = detect_project(tmp_path)
23
+
24
+ assert detection.frontend is None
25
+ assert detection.python_files == ("requirements.txt",)
26
+ assert not detection.docker_compose
27
+
28
+
29
+ def test_detects_mixed_project(tmp_path) -> None:
30
+ (tmp_path / "package.json").write_text(
31
+ json.dumps({"scripts": {"start": "next start"}}), encoding="utf-8"
32
+ )
33
+ (tmp_path / "pyproject.toml").write_text("[project]\nname = 'api'\n", encoding="utf-8")
34
+ (tmp_path / "docker-compose.yml").write_text("services: {}\n", encoding="utf-8")
35
+
36
+ detection = detect_project(tmp_path)
37
+
38
+ assert detection.frontend is not None
39
+ assert detection.frontend.scripts == ("start",)
40
+ assert detection.python_files == ("pyproject.toml",)
41
+ assert detection.docker_compose
42
+
43
+
44
+ def test_reports_no_signals_for_empty_directory(tmp_path) -> None:
45
+ detection = detect_project(tmp_path)
46
+
47
+ assert not detection.found_anything