python3 support

Issue #7 resolved
Konrad Mohrfeldt created an issue

hi,

I’m a new vmm user and very happy with it so… thank you for creating it :).

are you planning to support python3 with vmm with the EOL of python2 coming closer? and would you accept pull-requests that implement such a change?

my personal motivation for the question: I’m switching from postfixadmin and got used to delegating mailbox/alias domain control to other people, if I only do mail-hosting for them. so i would like to have some kind of rest api for vmm. I’d do this myself but don’t want to write any code in python2 anymore. if vmm would support python3 I’ll probably use the python package to implement the rest api (as a separate package) and a frontend on top of it. best-case-scenario: we’d work this out before the debian buster freeze :).

any thoughts?

Comments (12)

  1. Pascal Volk repo owner

    Hi Konrad,

    the 0.7.x branch is py3-ready: https://bitbucket.org/pvo/vmm/src/v0.7.x/vmm At least there was no problem at 2014-06-09. :-) (Also no database changes so far.)

    The idea of delegating domains to different users/owners isn't new, but it's also not written to the TODO file. (This would require a new table.)

    There a currently no plans for REST-related code.

    The main problem: I have to find the way back to (Python) programming.

    Regards,

    Pascal

  2. Konrad Mohrfeldt reporter

    wonderful. i should’ve looked into the other branches. is there anything holding you back from merging the 0.7.x branch besides a lack of time? i’ll gladly take a look at it.

    concerning rest: I think vmm is fine as it is. in fact i guess that the rest api would be perfect as a separate package that just imports vmm so vmm itself doesn’t need to have any additional dependencies like flask. the only thing that i would look into is if any of the current code is tightly coupled to cli use. other than that vmm seems to be good at what it does :).

    concerning owners: do you think that domain owners would be a useful concept on the cli? it strikes me as something I’d want when having a web frontend but not on the cli.

    anyway. i will look into the python3 branch and will try to work out a little proof-of-concept in the coming week.

  3. Konrad Mohrfeldt reporter

    ok. I’ve started working on vmm-rest 😊.

    I’ve found a few issues while working with vmm as a library, but concerning python3-support or general cleanup I’d only fix a few things:

    • PEP8 compliance
    • quote usage (mixed use of single vs double quotes)
    • string interpolations for type conversions (things like foo = '%s' % some_int instead of foo = str(some_int))
    • order of *args and **kwargs in relation to normal arguments and keyword arguments (things like def domain_services(self, domainname, force=False, *services): pass instead of def domain_services(self, domainname, *services, force=False): pass)
    • modification of builtins module

    There are a some other issues I’d like to propose changes for, that are not directly tied to python3-support but to vmm being usable as a library. I’ll just create pull-requests for these if that’s ok for you:

    • creating a privileged-operations helper that takes care of executing root-only stuff like os.chown in order to remove the requirement of being root when running vmm
    • adding domain-ownership management (if you have wishes for that, shoot)

    That’s about it, though I’m sure I forgot something.

  4. Antonio Huete Jimenez

    Are there any plans to move forward with 0.7.x and make a release, perhaps also update http://vmm.localdomain.org/ (ie. the git repo does not point to bitbucket, etc) ?

    Also I was thinking maybe call out for maintainers ?

  5. Konrad Mohrfeldt reporter

    I’m still interested in that as well. I use vmm and would be very annoyed if it vanishes from Debian bullseye next year, because it still requires Python2. I’d love to see the REST API, but that is all future talk. IMHO we should just rigorously convert the codebase to Python3, drop Python2 support and pipe it all trough the black code formatter and be happy ☺.

    I’ve been doing a lot of Python3 development but next to none in Python2, so I would be happy to help with the transition if we drop the latter.

  6. Konrad Mohrfeldt reporter

    I have started to work on vmm based on the work in the v0.7.x branch. I have moved my source to GitHub as I’m not that comfortable with mercurial, but in case @pvo get’s back to us, I can provide them as patches. My goals are:

    • to further improve python3 support (and make use of its features)
    • make it easier to contribute code to it by adding lint rules and tests
    • refactor vmm into a non-root helper and a cli library

    I have:

    • formatted the code with black
    • renamed the package to vmm (that one might be cause a stir, PEP8 recommends “short, all-lowercase names” so I went all-in)
    • fixed flake8 errors
    • reworked some of the SQL statements and SQL query generation (I found a few instances where string formatting was used for inserting query arguments)

    The only remaining flake8 errors come from the use of the cfg_dget function, that is injected into global builtins scope. I’m not really sure yet what to do with it.

    Apart from that I would really like to refactor some of the code to use more recent python features like enums, argparse and some other stuff, but I don’t think I’ll find the time. If anyone want’s to help out, that’d be great.

  7. Antonio Huete Jimenez

    Excellent, thanks a lot. When the linter and the tests are in place I might take a look but my python-foo is not so great yet 🙂

  8. Pascal Volk repo owner

    Hi @Konrad Mohrfeldt ,

    in the meantime I've released vmm-0.7.0.
    I've migrated the repository from Mercurial to Git, because Bitbucket has dropped the support for hg.

    There will be no database ALTERnations in the 0.7 series. For the v0.8.x branch there will be some db modifications. So there could be a `domain_owner' table.

    PEP8: At some point I'll re-run the pep8 (and pylint) script. :-)
    Before that I'll do some other things: %s -> some py3-ish string formatting, relative imports, probably some clean-ups ...

    Yeah, I'm mixing quotations. It's easier to add a single quotation mark in a double quoted string.

    "Non-Root-Usage": There is sudo ... :-)
    I wasn't able to test how Dovecot will create missing directories and set proper permissions. I also don't know how doveadm will behave with non-root users.

    I'm not interested in MS-GitHub. So I've deleted my GitHub account years ago.

    The REST code could be placed in the vmm directory, besides the `cli' directory.

    There is no flake in my cli ;-)

    Regards,
    Pascal

  9. Pascal Volk repo owner

    Hi @Konrad Mohrfeldt , I guess this issue can be closed?
    Anything more specific described will qualify for a new issue/ticket.

    Regards,
    Pascal

  10. Log in to comment