Review Blender ID addon #48024

Closed
opened 2016-04-01 11:13:40 +02:00 by Sybren A. Stüvel · 13 comments

Hey Campbell,

Can you review the Blender ID addon for inclusion in master? The README.md should contain everything needed to build, install and use the addon. I figured that to include the addon in master, we'd build it with python setup.py bdist and then unzip the resulting zip file into Blender's addon dir.

This addon is used by the Blender Cloud addon, which we'll offer for review soon too.

Thanks!

Hey Campbell, Can you review the [Blender ID addon](https://developer.blender.org/diffusion/BIA/) for inclusion in master? The README.md should contain everything needed to build, install and use the addon. I figured that to include the addon in master, we'd build it with `python setup.py bdist` and then unzip the resulting zip file into Blender's addon dir. This addon is used by the [Blender Cloud addon](https://developer.blender.org/diffusion/BCA/), which we'll offer for review soon too. Thanks!
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Campbell Barton was assigned by Sybren A. Stüvel 2016-04-01 11:13:40 +02:00
Author
Owner

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

Added subscriber: @brita

Added subscriber: @brita

Initial review:

  • imports should be moved inline (especially heavy modules like requests), so its not slowing down startup:

  • files shouldn't be created when loading the module, better do this on register instead. profiles_path = bpy.utils.user_resource('CONFIG', "blender_id", create=True)

  • Suggest to use __all__ to all py files to show whats meant for use outside the modules own code.

  • Probably you prefer to keep this as-is, but did you consider using a single operator for BlenderIdLogin, BlenderIdValidate, BlenderIdLogout?... if there are 2+ more similar operators likely to be added which also do a single operation. They could be split into regular functions (so code remains separated). Then a single operator can call any of them based on a single enum property.

  • Would be nice to have a template addon that uses this, some hello-world single file example.

Initial review: - imports should be moved inline (especially heavy modules like requests), so its not slowing down startup: - files shouldn't be created when loading the module, better do this on register instead. `profiles_path = bpy.utils.user_resource('CONFIG', "blender_id", create=True)` - Suggest to use `__all__` to all py files to show whats meant for use outside the modules own code. - Probably you prefer to keep this as-is, but did you consider using a single operator for `BlenderIdLogin`, `BlenderIdValidate`, `BlenderIdLogout`?... if there are 2+ more similar operators likely to be added which also do a single operation. They could be split into regular functions (so code remains separated). Then a single operator can call any of them based on a single enum property. - Would be nice to have a template addon that uses this, some hello-world single file example.
Author
Owner

In #48024#367652, @ideasman42 wrote:

  • imports should be moved inline (especially heavy modules like requests), so its not slowing down startup:

I've moved requests and modules that are only used in one or two spots to inline. Commonly used modules (os, sys, json, bpy) have been kept at module level. I've also added support for reloading the addon. infrastructure/blender-id-addon@7721c3ff

  • files shouldn't be created when loading the module, better do this on register instead. profiles_path = bpy.utils.user_resource('CONFIG', "blender_id", create=True)

Done in infrastructure/blender-id-addon@fc139e5bc3

  • Suggest to use __all__ to all py files to show whats meant for use outside the modules own code.

Done in infrastructure/blender-id-addon@806f0c76

  • Probably you prefer to keep this as-is, but did you consider using a single operator for BlenderIdLogin, BlenderIdValidate, BlenderIdLogout?... if there are 2+ more similar operators likely to be added which also do a single operation. They could be split into regular functions (so code remains separated). Then a single operator can call any of them based on a single enum property.

We feel that the current approach (3 operators) is clearer for the user, as login/logout/validate are different actions, and not three variations of the same action.

  • Would be nice to have a template addon that uses this, some hello-world single file example.

We can add that to the README.md.

> In #48024#367652, @ideasman42 wrote: > - imports should be moved inline (especially heavy modules like requests), so its not slowing down startup: I've moved requests and modules that are only used in one or two spots to inline. Commonly used modules (os, sys, json, bpy) have been kept at module level. I've also added support for reloading the addon. infrastructure/blender-id-addon@7721c3ff > - files shouldn't be created when loading the module, better do this on register instead. `profiles_path = bpy.utils.user_resource('CONFIG', "blender_id", create=True)` Done in infrastructure/blender-id-addon@fc139e5bc3 > - Suggest to use `__all__` to all py files to show whats meant for use outside the modules own code. Done in infrastructure/blender-id-addon@806f0c76 > - Probably you prefer to keep this as-is, but did you consider using a single operator for `BlenderIdLogin`, `BlenderIdValidate`, `BlenderIdLogout`?... if there are 2+ more similar operators likely to be added which also do a single operation. They could be split into regular functions (so code remains separated). Then a single operator can call any of them based on a single enum property. We feel that the current approach (3 operators) is clearer for the user, as login/logout/validate are different actions, and not three variations of the same action. > - Would be nice to have a template addon that uses this, some hello-world single file example. We can add that to the README.md.
Author
Owner

We're no longer using RNA to store authentication info; see infrastructure/blender-id-addon@4b43b5d53d

We're no longer using RNA to store authentication info; see infrastructure/blender-id-addon@4b43b5d53d

Great, some other points...

Regarding having 3x operations, its OK, just wanting to avoid having every single transaction with the server adding a new operator (in the case more are needed).
The point isn't so much that there is some fixed limit to the number of operators you should define, more that operators are intended for users, not so much for defining lower level API's.

Looking into this, the blender-cloud add-on isn't even calling the operators.
So perhaps these could be removed and kept as API's the Python module exposes.


There are also some minor changes I'd suggest, made a small patch. P345

Summary

  • Enforce utf-8 file io (which is json convention too), and not always assured to be default depending on the platform and Python env vars.
  • When there is a choice or it doesn't matter - use immutable data (tuples instead of lists).
  • Tweak style for property definitions (used all over existing code).

One other thing is this mixes single double quotes. Our existing convention is to use single for API identifiers/enums (what would be defines or enums in C/C++), and double-quotes for text content. No big deal but prefer this over mixing them randomly.

eg:

     blender_id_password = StringProperty(
            name="Password",
            default="",
            options={'HIDDEN', 'SKIP_SAVE'},
            subtype='PASSWORD',
            ) 
Great, some other points... Regarding having 3x operations, its OK, just wanting to avoid having every single transaction with the server adding a new operator (in the case more are needed). The point isn't so much that there is some fixed limit to the number of operators you should define, more that operators are intended for users, not so much for defining lower level API's. Looking into this, the blender-cloud add-on isn't even calling the operators. So perhaps these could be removed and kept as API's the Python module exposes. ---- There are also some minor changes I'd suggest, made a small patch. [P345](https://archive.blender.org/developer/P345.txt) Summary - Enforce utf-8 file io (which is json convention too), and not always assured to be default depending on the platform and Python env vars. - When there is a choice or it doesn't matter - use immutable data (tuples instead of lists). - Tweak style for property definitions (used all over existing code). One other thing is this mixes single double quotes. Our existing convention is to use single for API identifiers/enums *(what would be defines or enums in C/C++)*, and double-quotes for text content. No big deal but prefer this over mixing them randomly. eg: ``` blender_id_password = StringProperty( name="Password", default="", options={'HIDDEN', 'SKIP_SAVE'}, subtype='PASSWORD', ) ```
Author
Owner

In #48024#367894, @ideasman42 wrote:
Regarding having 3x operations, its OK, just wanting to avoid having every single transaction with the server adding a new operator (in the case more are needed).
The point isn't so much that there is some fixed limit to the number of operators you should define, more that operators are intended for users, not so much for defining lower level API's.

Looking into this, the blender-cloud add-on isn't even calling the operators.
So perhaps these could be removed and kept as API's the Python module exposes.

I don't really understand what you mean with "these could be removed and kept". The operators are needed for the GUI login/logout/verify buttons.

  • Enforce utf-8 file io (which is json convention too), and not always assured to be default depending on the platform and Python env vars.

Good.

  • When there is a choice or it doesn't matter - use immutable data (tuples instead of lists).

Sure.

  • Tweak style for property definitions (used all over existing code).

This one is a bit annoying. All over the existing code PEP8 is declared at the top, which states "Hanging indents should add a level", and not two levels. PyCharm, the editor both Francesco and I use, has functionality for automatically formatting a file according to PEP8, which we use a lot. What is the reason that for RNA properties PEP8 is not followed?

One other thing is this mixes single double quotes. Our existing convention is to use single for API identifiers/enums (what would be defines or enums in C/C++), and double-quotes for text content. No big deal but prefer this over mixing them randomly.

I'm not a fan of adding semantics to the different quote styles. I do agree that consistency is nice, so I'll change them to single quotes, unless a single quote is part of the quoted string. This is also the behaviour of Python itself when printing repr(string), and consistent with PEP8.

> In #48024#367894, @ideasman42 wrote: > Regarding having 3x operations, its OK, just wanting to avoid having every single transaction with the server adding a new operator (in the case more are needed). > The point isn't so much that there is some fixed limit to the number of operators you should define, more that operators are intended for users, not so much for defining lower level API's. > > Looking into this, the blender-cloud add-on isn't even calling the operators. > So perhaps these could be removed and kept as API's the Python module exposes. I don't really understand what you mean with "these could be removed and kept". The operators are needed for the GUI login/logout/verify buttons. > - Enforce utf-8 file io (which is json convention too), and not always assured to be default depending on the platform and Python env vars. Good. > - When there is a choice or it doesn't matter - use immutable data (tuples instead of lists). Sure. > - Tweak style for property definitions (used all over existing code). This one is a bit annoying. All over the existing code PEP8 is declared at the top, which states "Hanging indents should add a level", and not two levels. PyCharm, the editor both Francesco and I use, has functionality for automatically formatting a file according to PEP8, which we use a lot. What is the reason that for RNA properties PEP8 is not followed? > One other thing is this mixes single double quotes. Our existing convention is to use single for API identifiers/enums *(what would be defines or enums in C/C++)*, and double-quotes for text content. No big deal but prefer this over mixing them randomly. I'm not a fan of adding semantics to the different quote styles. I do agree that consistency is nice, so I'll change them to single quotes, unless a single quote is part of the quoted string. This is also the behaviour of Python itself when printing repr(string), and consistent with PEP8.

Quick reply to some of these issues...

Grepped Py source for blender-cloud for "\.logout" & _OT_logout and didn't see any results. if they're needed, fine to keep of course.

Regarding "Hanging indents should add a level", this is indeed annoying. Note that when the code was written none of the error checkers reported on this (pep8/flake8/pyflakes/pylint ~ one of these is newer and wasn't around at the time but cant recall which :)).
The warnings were made more strict later (and quieting them would cause a lot of minor changes all over).
Having said that, checked the changes in my patch and they aren't causing these warnings for flake8.

So fine to leave as-is, just noting on my own preference/conventions, which in this case afaics don't conflict with pep8.

Quick reply to some of these issues... Grepped Py source for blender-cloud for `"\.logout"` & `_OT_logout` and didn't see any results. if they're needed, fine to keep of course. Regarding `"Hanging indents should add a level"`, this is indeed annoying. Note that when the code was written none of the error checkers reported on this (pep8/flake8/pyflakes/pylint ~ *one of these is newer and wasn't around at the time but cant recall which :)*). The warnings were made more strict later (and quieting them would cause a lot of minor changes all over). Having said that, checked the changes in my patch and they aren't causing these warnings for flake8. So fine to leave as-is, just noting on my own preference/conventions, which in this case afaics don't conflict with pep8.

Added subscriber: @fsiddi

Added subscriber: @fsiddi

Hi there @ideasman42!

We would like to proceed with the inclusion of the add-on as "official" in the upcoming Blender release. As originally requested, there is now a very clear use-case for it.

Let us know if there is anything else we can do.

Hi there @ideasman42! We would like to proceed with the inclusion of the add-on as "official" in the upcoming Blender release. As originally requested, there is now a [very clear use-case ](https://cloud.blender.org/services) for it. Let us know if there is anything else we can do.

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Add-on has been merged!

Add-on has been merged!
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: infrastructure/blender-id#48024
No description provided.