Skip to content

Make all imports absolute #3764

Closed
Closed

Description

@alejoe91

As we discussed, we should make all imports absolute throughout the source code

Activity

  1. chrishalcrow commented on Mar 12, 2025

    @chrishalcrow
    Member

    Hello, turns out this is super easy with ruff. PEP8 and the default ruff and flake-8 rules allow for simple (same folder) relative imports, so that

    # This is considered ok
    from .benchmark_base import Benchmark, BenchmarkStudy
    # rather than
    from spikeinterface.benchmark.benchmark_base import Benchmark, BenchmarkStudy
    
    # This is considered confusing
    from ..preprocessing.astype import astype
    # and would be changed to
    from spikeinterface.preprocessing.astype import astype

    Note: we have 1279 same-level relative import and only 194 deeper-than-one-level.

    Should we keep the "simple" same-level relative imports? Opinions? @samuelgarcia @h-mayorquin @zm711 @JoeZiminski @yger ?

  2. alejoe91 commented on Mar 12, 2025

    @alejoe91
    MemberAuthor

    Mmm, not sure here. I would vote for all absolute, but I agree that same level imports are less confusing!

  3. zm711 commented on Mar 12, 2025

    @zm711
    Member

    I agree with Alessio, but my only thought is if we can convince Sam to allow us to use ruff (see my PR #3756 for how easy linting is to add and how quick it is), then I would use whatever default is convenient so that it is all done in the pre-commit/commit action. In that case I would sacrifice the full consistency in order to have the automaticity. :)

  4. chrishalcrow commented on Mar 12, 2025

    @chrishalcrow
    Member

    The Ruff pre-commit can handle both options with ease; the default is to allow for same-level relative imports.

  5. zm711 commented on Mar 12, 2025

    @zm711
    Member

    Okay that sounds like the best then to help new developers find their way around the library so I'm good with that. Thanks for playing around with it. I'm good with going all in on absolute then!

  6. h-mayorquin commented on Mar 12, 2025

    @h-mayorquin
    Contributor

    I am fine with same-level relative imports. I am +1 on whatever gets this through, both options are better than what we have for me.

  7. chrishalcrow commented on Mar 13, 2025

    @chrishalcrow
    Member

    Done in #3766

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

Metadata

Metadata

Assignees

Labels

packagingRelated to packaging/style

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions