RNA reference mapping: generate manual prefix based on current lang #104491

Closed
Damien Picard wants to merge 1 commits from pioverfour:dp_dynamic_manual_lang_mapping into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

The manual url prefix was generated statically, using the current
language from the preferences. This led to the rna_manual_reference
module having to be imported and deleted every time.

Instead, use a function to get the proper prefix each time, depending
on current language, even if it has changed.

This will allow us to use the proper manual language from the help
menu in a future commit.


The review was started in https://archive.blender.org/developer/D16263.

The manual url prefix was generated statically, using the current language from the preferences. This led to the `rna_manual_reference` module having to be imported and deleted every time. Instead, use a function to get the proper prefix each time, depending on current language, even if it has changed. This will allow us to use the proper manual language from the help menu in a future commit. ----- The review was started in https://archive.blender.org/developer/D16263.
Damien Picard reviewed 2023-02-09 00:30:44 +01:00
@ -1007,3 +1006,1 @@
# avoid storing in memory
del _sys.modules["rna_manual_reference"]
return ret
return (ref_mod.get_url_manual_prefix(), ref_mod.url_manual_mapping)
Author
Member

In the original review, Campbell wrote:

This change doesn't seem necessary, can't this be left as-is? (replacing ref_mod.url_manual_prefix with ref_mod.url_manual_prefix()). Why is it necessary to keep the module loaded?

I replied by quoting what Bastien wrote in D15766:

I do not understand that, makes no sense to me, it basically defeats the point of modules caching in python, by forcing re-importing the module on every call?

Unless the point here is that this module has to be reloaded every time, to regenerate the rna_manual_reference.LANG value?

I wanted to use the url_manual_prefix in another file for !104492, but Bastien requested this change, so I figured I might as well change the existing use at the same time. But it may well be that I misunderstood the intent behind unloading the module on each call.

In [the original review](https://archive.blender.org/developer/D16263), Campbell wrote: > This change doesn't seem necessary, can't this be left as-is? (replacing `ref_mod.url_manual_prefix` with `ref_mod.url_manual_prefix()`). Why is it necessary to keep the module loaded? I replied by quoting what Bastien wrote in [D15766](https://archive.blender.org/developer/differential/0015/0015766/index.html): > I do not understand that, makes no sense to me, it basically defeats the point of modules caching in python, by forcing re-importing the module on every call? > > Unless the point here is that this module has to be reloaded every time, to regenerate the rna_manual_reference.LANG value? I wanted to use the `url_manual_prefix` in another file for !104492, but Bastien requested this change, so I figured I might as well change the existing use at the same time. But it may well be that I misunderstood the intent behind unloading the module on each call.

In general avoid mixing in unrelated changes, it complicates review and means the reviewer needs to guess at why a change was made that isn't related to the patch description.

The intent was to avoid keeping a large mapping in memory unnecessarily.
Since this only runs when the user clicks on a manual link, I didn't see the overhead of loading the module each time to be a problem (it's cached as a *.pyc file so loading is fast). But it would be better to discuss this outside of this patches review.

Please remove these changes from the patch.

In general avoid mixing in unrelated changes, it complicates review and means the reviewer needs to guess at why a change was made that isn't related to the patch description. The intent was to avoid keeping a large mapping in memory unnecessarily. Since this only runs when the user clicks on a manual link, I didn't see the overhead of loading the module each time to be a problem (it's cached as a `*.pyc` file so loading is fast). But it would be better to discuss this outside of this patches review. Please remove these changes from the patch.
Author
Member

Thank you for the explanation :)

Thank you for the explanation :)

This kind of information should be included in comments, also - importing then deleting from sys.modules is not great, committed 9fd71d470e to improve the situation, also double checked performance isn't likely to be a problem.

This kind of information should be included in comments, also - importing then deleting from `sys.modules` is not great, committed 9fd71d470e5bebf12029acb770f3ab7620b418d3 to improve the situation, also double checked performance isn't likely to be a problem.
pioverfour marked this conversation as resolved
Damien Picard requested review from Campbell Barton 2023-02-09 00:31:18 +01:00
Damien Picard requested review from Aaron Carlisle 2023-02-09 00:31:18 +01:00
Campbell Barton requested changes 2023-02-09 00:47:51 +01:00
@ -36,0 +34,4 @@
if language == 'DEFAULT':
import os
language = os.getenv('LANG', '').split('.')[0]
return language_codes.get(language, 'en')

Double quotes for non-enums.

Double quotes for non-enums.
pioverfour marked this conversation as resolved
Damien Picard force-pushed dp_dynamic_manual_lang_mapping from 4ed638e55d to 6e480b9e17 2023-02-09 01:42:29 +01:00 Compare
Damien Picard requested review from Campbell Barton 2023-02-09 01:42:48 +01:00
Campbell Barton approved these changes 2023-02-09 03:56:50 +01:00
Campbell Barton requested changes 2023-02-09 04:03:10 +01:00
Campbell Barton left a comment
Owner

This patch in it's current form doesn't seem to do anything useful.

url_manual_prefix() needs to be made into a function, currently any script that imports this will still have a static variable.

This patch in it's current form doesn't seem to do anything useful. url_manual_prefix() needs to be made into a function, currently any script that imports this will still have a static variable.

After checking on D15766 & D16263, I'd propose an alternative change to this, !104494.

After checking on D15766 & D16263, I'd propose an alternative change to this, !104494.
Author
Member

See !104494 instead.

See !104494 instead.
Damien Picard closed this pull request 2023-02-09 19:36:07 +01:00
Damien Picard deleted branch dp_dynamic_manual_lang_mapping 2023-02-10 18:06:08 +01:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: blender/blender#104491
No description provided.