Skip to main content

code-porter

PyPI - Python Version PyPI Version CI License

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

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

快速开始

无需安装任何 Python 环境或依赖,一行命令即可运行:

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

uvxuv 自带的命令,如果尚未安装 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

默认终端输出包括:

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

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

--status / -s 可选值:dirtycleangitnot-gitremoteno-remoteexportableskipbundleoverlayzip

导出 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

# 交互终端会弹出 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 说明:

  • depsnode_modules.venvvenv.uv-cache 等可重装依赖(推荐)
  • cache.next.cache__pycache__、各类工具缓存
  • builddistbuildtarget 等构建产物(风险更高,需有意选择)
  • all:以上全部(仍永远不会删除 .git

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

命令

命令 作用
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、.git
  • 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

发布

uv build
uv publish

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_porter-0.4.1.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_porter-0.4.1-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file code_porter-0.4.1.tar.gz.

File metadata

  • Download URL: code_porter-0.4.1.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for code_porter-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7c6e80863ec6a548f6133f37bb0513339e19b0b62ec7521083091f618ca93b4e
MD5 9a6261e2845162c5956f3d6df781e82b
BLAKE2b-256 77eb2c28b72076027be948af87ad58a5383db5243c9a2a6b827bcae4bb04a2a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for code_porter-0.4.1.tar.gz:

Publisher: publish.yml on star-plan/code-porter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code_porter-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: code_porter-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for code_porter-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 959190eb0c5d9a97fc9d095d9c6303123609d03970a7a3d60041965a263be042
MD5 b9c5c262cbb5eb865314c9258bcfcb79
BLAKE2b-256 96415fc8f4b96eb3f16d7c10c3e7bb055186bf7e58d992dc21c04cc675c7a47e

See more details on using hashes here.

Provenance

The following attestation bundles were made for code_porter-0.4.1-py3-none-any.whl:

Publisher: publish.yml on star-plan/code-porter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.0

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

This release

0.4.1 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

0.0.3

2 files

0.0.2

2 files

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