Skip to main content

code-porter

PyPI - Python Version PyPI Version CI License

一个纯本地运行的代码库导入导出工具。它会在当前机器上扫描项目,优先将 Git 仓库导出为 git bundle,将非 Git 项目导出为 zip;导出完成后,可在另一台机器上基于 manifest 批量导入。

设计文档见 docs/(产品设计 · 技术架构)。局部变更计划放在 docs/changes/。

快速开始

普通用户:包管理器安装(推荐)

前置条件: 本机需已安装 Git 并加入 PATH(导出 / 导入 bundle 会调用系统 git)。

Scoop(Windows)

scoop bucket add star-plan https://github.com/star-plan/scoop
scoop install code-porter
code-porter --help

Homebrew(macOS / Linux)

brew tap star-plan/tap
brew install code-porter
code-porter --help

普通用户:下载预编译二进制

不需要安装 Python 或 uv。打开 GitHub Releases,按系统下载对应文件:

平台 文件
Windows (x64) code-porter-windows-amd64.exe
Linux (x64) code-porter-linux-amd64
macOS (Intel) code-porter-macos-amd64
macOS (Apple Silicon) code-porter-macos-arm64
# Linux / macOS
chmod +x code-porter-linux-amd64   # 或对应的 macOS 文件名
./code-porter-linux-amd64 --help

# Windows(PowerShell / cmd)
.\code-porter-windows-amd64.exe --help

可用 Release 中的 SHA256SUMS 校验下载文件。Windows SmartScreen 或 macOS Gatekeeper 可能拦截未签名程序:Windows 选「更多信息 → 仍要运行」;macOS 可右键 → 打开。

开发者:uvx 一行运行

无需手动装依赖,一行命令即可运行:

# 查看帮助
uvx code-porter --help

uvx 是 uv 自带的命令,如果尚未安装 uv,可参考 uv 官方安装指南。

用法

扫描本地目录

# 默认:紧凑表格 + 汇总(适合人读)
uvx code-porter scan ~/code ~/lab

# 需要落盘时再写 JSON 文件
uvx code-porter scan ~/code ~/lab --json-output reports/local-scan.json

# 脚本/管道:只输出 JSON
uvx code-porter scan ~/code ~/lab --json

# 查看完整列(remote / clean / 大目录 / 完整原因)
uvx code-porter scan ~/code ~/lab --verbose

# 只看脏工作区项目(可重复 --status / -s,OR 关系)
uvx code-porter scan ~/code --status dirty
uvx code-porter scan ~/code -s dirty -s no-remote

# 按体积从大到小排序(可再加 --reverse / -r 反转)
uvx code-porter scan ~/code --sort size
uvx code-porter scan ~/code -S name -r

默认终端输出包括:

  • 项目名称、类型、Git 状态(是否仓库 / remote / clean)
  • 目录大小、推荐打包策略、是否值得导出
  • 简短 Note,以及一行汇总(各策略数量、值得导出数量)

使用 --verbose 可额外看到 remote、clean、大目录、忽略目录与完整原因;使用 --json / --json-output 获取完整机器可读结果(含路径、remote URL 等)。

--status / -s 可选值:dirty、clean、git、not-git、remote、no-remote、exportable、skip、bundle、overlay、zip。

--sort / -S 可选值:path、name、size(默认大→小)、type、package、export(值得导出优先)。加 --reverse / -r 可反转该字段的自然方向。筛选(--status)先于排序。

导出 bundle/zip 归档

uvx code-porter export ~/code ~/lab ./exports/local-backup

导入归档

uvx code-porter import ./exports/local-backup/manifest.json ~/code/imported

清理可重建垃圾目录

# 默认 dry-run:列出 deps / cache / build 候选及体积
uvx code-porter clean ~/code

# 按可回收体积从大到小排序
uvx code-porter clean ~/code --sort size
uvx code-porter clean ~/code -S project

# 交互终端会弹出 checkbox 勾选 profile,并询问是否立刻删除
# 非交互 / 脚本用法:
uvx code-porter clean ~/code -p deps --apply --yes
uvx code-porter clean ~/code -p deps -p cache --apply --yes
uvx code-porter clean ~/code -p all --apply --yes

Profile 说明:

  • deps:node_modules、.venv、venv、.uv-cache / uv-cache、gomodcache 等可重装依赖(推荐);以及含 repositories.config 的老 NuGet packages
  • cache:.next、.cache、.vs、__pycache__、gocache 等各类工具缓存
  • build:dist、build、target 等构建产物(风险更高,需有意选择);以及紧挨 .csproj / .fsproj / .vbproj / .sln 的 bin、obj,和 VSTest 的 TestResults
  • all:以上全部(仍永远不会删除 .git)

匹配按目录名(basename),因此 .tmp/uv-cache、.tmp/gocache 这类嵌套缓存也会被识别;不会整目录删除可能混有业务文件的 .tmp。歧义名字例外:bin / obj 需父目录有 .NET 工程文件;TestResults 需邻居工程文件或目录内有 .trx;packages 需含 repositories.config。scan 体积与 zip 导出使用同一套规则,因此不会把脚本仓的 bin/ 排除掉。

默认只预览不删除;必须显式 --apply 才会动手。非交互模式下 --apply 还需要 -p/--profile 与 -y/--yes。

默认列表顺序为 profile(deps → cache → build),同 profile 内按体积从大到小。可用 --sort / -S 改为 size、project、name、path 等;--reverse / -r 反转自然方向。

命令

命令 作用
scan 扫描本地目录,分析项目结构
clean 预览/删除可重建垃圾目录(node_modules、.venv 等)
export 扫描并输出 bundle/zip 归档,以及 manifest.json
import 根据 manifest.json 将归档导入到目标目录

当前打包策略

  • 干净 Git 仓库:导出 git bundle
  • 脏 Git 仓库:导出 git bundle,并额外导出工作区 overlay zip
  • 非 Git 项目:导出 zip

说明

  • 默认会排除 node_modules、.venv、dist、build、target、.next、.cache、.vs、.git;.NET 的 bin/obj/TestResults 按邻居规则排除,不会全局匹配名为 bin 的目录
  • scan 将 *.csproj / *.fsproj / *.vbproj / *.sln / *.slnx 识别为 dotnet 项目;无 git 时多个 csproj 会收束到最近的解决方案文件
  • scan 与 export 支持 --large-dir-threshold-mb 调整大目录阈值
  • scan 默认只输出紧凑表格与汇总;--json 纯 JSON,--json-output 写文件,-v/--verbose 显示完整列,-s/--status 按状态筛选
  • clean 默认 dry-run;交互终端可用 checkbox 勾选 profile;--apply 真删,非交互需 -p + -y
  • scan、export、import 会在终端显示进度条,减少长任务等待焦虑
  • 导出 zip 时会读取项目根目录的 .gitignore,并叠加默认排除目录
  • bundle 导入后如果存在 overlay zip,会在 clone 后覆盖工作区文件,以保留未提交改动
  • import 遇到已存在目录时默认跳过,可用 --on-existing replace 覆盖

开发者

# 克隆仓库后,使用 uv 同步依赖
git clone https://github.com/deali/code-porter
cd code-porter
uv sync

# 运行
uv run code-porter --help

发布

# 本地构建并上传到 PyPI
uv build
uv publish

打 v*.*.* 标签推送后,GitHub Actions 会:

  1. 运行测试并发布 wheel/sdist 到 PyPI
  2. 在 Windows / Linux / macOS 上用 PyInstaller 构建 standalone 二进制
  3. 创建 GitHub Release,附带各平台二进制与 SHA256SUMS
  4. (可选)若配置了 PACKAGING_TOKEN,通知 star-plan/scoop 与 star-plan/homebrew-tap 立即同步;否则对方按 cron 自动拉取 Release 本地预览二进制(需 dev 依赖):
uv sync --group dev
uv run pyinstaller --noconfirm --clean packaging/code-porter.spec
# 产物:dist/code-porter 或 dist/code-porter.exe

Metadata

Release files for code-porter 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for code-porter 0.6.0
File Size Uploaded Provenance Actions
code_porter-0.6.0.tar.gz 45.5 kB With provenance Details for code_porter-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for code-porter 0.6.0
File Interpreter ABI Platform Actions
code_porter-0.6.0-py3-none-any.whl Python 3 none any Details for code_porter-0.6.0-py3-none-any.whl

Total release size: 83.5 kB

Release files / code_porter-0.6.0.tar.gz

Download URL code_porter-0.6.0.tar.gz
Size 45.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d42d9b425e0f524b228d9f50eff022104237185776d448e12faedb0847e3e30c
BLAKE2b-256 checksum
How to use checksums
984be7e25c7dc3fe95b9df30535b316b9b158893e603cd8be8e2d929441c7898
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release files / code_porter-0.6.0-py3-none-any.whl

Download URL code_porter-0.6.0-py3-none-any.whl
Size 38.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47f05489cfad9aa5ab6158791a648838a1eefa609414abb806f5aeb429ba3890
BLAKE2b-256 checksum
How to use checksums
7caf2a0227e3c683dd88ed06d97b7bebc4968fbd939ecaf6dcabd154c287916d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Security for code-porter 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for code_porter-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page