mirror of
https://github.com/clearml/clearml-agent
synced 2025-03-13 15:08:44 +00:00
Add PackageCollectorRequirement to allow multiple entries of the same package
This commit is contained in:
parent
1afa3a3914
commit
259113c989
@ -90,7 +90,7 @@ from trains_agent.helper.process import (
|
|||||||
get_docker_id,
|
get_docker_id,
|
||||||
commit_docker, terminate_process,
|
commit_docker, terminate_process,
|
||||||
)
|
)
|
||||||
from trains_agent.helper.package.priority_req import PriorityPackageRequirement
|
from trains_agent.helper.package.priority_req import PriorityPackageRequirement, PackageCollectorRequirement
|
||||||
from trains_agent.helper.repo import clone_repository_cached, RepoInfo, VCS
|
from trains_agent.helper.repo import clone_repository_cached, RepoInfo, VCS
|
||||||
from trains_agent.helper.resource_monitor import ResourceMonitor
|
from trains_agent.helper.resource_monitor import ResourceMonitor
|
||||||
from trains_agent.helper.runtime_verification import check_runtime, print_uptime_properties
|
from trains_agent.helper.runtime_verification import check_runtime, print_uptime_properties
|
||||||
@ -322,6 +322,7 @@ class Worker(ServiceCommandSection):
|
|||||||
PriorityPackageRequirement,
|
PriorityPackageRequirement,
|
||||||
PostRequirement,
|
PostRequirement,
|
||||||
ExternalRequirements,
|
ExternalRequirements,
|
||||||
|
partial(PackageCollectorRequirement, collect_package=['trains']),
|
||||||
)
|
)
|
||||||
|
|
||||||
# poll queues every _polling_interval seconds
|
# poll queues every _polling_interval seconds
|
||||||
|
@ -38,3 +38,38 @@ class PriorityPackageRequirement(SimpleSubstitution):
|
|||||||
return Text('')
|
return Text('')
|
||||||
PackageManager.out_of_scope_install_package(str(req))
|
PackageManager.out_of_scope_install_package(str(req))
|
||||||
return Text(req)
|
return Text(req)
|
||||||
|
|
||||||
|
|
||||||
|
class PackageCollectorRequirement(SimpleSubstitution):
|
||||||
|
"""
|
||||||
|
This RequirementSubstitution class will allow you to have multiple instances of the same
|
||||||
|
package, it will output the last one (by order) to be actually used.
|
||||||
|
"""
|
||||||
|
name = tuple()
|
||||||
|
|
||||||
|
def __init__(self, session, collect_package):
|
||||||
|
super(PackageCollectorRequirement, self).__init__(session)
|
||||||
|
self._collect_packages = collect_package
|
||||||
|
self._last_req = None
|
||||||
|
|
||||||
|
def match(self, req):
|
||||||
|
# match package names
|
||||||
|
return req.name and (req.name.lower() in self.name or req.name.lower() in self._collect_packages)
|
||||||
|
|
||||||
|
def replace(self, req):
|
||||||
|
"""
|
||||||
|
Replace a requirement
|
||||||
|
:raises: ValueError if version is pre-release
|
||||||
|
"""
|
||||||
|
self._last_req = req.clone()
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def post_scan_add_req(self):
|
||||||
|
"""
|
||||||
|
Allows the RequirementSubstitution to add an extra line/requirements after
|
||||||
|
the initial requirements scan is completed.
|
||||||
|
Called only once per requirements.txt object
|
||||||
|
"""
|
||||||
|
last_req = self._last_req
|
||||||
|
self._last_req = None
|
||||||
|
return last_req
|
||||||
|
@ -338,6 +338,14 @@ class RequirementSubstitution(object):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def post_scan_add_req(self): # type: () -> Optional[MarkerRequirement]
|
||||||
|
"""
|
||||||
|
Allows the RequirementSubstitution to add an extra line/requirements after
|
||||||
|
the initial requirements scan is completed.
|
||||||
|
Called only once per requirements.txt object
|
||||||
|
"""
|
||||||
|
return None
|
||||||
|
|
||||||
def post_install(self, session):
|
def post_install(self, session):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -492,6 +500,14 @@ class RequirementsManager(object):
|
|||||||
)
|
)
|
||||||
if not conda:
|
if not conda:
|
||||||
result = map(self.translator.translate, result)
|
result = map(self.translator.translate, result)
|
||||||
|
|
||||||
|
result = list(result)
|
||||||
|
# add post scan add requirements call back
|
||||||
|
for h in self.handlers:
|
||||||
|
req = h.post_scan_add_req()
|
||||||
|
if req:
|
||||||
|
result.append(req.tostr())
|
||||||
|
|
||||||
return join_lines(result)
|
return join_lines(result)
|
||||||
|
|
||||||
def post_install(self, session):
|
def post_install(self, session):
|
||||||
|
Loading…
Reference in New Issue
Block a user