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.jsonfile in the project root. - Outputs a
.docxfile 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copyright_code_extractor-0.1.0.tar.gz.
File metadata
- Download URL: copyright_code_extractor-0.1.0.tar.gz
- Upload date:
- Size: 59.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7901b9e10693bc85eb1125c8b94c315d433c053b88d80bd8499f4d0f4835a755
|
|
| MD5 |
d9c013dfb57c64106e8f8266873df5a9
|
|
| BLAKE2b-256 |
b782f2998d0f4a57d669d442742761b33f95df0ce19135c26b2a6102c9884fe6
|
File details
Details for the file copyright_code_extractor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: copyright_code_extractor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edf5f96628bcc216d28c1129275b0db0dd447da2a0eae21c1475ce9dcfbcce50
|
|
| MD5 |
b20ea4b7c19ad2c706eac7f97fa1823f
|
|
| BLAKE2b-256 |
e7a19a85cf420b028b50c2212022fe8f2ad193d8f177c3bd68e328221855e39a
|