Skip to main content

A tool to extract source code for China Software Copyright application.

Project description

Copyright Code Extractor

A tool to automatically extract source code lines from a project, designed to meet the requirements for China Software Copyright (软著) application.

It scans a project directory, finds relevant source files based on common extensions, removes comments, and concatenates the code into a single DOCX file, formatted with approximately 50 lines per page.

Features

  • Extracts a configurable number of code lines (default: 3000).
  • Optionally extracts all code for the "first 30 + last 30 pages" rule.
  • Removes single-line (//, #) and multi-line (/* ... */) comments.
  • Ignores common binary files, version control directories, dependencies (node_modules, .venv, etc.), and configuration files by default.
  • Supports configuration via a .copyright-extractor.json file in the project root.
  • Outputs a .docx file ready for submission.

Installation

It's recommended to use a modern Python package manager like uv or pip within a virtual environment.

# Using uv (recommended)
uv venv # Create virtual environment (if not already done)
source .venv/bin/activate # Activate environment (Linux/macOS)
# or .\.venv\Scripts\activate (Windows)
uv pip install -e .

# Using pip
python -m venv .venv
source .venv/bin/activate # Activate environment (Linux/macOS)
# or .\.venv\Scripts\activate (Windows)
pip install -e .

Usage

After installation, you can run the extractor from your terminal. Provide the path to the root directory of the project you want to analyze.

Basic Usage:

copyright-code-extractor /path/to/your/project

Or, if you prefer using python -m:

# Using uv
uv run python -m copyright_code_extractor /path/to/your/project

# Using python directly from the activated venv
python -m copyright_code_extractor /path/to/your/project

This will generate an extracted_code.docx file in the current directory.

Common Options:

  • -o, --output FILE_PATH: Specify a different output DOCX file path.
  • -l, --lines NUM_LINES: Override the total number of lines to extract.
  • --all: Extract all lines (for the "first 30 + last 30 pages" rule), overrides --lines.
  • -c, --config CONFIG_FILE: Specify a path to a custom configuration file.
  • -v, --verbose: Enable more detailed logging output.
  • --version: Show the version and exit.
  • --help: Show help message with all options.

Configuration

You can customize the extraction process by creating a .copyright-extractor.json file in the root directory of the project being analyzed (e.g., /path/to/your/project/.copyright-extractor.json).

The tool will automatically detect and use this file if it exists. You can override settings from the config file using command-line options.

Example .copyright-extractor.json:

{
  "output_file": "MyProject_SourceCode_ForCopyright.docx",
  "lines_to_extract": 4000,
  "extract_all": false,
  "source_root": "src", // Optional: Specify if main source code is in a sub-directory
  "ignore_patterns": [
    ".git",
    ".idea",
    ".vscode",
    ".venv",
    "node_modules",
    "dist",
    "build",
    "__pycache__",
    "*.log",
    "tests", // Add project-specific patterns
    "docs"
  ],
  "include_extensions": [
    // List only the extensions you want to include
    ".py",
    ".ts",
    ".tsx",
    ".vue",
    ".java",
    ".go"
  ]
}

See src/copyright_code_extractor/config.py for all available configuration options and their defaults.

License

This project is licensed under the GNU General Public License v3.0.

Project details


Download files

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

Source Distribution

copyright_code_extractor-0.1.0.tar.gz (59.2 kB view details)

Uploaded Source

Built Distribution

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

copyright_code_extractor-0.1.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page