#12410 closed enhancement (fixed)
Add get_plugins_dir method to Environment class
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.11 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: |
|
||
Internal Changes: |
Description (last modified by )
The proposed change is a refactoring to replace the function trac.loader.get_plugins_dir
with the method trac.env.Environment.get_plugins_dir
.
Attachments (0)
Change History (11)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Description: | modified (diff) |
---|
comment:3 by , 9 years ago
API Changes: | modified (diff) |
---|
follow-up: 7 comment:5 by , 9 years ago
Sure.
I wonder how many times these methods are called, but now that you added a helper method, it might be a cheap optimization to memoize these calls, e.g.
def _get_path_to_dir(self, dir): """Retrieve and memoize normalized path to immediate subdir of self.path""" _dir = '_%s_dir' % dir if not hasattr(self, _dir): path = os.path.join(self.path, dir) setattr(self, _dir, os.path.normcase(os.path.realpath(path))) return getattr(self, _dir)
comment:6 by , 9 years ago
comment:7 by , 9 years ago
Replying to Christian Boos:
I wonder how many times these methods are called, but now that you added a helper method, it might be a cheap optimization to memoize these calls, e.g.
In general we seem to follow the undocumented pattern of using properties for short computations or those that can be cached, and get_
for lengthier computations, database access or methods that could raise an exception.
Therefore, for API consistency it might make sense to just deprecate the 4 methods and add lazily-evaluated properties templates_dir
, htdocs_dir
and plugins_dir
, rather than implementing lazy evaluation for the methods. It's unlikely many plugins access those methods anyway, so removing them in 1.3.1 shouldn't have a big impact.
comment:8 by , 9 years ago
Correction: Technically we only have to deprecate 3 methods since the 4th was just added.
comment:10 by , 9 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Proposed changes in log:rjollos.git:t12410.
I stuck with the existing naming convention even though I think these
get_*
methods that return paths should instead be lazily-evaluated properties.Should
realpath
andnormpath
be called in the similar methodsget_templates_dir
,get_htdocs_dir
,get_log_dir
andget_plugins_dir
? We could add a_get_path_to_dir
method: