Metadata-Version: 2.4
Name: samarth
Version: 0.2.0
Summary: Multi-platform Python protection pipeline — PyArmor, Nuitka, and pure-Python modes
Author-email: Samarth <creatorpc@proton.me>
License: MIT
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: <3.14,>=3.10
Description-Content-Type: text/markdown
Requires-Dist: pyarmor>=9.0
Requires-Dist: nuitka>=2.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"

# SAMARTH ENC

A Python build tool that chains multiple protection strategies — PyArmor
bytecode encryption, Nuitka native compilation, or both — into one command.
It auto-detects your environment and picks the strongest strategy that
actually works there, rather than silently producing output that won't run.

## Platform support

| Platform | Universal | PyArmor | Nuitka | Combined |
|---|---|---|---|---|
| Linux x86_64 | ✓ | ✓ | ✓ | ✓ |
| Linux ARM64 | ✓ | ✓ | ✓ | ✓ |
| Windows x86_64 | ✓ | ✓ | ✓ | ✓ |
| macOS x86_64/ARM64 | ✓ | ✓ | ✓ | ✓ |
| Termux (ARM64) | ✓ | ✓ (linux.aarch64) | ✓ (module only, Nuitka 2.6.7+) | ✗ |
| Pydroid 3 | ✓ | Experimental | ✗ | ✗ |

**Notes:**
- Nuitka standalone/onefile builds don't work reliably on Termux due to
  Android's dynamic linker not matching standard Linux assumptions.
- Pydroid has no accessible C compiler. PyArmor works experimentally there
  (its Android runtime is built for Termux/NDK Python, not Pydroid's own
  build — test before shipping).
- Cross-compiled artifacts are never portable. Build on the target device or
  use PyArmor's `--platform` flag for cross-compilation.

## Install

```bash
pip install samarth
```

If you want PyArmor and/or Nuitka protection (not just Universal mode):

```bash
pip install pyarmor nuitka
```

Nuitka requires a C compiler:

```bash
# Debian/Ubuntu/VPS
sudo apt install build-essential patchelf

# Termux
pkg install clang patchelf

# Windows — Nuitka will offer to download MinGW64 on first run
# macOS
xcode-select --install
```

**Termux-specific PyArmor fix** (if you get a `.so` load error):

```bash
patchelf --add-needed libpython3.11.so.0.1 \
  $(python -c "import pyarmor; print(__import__('pathlib').Path(pyarmor.__file__).parent)")/cli/core/android/aarch64/pytransform3.so
```

Replace `3.11` with your actual Python version.

## Usage

### Interactive menu

```
samarth
```

```
SAMARTH ENC

[1]  Universal Python Build
[2]  PyArmor Protection
[3]  Native Compilation
[4]  PyArmor + Nuitka
[5]  Termux Build
[6]  Pydroid Compatibility Build
[7]  Automatic Platform Detection
[8]  Compatibility Checker
[9]  Dependency Checker
[10] Integrity Checker
[11] Debug Protected File
[12] Build Diagnostics
[0]  Exit
```

### CLI subcommands

```bash
samarth build app.py                        # auto-select best mode
samarth build app.py --mode pyarmor         # specific mode
samarth build mypackage/ --mode combined --output dist/

samarth detect                              # show OS/arch/tool report
samarth check                               # show which modes work here
samarth deps                                # check tool availability

samarth integrity app.py <sha256-hash>      # verify file hasn't changed
samarth debug dist/app.py                   # run and show stdout/stderr
samarth diagnostics samarth_output/         # print build manifest
```

### Build modes

**universal** — copies source and precompiles `.pyc`. No external tools
needed. Works on every CPython 3.10–3.13 environment including Pydroid.
Provides no meaningful protection, just bytecode instead of source.

**pyarmor** — PyArmor bytecode encryption. Output requires the
`pyarmor_runtime_*` package at runtime. Supports cross-compilation via
`--platform` (see PyArmor docs). The only practical option for Pydroid and
the safer Termux choice.

**nuitka** — Nuitka compiles source to native code. No PyArmor layer.
Requires a C compiler. On Termux, only `--mode module` is supported
(Nuitka 2.6.7+). Not available on Pydroid.

**combined** — PyArmor encrypts first, Nuitka compiles the result. Strongest
desktop protection. Not supported on Android because Nuitka needs a full
native toolchain Android doesn't provide in Termux/Pydroid.

**termux-native** — Must run inside Termux on the target device. Runs
PyArmor with the correct `linux.*` platform string (per PyArmor's own Termux
notes, issue #1674), then optionally compiles with Nuitka `--module`. Cross-
compiling from your VPS and copying the result to Termux will not work.

**pydroid-compat** — Falls back to Universal Python mode by default.
Optionally attempts PyArmor with `--attempt-pyarmor`, but this is unverified
against Pydroid's own Python build and may fail at runtime.

## Build output

Every build creates `samarth_output/` (or `--output DIR`) containing:
- The compiled/protected files
- `samarth_manifest.json` — records what was built, on what machine,
  and explicitly notes which platforms have not been tested

The manifest is honest: a successful build on Linux x86_64 is not evidence
the output runs on Termux ARM64. Test on each target separately.

## Packaging for PyPI

```bash
pip install build twine
python -m build
twine upload dist/*
```

If shipping a PyArmor-protected extension, include the runtime folder:

```toml
[tool.setuptools.package-data]
"your_package" = ["*.so", "*.pyd", "pyarmor_runtime_*/**"]
```

First upload: create a PyPI account, generate an API token under Account
Settings → API tokens, then use `__token__` as the username and the token
as the password when twine prompts.

## Runtime checks

```python
from samarth.guard import run_all

run_all(
    min_python=(3, 10),
    max_python=(3, 13),
    allowed_platforms=("Linux", "Windows", "Darwin"),
)
```

For integrity verification, compute the hash once after your final build:

```bash
python -c "import hashlib; print(hashlib.sha256(open('app.py','rb').read()).hexdigest())"
```

Then pass it to `run_all`:

```python
run_all(expected_sha256="<hash>", file_path=__file__)
```

Every check exits with status 1 and a message on failure. None of this
resists a determined reverse engineer — it catches version mismatches and
casual debugging.

## Running tests

```bash
python -m unittest discover -v tests/
```

All 13 tests run without PyArmor or Nuitka installed. Tests that require
those tools or specific hardware (Termux, Pydroid, ARM64) are marked
with `skipTest` where the environment isn't detected.

## Troubleshooting

**`'pyarmor' not found on PATH`** — `pip install pyarmor`, confirm
`pyarmor --version` works in the same shell.

**`'nuitka' not found on PATH`** — `pip install nuitka`, and confirm a C
compiler is installed (see Install section above).

**`pyarmor produced no output`** — run `pyarmor gen` directly on your
source to see the raw error. Usually a missing activation or empty input.

**PyArmor `.so` load error in Termux** — apply the `patchelf` fix shown
in the Install section above.

**`'<name>' not found in PyArmor output`** — PyArmor renamed the entry
file. Use `samarth build ... --entry <actual-name>`.

**Output runs on build machine but not on target** — compiled output is
tied to OS, architecture, and Python version. Build on each target, or
for PyArmor use cross-platform `--platform` flags.

## License

MIT
