Skip to content

Commit f6931f3

Browse files
committed
Changed plugins to be stateless (at least for the relevant user code); Configuration and conenctors given to plugins now exist with plugin initialization (and will probably not change, although they could); reworked parameter set for domains and activities to be of a consuming nature, which allows us to spot wrong user config params and report them (we do raise an exception); Removed unnecessary code; Cleanup preps for PR into main repo devel branch; protontypes#164
1 parent 377d6a8 commit f6931f3

File tree

8 files changed

+92
-138
lines changed

8 files changed

+92
-138
lines changed

libreselery/commandline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def _runCommand(args):
2929
# various APIs and servers to
3030
# allow data gathering
3131
selery.connect()
32+
33+
# initialize the CDE (Contribution Distribution Engine)
34+
# this also involves finding and
35+
# instantiating activity plugins
36+
selery.startEngine()
37+
3238
# let libreselery gather data
3339
# of all involved projects,
3440
# dependencies and contributors

libreselery/contribution_activity_plugins/git_file_contributors.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,12 @@ def initialize_(self, activity):
4747
bool: True if successfully initialized
4848
"""
4949
self.fileFilters = activity.applies_to
50-
return True
51-
52-
def onGlobalsUpdate_(self):
53-
"""
54-
Overload of abstract event method which signalizes the change of the global configuration
5550

56-
Parameters:
57-
None
58-
59-
Returns:
60-
None
61-
"""
51+
### get global configurations
6252
self.directory = self.getGlobals().directory
53+
return True
6354

64-
def gather_(self, cachedContributors=[]):
55+
def gather_(self):
6556
"""
6657
Overload of abstract method which is responsible for gathering
6758
contributor information and scoring contributors based on the action defined
@@ -294,14 +285,14 @@ def test():
294285
}
295286
### create an activity object
296287
activity = ContributionActivity(d)
288+
289+
### emulate some global information
290+
### which is used by the plugin to work properly
291+
globalCfg = LibreSeleryConfig({"directory": os.getcwd()})
297292
### initialize the action
298293
### which will in turn use this specific plugin
299294
### if configured correctly
300-
init = activity.initialize_()
301-
### emulate some global information
302-
### which is used by the plugin to work properly
303-
config = LibreSeleryConfig({"directory": os.getcwd()})
304-
activity.updateGlobals(config=config, connectors=None)
295+
init = activity.initialize_(globals=globalCfg)
305296
if init:
306297
### let us do our work
307298
contributors, scores = activity.gather_()

libreselery/contribution_activity_plugins/github_remote_contributors.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,46 +50,25 @@ def initialize_(self, activity):
5050
Returns:
5151
bool: True if successfully initialized
5252
"""
53+
### get some information about our activity
5354
init = True
5455
self.uniform_score = activity.readParam("uniform_score")
5556
self.min_contributions = activity.readParam("min_contributions", default=0)
5657
self.include_deps = activity.readParam("include_dependencies", default=False)
5758
init = False if not self.uniform_score or not self.min_contributions else True
58-
return init
59-
60-
def onGlobalsUpdate_(self):
61-
"""
62-
Overload of abstract event method which signalizes the change of the global configuration
63-
64-
Parameters:
65-
Non
66-
67-
Returns:
68-
None
69-
"""
7059
### get current project
7160
self.directory = self.getGlobals().directory
72-
### get special params
73-
###
74-
### TODO:
75-
### these config values should probably not come from globals()
76-
### but from activity (self.initialize_) instead
77-
### because they are not global anymore and instead
78-
### define this specific activity
61+
62+
### get global configurations
7963
self.include_main_repository = self.getGlobals().include_main_repository
8064

81-
### get current github connector
82-
###
83-
### TODO:
84-
### connectors are a dict atm, containing all possible
85-
### (preinitialized) connector objects. These can be
86-
### considered "work in progress" and will change slightly
87-
### as time goes on
65+
### get global github connector
8866
self.githubConnector = self.getConnectors().get(
8967
self.GITHUB_CONNECTOR_NAME, None
9068
)
69+
return init
9170

92-
def gather_(self, cachedContributors=[]):
71+
def gather_(self):
9372
"""
9473
Overload of abstract method which is responsible for gathering
9574
contributor information and scoring contributors based on the activity defined
@@ -223,24 +202,23 @@ def test():
223202
}
224203
### create an activity object
225204
activity = ContributionActivity(d)
226-
### initialize the activity
227-
### which will in turn use this specific plugin
228-
### if configured correctly
229-
init = activity.initialize_()
230205
### emulate some global information
231206
### which is used by the plugin to work properly
232207
test_grabEnvironmentVarsFromFile(
233208
os.path.join(os.environ["HOME"], ".libreselery/tokens.env")
234209
)
235210
myGithubToken = os.environ["GITHUB_TOKEN"]
236211
connectors = {"github": GithubConnector(myGithubToken)}
237-
config = LibreSeleryConfig(
212+
globalCfg = LibreSeleryConfig(
238213
{
239214
"directory": os.path.abspath(os.path.join(os.getcwd(), "..", "..")),
240215
"include_main_repository": True,
241216
}
242217
)
243-
activity.updateGlobals(config=config, connectors=connectors)
218+
### initialize the activity
219+
### which will in turn use this specific plugin
220+
### if configured correctly
221+
init = activity.initialize_(globals=globalCfg, connectors=connectors)
244222
if init:
245223
### let us do our work
246224
contributors, scores = activity.gather_()

libreselery/contribution_activity_plugins/hello_world_activity_plugin.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,12 @@ def initialize_(self, activity):
4747
"""
4848
self.log("INIT")
4949

50-
return True
51-
52-
def onGlobalsUpdate_(self):
53-
"""
54-
Overload of abstract event method which signalizes the change of the global configuration
55-
56-
Parameters:
57-
None
58-
59-
Returns:
60-
None
61-
"""
6250
### example
6351
self.someGlobalInformation = self.getGlobals().simulation
64-
pass
6552

66-
def gather_(self, cachedContributors=[]):
53+
return True
54+
55+
def gather_(self):
6756
"""
6857
Overload of abstract method which is responsible for gathering
6958
contributor information and scoring contributors based on the activity defined
@@ -111,14 +100,13 @@ def test():
111100
}
112101
### create an activity object
113102
activity = ContributionActivity(d)
103+
### emulate some global information
104+
### which is used by the plugin to work properly
105+
globalCfg = LibreSeleryConfig({"simulation": True})
114106
### initialize the action
115107
### which will in turn use this specific plugin
116108
### if configured correctly
117-
init = activity.initialize_()
118-
### emulate some global information
119-
### which is used by the plugin to work properly
120-
config = LibreSeleryConfig({"simulation": True})
121-
activity.updateGlobals(config=config, connectors=None)
109+
init = activity.initialize_(globals=globalCfg)
122110
### preparations done, lets do something
123111
if init:
124112
### let us do our work

libreselery/contribution_distribution_engine.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,20 @@
66

77

88
class ContributionDistributionEngine(object):
9-
def __init__(self, config):
9+
def __init__(self, config, connectors):
1010
super(ContributionDistributionEngine, self).__init__()
1111
###grab relevant entries from selery cfg
12-
self.domains = self._extractContributionDomains(config)
13-
### set our global config to the one given
14-
### these globals can be used by plugins and others
15-
self.updateGlobals(config=config)
12+
self.domains = self._extractContributionDomains(config, connectors)
1613

17-
def _extractContributionDomains(self, config):
14+
def _extractContributionDomains(self, config, connectors):
1815
### read the config and parse usable objects for each domain configured
1916
domains = []
2017
for domainDict in config.contribution_domains:
2118
domain = cdetypes.ContributionDomain(domainDict)
19+
domain.initialize_(config, connectors)
2220
domains.append(domain)
2321
return domains
2422

25-
def updateGlobals(self, config=None, connectors=None):
26-
for domain in self.domains:
27-
domain.updateGlobals(config=config, connectors=connectors)
28-
2923
def splitDictKeyVals(self, d):
3024
return cdetypes.splitDictKeyVals(d)
3125

0 commit comments

Comments
 (0)