easyPythonpi icon indicating copy to clipboard operation
easyPythonpi copied to clipboard

Fix dependency declaration in setup.py

Open calchiwo opened this issue 11 months ago • 10 comments

  • Removed environment dependent dependency checks.
  • Declared runtime dependencies explicitly using install_requires.
  • Removed deprecated setup_requires usage.

This improves installation reliability and aligns with Python packaging best practices.

Summary by Sourcery

Declare runtime dependencies explicitly in setup.py and simplify version retrieval logic by assuming the requests library is available.

Bug Fixes:

  • Ensure the requests dependency is always installed at runtime by listing it unconditionally in install_requires instead of relying on environment checks and setup_requires.

Enhancements:

  • Remove deprecated setup_requires usage and environment-dependent dependency handling to align with current Python packaging best practices.

Build:

  • Update setup.py dependency declarations to use a fixed install_requires list for numpy and requests.

calchiwo avatar Dec 24 '25 14:12 calchiwo

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Reworks setup.py dependency handling to declare requests as a hard runtime dependency, remove environment-dependent logic and deprecated setup_requires usage, and simplify PyPI version lookup.

Sequence diagram for package installation with explicit requests dependency

sequenceDiagram
    actor Developer
    participant pip
    participant setup_py
    participant requests
    participant PyPI

    Developer->>pip: pip install easyPythonpi
    pip->>setup_py: Evaluate install_requires
    setup_py-->>pip: numpy>=1.19.5, requests>=2.25.1
    pip->>pip: Resolve and install dependencies
    pip->>requests: Install requests
    pip->>setup_py: Run setup and get version
    setup_py->>requests: get https://pypi.org/pypi/easyPythonpi/json
    requests->>PyPI: HTTP GET package metadata
    PyPI-->>requests: JSON version data
    requests-->>setup_py: Parsed response
    setup_py-->>pip: Package version from PyPI
    pip-->>Developer: Installation complete

Flow diagram for dependency handling in setup.py before and after change

flowchart TD
    subgraph Before_change
        B1[Check environment for requests_installed]
        B1 -->|requests_installed is False| B2[install_requires includes numpy and requests]
        B1 -->|requests_installed is True| B3[install_requires includes only numpy]
        B2 --> B4[setup_requires includes requests]
        B3 --> B4
        B4 --> B5[Call get_pypi_version]
        B5 --> B6[If requests not installed, return default version]
    end

    subgraph After_change
        A1[install_requires includes numpy and requests unconditionally]
        A1 --> A2[pip installs numpy and requests]
        A2 --> A3[Call get_pypi_version]
        A3 --> A4[Use requests to fetch version from PyPI]
    end

File-Level Changes

Change Details Files
Simplify PyPI version resolution by assuming requests is always available.
  • Removed conditional fallback in get_pypi_version that handled missing requests by returning a default version.
  • Kept the network request to PyPI unchanged, now relying on requests being installed via install_requires.
setup.py
Make requests a direct runtime dependency and remove deprecated/conditional dependency mechanisms.
  • Replaced environment-dependent install_requires construction with a static list including both numpy and requests.
  • Removed setup_requires usage in favor of explicit install_requires-only dependency declaration.
setup.py

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

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Dec 24 '25 14:12 sourcery-ai[bot]

@sourcery-ai ai review

extinctsion avatar Dec 24 '25 20:12 extinctsion

Sure! I'm generating a new review now.

sourcery-ai[bot] avatar Dec 24 '25 20:12 sourcery-ai[bot]

@calchiwo pls check it's failing the tests and check the feedback from ai. I hope this will help you in resolving the issues

extinctsion avatar Dec 24 '25 20:12 extinctsion

Hey @extinctsion, I've posted a new review for you!

sourcery-ai[bot] avatar Dec 24 '25 20:12 sourcery-ai[bot]

@extinctsion fixed. i've removed setup-time network calls + dynamic versioning from setup.py. switched to static version so installs/tests don’t break in offline or CI envs. should be good now.

calchiwo avatar Jan 07 '26 15:01 calchiwo

@calchiwo the test cases are failing. Pls see why.

extinctsion avatar Jan 07 '26 16:01 extinctsion

@extinctsion found the issue. tests import methods.* as a top-level module, but it lives under easyPythonpi.methods. imports break in a clean env. i can fix the test imports if you want me to.

calchiwo avatar Jan 07 '26 17:01 calchiwo

Sure. You can create an issue and raise a PR against it

extinctsion avatar Jan 08 '26 11:01 extinctsion