Skip to content

Desloppify codebase#338

Merged
vinitkumar merged 9 commits into
masterfrom
desloppify-codebase
Jul 13, 2026
Merged

Desloppify codebase#338
vinitkumar merged 9 commits into
masterfrom
desloppify-codebase

Conversation

@vinitkumar

@vinitkumar vinitkumar commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary by Sourcery

Simplify ID generation, deduplicate benchmark helpers, and clean up tests and config.

New Features:

  • Introduce a shared benchmark_utils module providing ANSI color definitions, random string generation, and time formatting used across all benchmark scripts.

Bug Fixes:

  • Fix Rust backend adapter usage by directly referencing the module-level rust_dicttoxml function, ensuring backend selection works correctly.

Enhancements:

  • Simplify get_unique_id to delegate directly to make_id without maintaining an unused local ID list.
  • Refactor backend_selector.has_special_keys to use concise any-based iteration for dictionaries and lists.
  • Allow read_input to accept already-constructed CLIConversionOptions alongside argparse namespaces, and reuse parsed options in the CLI main flow.

Build:

  • Remove obsolete bumpversion, wheel, alias, and Ty configuration from setup.cfg to streamline project configuration.

Tests:

  • Remove unused and overly detailed tests around get_unique_id that depended on specific ID formats, and clean up unused TYPE_CHECKING imports and fixtures in test modules.

Chores:

  • Extract duplicated benchmark helper functions (colors, random string, time formatting) into a single shared module and update all benchmark scripts to use it.
  • Trim unused imports from tests and benchmark scripts to reduce clutter.

@sourcery-ai

sourcery-ai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refactors and de-duplicates utility logic across benchmarks, simplifies dicttoxml internals and backend selection, and removes unused/testing-only code to clean up the codebase while keeping behavior consistent.

Sequence diagram for CLI read_input and convert flow

sequenceDiagram
    participant main
    participant argparse_ArgumentParser as argparseArgumentParser
    participant CLIConversionOptions
    participant _APP

    main->>argparse_ArgumentParser: create_parser()
    main->>argparse_ArgumentParser: parse_args(argv)
    argparse_ArgumentParser-->>main: args
    main->>CLIConversionOptions: from_namespace(args)
    CLIConversionOptions-->>main: options

    main->>main: read_input(options)
    main->>_APP: read_input(options)
    _APP-->>main: data

    main->>_APP: convert(data, options)
    _APP-->>main: xml_output
    main->>main: write_output(xml_output, options.output)
Loading

File-Level Changes

Change Details Files
Centralize shared benchmark helpers into a single module and update all benchmark scripts to use it.
  • Introduce benchmark_utils.py providing Colors, colorize, random_string, and format_time helpers.
  • Remove inline definitions of color/formatting helpers and random_string from individual benchmark scripts.
  • Replace local imports (random, string, etc.) and usages with imports from benchmark_utils across benchmark.py, benchmark_multi_python.py, benchmark_all.py, and benchmark_rust.py.
benchmark_utils.py
benchmark.py
benchmark_multi_python.py
benchmark_all.py
benchmark_rust.py
Simplify dicttoxml unique ID generation and remove unused logging.
  • Remove LOG logger setup and associated logging import from dicttoxml.py.
  • Replace get_unique_id’s list-and-loop based de-duplication with a direct call to make_id, simplifying the function and its semantics.
  • Update docstring wording of get_unique_id to reflect non-uniqueness guarantees.
json2xml/dicttoxml.py
tests/test_missing_coverage.py
Optimize backend selection for dicttoxml_fast by reusing a shared selector instance and simplifying the Rust adapter.
  • Remove rust_dicttoxml attribute from _RustBackendAdapter and switch to using module-level _rust_dicttoxml directly in can_handle and render.
  • Introduce a module-level _BACKEND_SELECTOR combining Rust and Python adapters.
  • Update dicttoxml_fast.dicttoxml to reuse _BACKEND_SELECTOR instead of creating a new BackendSelector per call.
json2xml/dicttoxml_fast.py
Streamline backend selection heuristics by using more concise, functional-style checks.
  • Refactor has_special_keys to use any(...) on dict items, combining key pattern checks and recursive calls into a single expression.
  • Refactor list handling in has_special_keys to use any(...) over list items, removing explicit loops while preserving behavior.
json2xml/backend_selector.py
Make CLI input reading accept both argparse.Namespace and CLIConversionOptions, reducing coupling and minor duplication.
  • Broaden read_input’s parameter type to accept argparse.Namespace
CLIConversionOptions and adapt initialization accordingly.
  • Compute CLIConversionOptions once in main, pass options to read_input, and reuse options for convert/write_output paths.
  • Slightly rearrange main error-handling flow to work with the new read_input signature without changing behavior.
  • Remove unused imports, types, configuration stanzas, and dead tests to desloppify the test suite and setup configuration.
    • Delete tests for get_unique_id that rely on the old uniqueness semantics from test_missing_coverage.py.
    • Remove unused imports (MagicMock, pytest, numbers, TYPE_CHECKING-related type-only imports, json) from several test modules.
    • Strip obsolete bumpversion, wheel, aliases, and tool.ty sections from setup.cfg that are no longer used.
    tests/test_missing_coverage.py
    tests/test_dict2xml.py
    tests/test_utils.py
    tests/test_json2xml.py
    setup.cfg

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    @sourcery-ai sourcery-ai Bot left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Hey - I've reviewed your changes and they look great!


    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    @codecov

    codecov Bot commented Jul 13, 2026

    Copy link
    Copy Markdown

    Codecov Report

    ✅ All modified and coverable lines are covered by tests.
    ✅ Project coverage is 100.00%. Comparing base (ea80fc6) to head (6a2ddfb).

    Additional details and impacted files
    @@            Coverage Diff            @@
    ##            master      #338   +/-   ##
    =========================================
      Coverage   100.00%   100.00%           
    =========================================
      Files            7         7           
      Lines          730       714   -16     
    =========================================
    - Hits           730       714   -16     
    Flag Coverage Δ
    unittests 100.00% <100.00%> (ø)

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Harness.
    📢 Have feedback on the report? Share it here.

    @vinitkumar vinitkumar merged commit 84eedb5 into master Jul 13, 2026
    61 checks passed
    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.

    1 participant