Skip to content

Conversation

@tahatehran
Copy link
Contributor

No description provided.

Saraye Tell and others added 10 commits January 31, 2026 00:20
# Conflicts:
#	iran_encoding/__init__.py
- Ported legacy C logic to pure Python for zero-dependency reliability.
- Implemented requested language detection and number handling rules.
- Improved C extension and wrapper for performance optimization.
- Professionalized documentation in English and Persian.
- Updated and expanded test suite (all 37 tests passing).
- Prepared for PyPI distribution as v1.1.0.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>
- Deleted redundant and failing `.github/workflows/python-package-conda.yml`.
- Updated `.github/workflows/ci.yml` and `qodana-ci.yml` to run on all branches for better validation.
- Updated `MANIFEST.in` to include C and H source files for proper source distribution.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>
…0-10619367560126165419

Professional overhaul of Iran System encoding library
- Fixed `qodana.yml` by merging duplicate `properties` keys.
- Fixed `tests/test_suite.py` to correctly add the tests directory to `sys.path`, resolving `ModuleNotFoundError` during test collection in CI.
- Verified fix by running `pytest` locally.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>
…0-10619367560126165419

fix: resolve CI failures in qodana and test suite
* chore: finalize professional release v1.1.0

- Updated author metadata and support email in `setup.py`.
- Overhauled README and Wiki documentation in both English and Persian.
- Refactored Qodana configuration to `.qodana/qodana.yml`.
- Cleaned up redundant files (`requirements.txt`, `test_encoding.py`).
- Optimized CI workflows for the new project structure.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* chore: clean up IDE artifacts and refine gitignore

- Removed `.idea/` directory.
- Refined `.gitignore` to include more specific exclusions for C compiled artifacts, IDE settings, and Qodana caches.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: correct qodana workflow args and update linter version

- Updated `qodana-ci.yml` to use `--yaml-name` instead of `-c` and upgraded action version to `v2024.3`.
- Ensured all documentation and metadata are finalized.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve Qodana YAML unmarshal error and optimize config

- Fixed `qodana.yml` by quoting boolean values in `properties` to satisfy the `map[string]string` constraint.
- Refined `exclude` section to use a standard format.
- Updated `qodana-ci.yml` to symlink the config to the root for better compatibility with the Qodana action.
- Verified all tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* feat: automate pypi publishing on push to main

- Updated `publish-to-pypi.yml` to trigger automatically on push to `main`.
- Added twine check step for package distribution validation.
- Upgraded checkout and setup-python actions to latest versions.
- Finalized professional configuration for release.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve qodana configuration issues and finalize release

- Refactored `qodana.yaml` to use the correct `linter` key and hidden directory.
- Updated `qodana-ci.yml` to point to the new configuration location.
- Verified all tests pass.
- Cleaned up .idea and refined .gitignore.
- Finalized professional documentation and wiki.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve Qodana CI failures and schema errors

- Updated `qodana.yaml` to use the correct `linter` key and Community image.
- Quoted boolean values in `properties` to satisfy the map[string]string constraint.
- Updated `qodana-ci.yml` to copy the configuration file to the root during analysis, ensuring the scan finds it.
- Verified project integrity with all 76 tests passing.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: optimize qodana config for community edition

- Removed redundant `bootstrap` command from `qodana.yaml`.
- Set linter to `jetbrains/qodana-python-community:latest` for compatibility with the free version.
- Simplified configuration properties.
- Verified all tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* chore: finalize professional release v1.1.0

- Updated author metadata and support email in `setup.py`.
- Overhauled README and Wiki documentation in both English and Persian.
- Refactored Qodana configuration to `.qodana/qodana.yml`.
- Cleaned up redundant files (`requirements.txt`, `test_encoding.py`).
- Optimized CI workflows for the new project structure.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* chore: clean up IDE artifacts and refine gitignore

- Removed `.idea/` directory.
- Refined `.gitignore` to include more specific exclusions for C compiled artifacts, IDE settings, and Qodana caches.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: correct qodana workflow args and update linter version

- Updated `qodana-ci.yml` to use `--yaml-name` instead of `-c` and upgraded action version to `v2024.3`.
- Ensured all documentation and metadata are finalized.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve Qodana YAML unmarshal error and optimize config

- Fixed `qodana.yml` by quoting boolean values in `properties` to satisfy the `map[string]string` constraint.
- Refined `exclude` section to use a standard format.
- Updated `qodana-ci.yml` to symlink the config to the root for better compatibility with the Qodana action.
- Verified all tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* feat: automate pypi publishing on push to main

- Updated `publish-to-pypi.yml` to trigger automatically on push to `main`.
- Added twine check step for package distribution validation.
- Upgraded checkout and setup-python actions to latest versions.
- Finalized professional configuration for release.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve qodana configuration issues and finalize release

- Refactored `qodana.yaml` to use the correct `linter` key and hidden directory.
- Updated `qodana-ci.yml` to point to the new configuration location.
- Verified all tests pass.
- Cleaned up .idea and refined .gitignore.
- Finalized professional documentation and wiki.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve Qodana CI failures and schema errors

- Updated `qodana.yaml` to use the correct `linter` key and Community image.
- Quoted boolean values in `properties` to satisfy the map[string]string constraint.
- Updated `qodana-ci.yml` to copy the configuration file to the root during analysis, ensuring the scan finds it.
- Verified project integrity with all 76 tests passing.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: optimize qodana config for community edition

- Removed redundant `bootstrap` command from `qodana.yaml`.
- Set linter to `jetbrains/qodana-python-community:latest` for compatibility with the free version.
- Simplified configuration properties.
- Verified all tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* chore: clean up redundant test data and verify encoding parity

- Removed `tests/corpus.json` as requested.
- Verified that the visual encoding logic (parentheses and alphanumeric sequences) correctly matches legacy expectations.
- Confirmed all 76 tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* chore: finalize professional release v1.1.0

- Updated author metadata and support email in `setup.py`.
- Overhauled README and Wiki documentation in both English and Persian.
- Refactored Qodana configuration to `.qodana/qodana.yml`.
- Cleaned up redundant files (`requirements.txt`, `test_encoding.py`).
- Optimized CI workflows for the new project structure.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* chore: clean up IDE artifacts and refine gitignore

- Removed `.idea/` directory.
- Refined `.gitignore` to include more specific exclusions for C compiled artifacts, IDE settings, and Qodana caches.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: correct qodana workflow args and update linter version

- Updated `qodana-ci.yml` to use `--yaml-name` instead of `-c` and upgraded action version to `v2024.3`.
- Ensured all documentation and metadata are finalized.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve Qodana YAML unmarshal error and optimize config

- Fixed `qodana.yml` by quoting boolean values in `properties` to satisfy the `map[string]string` constraint.
- Refined `exclude` section to use a standard format.
- Updated `qodana-ci.yml` to symlink the config to the root for better compatibility with the Qodana action.
- Verified all tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* feat: automate pypi publishing on push to main

- Updated `publish-to-pypi.yml` to trigger automatically on push to `main`.
- Added twine check step for package distribution validation.
- Upgraded checkout and setup-python actions to latest versions.
- Finalized professional configuration for release.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve qodana configuration issues and finalize release

- Refactored `qodana.yaml` to use the correct `linter` key and hidden directory.
- Updated `qodana-ci.yml` to point to the new configuration location.
- Verified all tests pass.
- Cleaned up .idea and refined .gitignore.
- Finalized professional documentation and wiki.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: resolve Qodana CI failures and schema errors

- Updated `qodana.yaml` to use the correct `linter` key and Community image.
- Quoted boolean values in `properties` to satisfy the map[string]string constraint.
- Updated `qodana-ci.yml` to copy the configuration file to the root during analysis, ensuring the scan finds it.
- Verified project integrity with all 76 tests passing.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* fix: optimize qodana config for community edition

- Removed redundant `bootstrap` command from `qodana.yaml`.
- Set linter to `jetbrains/qodana-python-community:latest` for compatibility with the free version.
- Simplified configuration properties.
- Verified all tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* chore: clean up redundant test data and verify encoding parity

- Removed `tests/corpus.json` as requested.
- Verified that the visual encoding logic (parentheses and alphanumeric sequences) correctly matches legacy expectations.
- Confirmed all 76 tests pass.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

* feat: implement visual order reversal for Persian text

- Updated `encode` to produce visual RTL byte sequences as requested (e.g., "سلام" results in `f4 91 f3 a8`).
- Updated `decode` to correctly handle visual RTL sequences and return logical Unicode.
- Improved `ReverseAlphaNumeric` to accurately handle bi-directional chunks (English, numbers, symbols).
- Ensured parity between Python and C implementations.
- Updated all tests to reflect the visual ordering requirement.

Co-authored-by: tahatehran <79411820+tahatehran@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @tahatehran, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant architectural overhaul to the iran-encoding library, transforming it into a self-contained, high-performance solution for Iran System character encoding. By eliminating external dependencies and directly porting the legacy C logic into a pure Python core, the library gains enhanced reliability and efficiency. The addition of an optional C extension and intelligent locale detection further refines its capabilities, ensuring accurate and context-aware processing of mixed Persian and English text. This update represents a substantial step towards a more robust and professionally maintained encoding tool.

Highlights

  • Dependency Removal and Pure Python Core: The library now operates without external dependencies like arabic_reshaper and python-bidi. The core Iran System C logic has been directly ported into a new pure Python module (iran_encoding/core.py), enhancing stability and control.
  • Optional C Extension for Performance: An optional C extension (iran_system.c) has been integrated, providing a performance-optimized backend for encoding/decoding. A new build_c_extension.py script automates its compilation across different operating systems.
  • Intelligent Locale Detection and Number Handling: A detect_locale function has been introduced to automatically identify Persian or English text. This enables smart number handling, converting to Iran System digits in Persian contexts and normalizing to ASCII in English contexts.
  • Comprehensive Testing and Documentation: Extensive new unit tests have been added (test_exact_behavior.py, test_iran_system_v1.py, and updates to existing tests) to ensure the new implementation's correctness. Comprehensive documentation in both English and Farsi (README.fa.md, wiki/) has also been added.
  • Project Modernization and Streamlining: The project's packaging metadata (setup.py) has been updated for a major version bump to 1.1.0, including improved classifiers, keywords, and project URLs. The command-line interface (cli.py) has been streamlined by removing WebSocket-related commands.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (5)
    • .github/workflows/ci.yml
    • .github/workflows/publish-to-pypi.yml
    • .github/workflows/python-package-conda.yml
    • .github/workflows/python-publish.yml
    • .github/workflows/qodana-ci.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

این یک بازسازی بسیار چشمگیر و جامع از کتابخانه است. حذف وابستگی‌های خارجی مانند arabic_reshaper و python-bidi و جایگزینی آن‌ها با یک هسته پایتون خالص که از منطق اصلی C پورت شده، گامی بزرگ در جهت بهبود قابلیت نگهداری و پایداری است. افزودن یک افزونه C اختیاری، مجموعه تست‌های گسترده و مستندات دو زبانه (انگلیسی و فارسی) کاری عالی است.

من چند مورد حیاتی در پیاده‌سازی C در رابطه با مدیریت بافر پیدا کرده‌ام که می‌تواند منجر به آسیب‌پذیری‌های امنیتی و از دست رفتن داده‌ها شود. همچنین پیشنهادی برای بهبود بیشتر عملکرد C wrapper ارائه کرده‌ام.

پس از رفع این موارد، این کتابخانه بسیار قوی و حرفه‌ای خواهد بود. کارتان عالی بود!

return unicodeChar;
// Final reversal for visual RTL
if (reverseAlphaNumericFlag) {
unsigned char finalReverse[2048];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

در تابع UnicodeToIransystem، بافر finalReverse با اندازه ثابت 2048 روی استک تعریف شده است. اگر طول رشته ورودی (len) بیشتر یا مساوی 2048 باشد، حلقه‌های بعدی باعث سرریز بافر (Stack-based Buffer Overflow) می‌شوند. این یک آسیب‌پذیری امنیتی جدی است که می‌تواند منجر به کرش برنامه یا اجرای کد مخرب شود.

برای رفع این مشکل، پیشنهاد می‌کنم حافظه را به صورت پویا روی هیپ با استفاده از malloc تخصیص دهید و پس از استفاده با free آن را آزاد کنید.

        unsigned char *finalReverse = malloc(len);
        if (finalReverse == NULL) { /* Handle allocation failure */ return; }
        for (byteCount = 0; byteCount < len; byteCount++) {
            finalReverse[byteCount] = iransystemString[len - 1 - byteCount];
        }
        memcpy(iransystemString, finalReverse, len);
        free(finalReverse);

Comment on lines +161 to +164
unsigned char reversed[2048];
unsigned char logical[2048];

strcatf(inString," ");
len=strlen(inString);
for(byteCount=0; byteCount<len; byteCount++){
if(inString[byteCount]<80){
if((byteCount-numberPosition)>1){
for(numberCount=numberPosition; numberCount<byteCount; numberCount++){
outString[numberCount]=inString[byteCount-(numberCount-numberPosition)-1];
}
}
numberPosition=byteCount+1;
outString[byteCount]=inString[byteCount];
if (len >= 2048) len = 2047;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

در تابع IransystemToUnicode، بافرهای reversed و logical با اندازه ثابت 2048 روی استک تعریف شده‌اند. خط if (len >= 2048) len = 2047; از سرریز بافر جلوگیری می‌کند، اما این کار با کوتاه کردن رشته ورودی انجام می‌شود که منجر به از دست رفتن داده (Data Loss) برای رشته‌های طولانی‌تر از ۲۰۴۷ کاراکتر می‌شود. این یک باگ جدی است.

برای رفع این مشکل، پیشنهاد می‌کنم برای این بافرها از تخصیص حافظه پویا (malloc) استفاده کنید تا رشته‌ها با هر طولی پشتیبانی شوند و در انتهای تابع حافظه را با free آزاد کنید.

Comment on lines +94 to +96
script_bytes = bytearray()
for char in unicode_str:
script_bytes.append(C_LIB.UnicodeToPersianScript(ord(char)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

در تابع unicode_to_iransystem_c، برای تبدیل هر کاراکتر یونیکد به Persian Script، یک حلقه پایتون اجرا می‌شود که تابع C UnicodeToPersianScript را فراخوانی می‌کند. این فراخوانی‌های مکرر از پایتون به C برای هر کاراکتر، برای رشته‌های طولانی بهینه نیست و باعث افت کارایی می‌شود.

برای بهبود عملکرد، پیشنهاد می‌کنم یک تابع جدید در C بنویسید که کل رشته را به عنوان ورودی دریافت کرده و script_bytes را در یک فراخوانی تولید کند. به این ترتیب از سربار حلقه‌ی پایتون جلوگیری می‌شود. این رویکرد برای تابع iransystem_to_unicode_c نیز قابل استفاده است.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants