|
| 1 | +# Pylint |
| 2 | +This is a markdown file, click Ctrl+Shift+V to view or click open preview. |
| 3 | + |
| 4 | +This README provides an introduction to using Pylint with the Hiero Python SDK. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 📋 What Is Pylint? |
| 9 | + |
| 10 | +[Pylint](https://pylint.pycqa.org/) is a static code analysis tool for Python that checks for programming errors, helps enforce a coding standard, and offers suggestions for refactoring. It parses your code without executing it, analyzing syntax, semantics, and style. |
| 11 | + |
| 12 | +## 🎯 Why Use Pylint? |
| 13 | +Using Pylint is currently optional but it can help to: |
| 14 | + |
| 15 | +* **Detect Errors**: Catches bugs before runtime. |
| 16 | +* **Ensure Consistent Style**: Helps us apply PEP 8 and the team's custom conventions via configuration. |
| 17 | +* **Code Quality Metrics**: Provides a maintainability score to track improvements over time. |
| 18 | +* **Refactoring Aid**: Highlights unused imports, duplicate code, and other refactoring opportunities. |
| 19 | + |
| 20 | +## ⚙️ Installation |
| 21 | +In the project root: |
| 22 | + |
| 23 | +```bash |
| 24 | +# Using pip (recommended) |
| 25 | +pip install --dev pylint |
| 26 | + |
| 27 | +# Using Poetry |
| 28 | +poetry add --dev pylint |
| 29 | + |
| 30 | +# Using Conda |
| 31 | +conda install -c conda-forge pylint |
| 32 | +``` |
| 33 | + |
| 34 | +Make sure that `pylint` is available in the same virtual environment or interpreter you use to run hiero. |
| 35 | + |
| 36 | +## 🛠 Configuration |
| 37 | + |
| 38 | +1. Immediately generate a default pylint configuration file: |
| 39 | + |
| 40 | + ```bash |
| 41 | + pylint --generate-rcfile > .pylintrc |
| 42 | + ``` |
| 43 | + |
| 44 | +2. Open this new file: `.pylintrc` and customize as needed (or leave as defaults). |
| 45 | + |
| 46 | +## ▶️ Running Pylint |
| 47 | + |
| 48 | +### Single File |
| 49 | +Write pylint with the path to the file you want to check. |
| 50 | +For example: |
| 51 | + |
| 52 | +```bash |
| 53 | +pylint src/hiero_sdk_python/tokens/token_dissociate_transaction.py |
| 54 | +``` |
| 55 | + |
| 56 | +### Entire Package |
| 57 | +You can check entire folders or package if desired: |
| 58 | + |
| 59 | +```bash |
| 60 | +pylint src/hiero_sdk_python/tokens |
| 61 | +pylint src/hiero_sdk_python |
| 62 | +``` |
| 63 | + |
| 64 | +### VS Code Integration |
| 65 | +Pylint can be integrated to become much more user-friendly in VS Code. |
| 66 | + |
| 67 | +Install and enable the extension for Pylint: |
| 68 | + |
| 69 | +Search in extensions: |
| 70 | +ms-python.pylint |
| 71 | + |
| 72 | +Once downloaded, point to a Python interpreter. |
| 73 | +Run ⇧⌘P → Python: Select Interpreter and pick the venv or interpreter you’re using. |
| 74 | +Be sure to point to the correct path or add the correct path. |
| 75 | + |
| 76 | +For example, if you're using a venv/virtualenv |
| 77 | +source .venv/bin/activate |
| 78 | +pip install pylint |
| 79 | +Check /location, it should not be: |
| 80 | +Location: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages |
| 81 | +It should be more like: |
| 82 | +Location: /Users/../../hedera_sdk_python/.venv/lib/python3.10/site-packages |
| 83 | + |
| 84 | +Verify installation in that environment: |
| 85 | +```bash |
| 86 | +python -m pip show pylint |
| 87 | +``` |
| 88 | + |
| 89 | +Then: |
| 90 | +⌘+Shift+P → type → Developer: Reload Window |
| 91 | + |
| 92 | +Next, in the terminal, in the output section, click the dropdown and select Pylint. |
| 93 | + |
| 94 | +You might need to update settings.json (vscode) with something like: |
| 95 | + // — Pylint extension settings — |
| 96 | + "pylint.enabled": true, |
| 97 | + "pylint.importStrategy": "fromEnvironment", |
| 98 | + "pylint.args": [ |
| 99 | + "--rcfile=${workspaceFolder}/hedera_sdk_python/.pylintrc" |
| 100 | + ] |
| 101 | + |
| 102 | + |
| 103 | +You can also just run through terminal: |
| 104 | +```bash |
| 105 | + pylint src/hiero_sdk_python/tokens/token_dissociate_transaction.py |
| 106 | +``` |
| 107 | + |
| 108 | +## 📝 Example Output |
| 109 | + |
| 110 | +```text |
| 111 | +************* Module hiero_sdk_python.tokens.nft_id |
| 112 | +src/hiero_sdk_python/tokens/nft_id.py:44:0: C0301: Line too long (112/100) (line-too-long) |
| 113 | +src/hiero_sdk_python/tokens/nft_id.py:1:0: C0114: Missing module docstring (missing-module-docstring) |
| 114 | +src/hiero_sdk_python/tokens/nft_id.py:14:4: C0103: Attribute name "tokenId" doesn't conform to snake_case naming style (invalid-name) |
| 115 | +------------------------------------ |
| 116 | +Your code has been rated at 8.50/10 |
| 117 | +``` |
| 118 | + |
| 119 | +## ✅ Next Steps |
| 120 | + |
| 121 | +* Tweak `.pylintrc` to gradually enable more strict rules. |
| 122 | +* Integrate Pylint to your VS code. |
| 123 | +* Integrate Pylint into your CI pipeline (GitHub Actions, GitLab CI). |
| 124 | +* Combine with other packages. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +Happy linting! 🚀 |
0 commit comments