Skip to content

Module organization #10

Closed
Closed

Description

@ddemidov

One thing I don't like is how the module is organized. When I write

from ev3dev import *

I expect to be able to write d = Device(). But now, since ev3dev module (the top folder) has the ev3dev submodule (the ev3dev.py file) I have to do d = ev3dev.Device(). Normally if I wanted that, I would just import ev3dev instead.

So I think we should keep just the ev3dev.py at the top level and get rid of the ev3dev folder with __init__.py.

Activity

  1. rhempel commented on Oct 17, 2015

    @rhempel
    Member

    I'm not so sure about that - we run into namespace pollution risks - besides, once the ev3dev.Device or ev3dev.Motor is instantiated, the prefix is no longer an issue

  2. ddemidov commented on Oct 17, 2015

    @ddemidov
    MemberAuthor

    When I care about namespace pollution, I do

    import ev3dev
    m = ev3dev.Motor()

    And when I just want convenience, I do

    from ev3dev import *
    m = Motor()

    I think this is standard practice for python.

  3. rhempel commented on Oct 17, 2015

    @rhempel
    Member

    Ah, now I understand - so just pull ev3dev.py and __init__.py up from the ev3dev folder. Does this affect things if we submit to any other repositories ? Sorry for my ignorance on this topic

  4. ddemidov commented on Oct 17, 2015

    @ddemidov
    MemberAuthor

    I am not sure what you mean by other repositories. Something like PyPI to make the bindings installable through easy_install or pip? I think that would be fine.

  5. rhempel commented on Oct 17, 2015

    @rhempel
    Member

    Yes, that kind of repo - when we install from there, what does the directory structure look like?

  6. ddemidov commented on Oct 17, 2015

    @ddemidov
    MemberAuthor

    When we install it, it resides somewhere in dist-packages folder (as single ev3dev.py file). I've added a setup.py in #11, you can try to install the package system-wide with sudo python setup.py install.

  7. antonvh commented on Oct 18, 2015

    @antonvh
    Contributor

    This document explains how the module should be structured (it was ok, now it isn't anymore). http://peterdowns.com/posts/first-time-with-pypi.html

    If you want to use it in another project without updating pypi, you can use subtree . Then test, change, and cherry pick back into master.

    git filter-branch --prune-empty --subdirectory-filter ev3dev libonly

  8. antonvh commented on Oct 18, 2015

    @antonvh
    Contributor

    The new structure also breaks autogen for me. - I pulled the latest ev3dev-lang repo in the pure-python branch.

  9. ddemidov commented on Oct 18, 2015

    @ddemidov
    MemberAuthor

    autogen should be fixed with ev3dev/ev3dev-lang@07c14ef.

    Re module organization and pypi: the document you referenced describes rather complex project with many files in it. Since our bindings reside in single file, I think nothing prevents us from having flat structure.

  10. ddemidov commented on Oct 18, 2015

    @ddemidov
    MemberAuthor
  11. antonvh commented on Oct 18, 2015

    @antonvh
    Contributor

    I can work with that, but I thought @rhempel wanted to have separate files for convenience classes that are not generated. Like e.g. motors.py or sensors.py that contain non-lego sensors, advanced PID control algorythms etc... Then it's nice to have them in a folder.

    You can also symlink a subdirectory of the repo into your mindstorms project btw. easier than symlinking.

  12. rhempel commented on Oct 18, 2015

    @rhempel
    Member

    There's a point at which PID control and other helpers need to be managed and customized by users. For now, we have all the helper functions (except higher level motor) auto-generated and I'm basically happy with the library. @ddemidov made a good point about having the main ev3dev.py not being in a subdirectory. For now, let's move forward with what we've got, and see what shakes out.

  13. ddemidov commented on Oct 18, 2015

    @ddemidov
    MemberAuthor

    resolved by #11

  14. antonvh commented on Oct 20, 2015

    @antonvh
    Contributor

    Can we please move back to the directory? It is more future-proof. @ericpascual also made a compelling namespace argument.

  15. ddemidov commented on Oct 20, 2015

    @ddemidov
    MemberAuthor

    We can always do this if we outgrow single file.

  16. ericpascual commented on Oct 20, 2015

    @ericpascual

    BTW the out of the directory move broke setup.py process, which is still looking for an ev3dev package (and thus a directory). The "packages" directive should be replaced by "py_modules". But I guess that we are in a transitional state for the moment, and that such adjustments will have to be done when the situation will be stabilized.

  17. ddemidov commented on Oct 20, 2015

    @ddemidov
    MemberAuthor

    Thanks, I'll make a PR with the fix. Strange, but setup.py install worked
    for me as is.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions