Solc Automated Parser and Installation Tool
Project description
Solc-Parser
A powerful Solidity compiler (solc) version management tool that automatically parses Solidity files and installs the appropriate solc version based on pragma statements and version requirements.
Features
- Automatic Version Detection: Parses Solidity files to extract version requirements from pragma statements
- Complete npm Semver Support: Full implementation of npm semantic versioning rules including:
- Caret ranges (
^1.2.3) - Tilde ranges (
~1.2.3) - Hyphen ranges (
1.2.3 - 2.3.4) - X-ranges (
1.2.x,1.x,*,0.8.*) - Comparison operators (
>=,<=,>,<,=) - Logical OR (
||) - Prerelease tags (
1.2.3-alpha.1) - Build metadata (
1.2.3+build.1)
- Caret ranges (
- Advanced Pragma Support: Parses and handles:
pragma solidityversion rangespragma abicoder v1/v2pragma experimental ABIEncoderV2, SMTChecker
- Automatic Installation: Downloads and installs solc binaries from official sources
- Global Version Management: Creates symbolic links for easy version switching
- Cross-Platform Support: Works on Linux and macOS
- PATH Integration: Provides instructions for PATH setup
Installation
From Source
git clone https://github.com/siksum/Solc-Parser.git
cd Solc-Parser
pip install -e .
Using pip
pip install solc-parser
Usage
Basic Usage
Parse a Solidity file and automatically install the appropriate solc version:
solc-parser your_contract.sol
Command Line Options
# List all available solc versions
solc-parser --list
# Install specific version(s)
solc-parser --install 0.8.30
solc-parser --install 0.7.* # Install latest 0.7.x version
# Use specific version
solc-parser --use 0.8.30
solc-parser --use 0.7.* # Use latest 0.7.x version
# Uninstall version(s)
solc-parser --uninstall 0.7.6
# Show current version
solc-parser --version
Examples
Simple Solidity File
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleContract {
uint256 public value;
function setValue(uint256 _value) external {
value = _value;
}
}
Running solc-parser simple.sol will:
- Parse the pragma statement
^0.8.0 - Find the latest compatible version (e.g., 0.8.30)
- Download and install solc 0.8.30
- Create a symbolic link for global use
Advanced Solidity File with Multiple Pragmas
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
pragma experimental SMTChecker;
contract AdvancedContract {
struct ComplexStruct {
uint256[] numbers;
string name;
}
function processData(ComplexStruct memory data) external pure returns (uint256) {
return data.numbers.length;
}
}
Running solc-parser advanced.sol will:
- Parse all pragma statements
- Determine version requirements:
^0.8.0(solidity version)>=0.5.0(abicoder v2 requirement)>=0.5.0(SMTChecker requirement)
- Find the best matching version that satisfies all requirements
- Install and configure the appropriate solc version
Version Range Support
Caret Ranges (^)
^1.2.3:=>=1.2.3 <2.0.0^0.2.3:=>=0.2.3 <0.3.0^0.0.3:=>=0.0.3 <0.1.0
Tilde Ranges (~)
~1.2.3:=>=1.2.3 <1.3.0~1.2:=>=1.2.0 <1.3.0~1:=>=1.0.0 <2.0.0
X-Ranges
1.2.xor1.2.*:=>=1.2.0 <1.3.01.xor1.*:=>=1.0.0 <2.0.0*orx:= accepts all versions
Hyphen Ranges
1.2.3 - 2.3.4:=>=1.2.3 <=2.3.4
Comparison Operators
>=1.2.3,<=1.2.3,>1.2.3,<1.2.3,=1.2.3
Logical OR
^1.2.3 || ^2.3.4:= satisfies either range
Installation Directory
Solc binaries are installed in:
~/.solc-parser/bin/
├── solc-0.7.6/
│ └── solc
├── solc-0.8.30/
│ └── solc
└── solc -> solc-0.8.30/solc # Symbolic link to current version
PATH Setup
After installation, add the binary directory to your PATH:
Temporary (current session only)
export PATH="$HOME/.solc-parser/bin:$PATH"
Permanent (bash)
echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Permanent (zsh)
echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Alternative: Use alias
echo "alias solc='$HOME/.solc-parser/bin/solc'" >> ~/.bashrc
source ~/.bashrc
Requirements
- Python 3.8 or higher
- Linux or macOS
- Internet connection for downloading solc binaries
Dependencies
requests: For downloading solc binaries
Development
Building
./build.sh
Testing
python -m pytest tests/
License
This project is licensed under the GNU General Public License v3 (GPLv3) - see the LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Issues
If you encounter any issues, please report them on the GitHub Issues page.
Author
Namryeong Kim - GitHub
Acknowledgments
- Solidity team for the official solc binaries
- npm semver specification for version range parsing rules
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 solc_parser-1.1.0.tar.gz.
File metadata
- Download URL: solc_parser-1.1.0.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9319885605744d5f4866d349ba821f471a6aa6c8164c069be2734831e5a50ceb
|
|
| MD5 |
b2cdfe699b155bbef210d239019f380e
|
|
| BLAKE2b-256 |
8854d8e8084bb6dfd422616505b25f9886958f16e7a3ffd31a45839b0aa84655
|
File details
Details for the file solc_parser-1.1.0-py3-none-any.whl.
File metadata
- Download URL: solc_parser-1.1.0-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
704f2a0487324ca2589754267c96f20355093efc61bcec577d6a42af5a5d3555
|
|
| MD5 |
3bbdc9aedced85f0d7791179f7dada89
|
|
| BLAKE2b-256 |
722a36c38fe92e4065110c46a35b1440010cf1765b42e5b6d499fad84528a401
|