Support clearing repository details in task.set_repo()

This commit is contained in:
allegroai 2023-12-07 16:31:51 +02:00
parent 82c28ba43b
commit 73e2ecf7fd
2 changed files with 39 additions and 26 deletions

View File

@ -2280,7 +2280,7 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
import pkg_resources import pkg_resources
except ImportError: except ImportError:
get_logger("task").warning( get_logger("task").warning(
"Requirement file %s skipped since pkg_resources is not installed" % package_name) "Requirement file `{}` skipped since pkg_resources is not installed".format(package_name))
else: else:
with Path(package_name).open() as requirements_txt: with Path(package_name).open() as requirements_txt:
for req in pkg_resources.parse_requirements(requirements_txt): for req in pkg_resources.parse_requirements(requirements_txt):

View File

@ -1553,53 +1553,66 @@ class Task(_Task):
raise Exception('Unsupported mutable type %s: no connect function found' % type(mutable).__name__) raise Exception('Unsupported mutable type %s: no connect function found' % type(mutable).__name__)
def set_packages(self, packages): def set_packages(self, packages):
# type: (Union[str, Sequence[str]]) -> () # type: (Union[str, Path, Sequence[str]]) -> ()
""" """
Manually specify a list of required packages or a local requirements.txt file. Manually specify a list of required packages or a local requirements.txt file.
When running remotely the call is ignored
When running remotely this call is ignored
:param packages: The list of packages or the path to the requirements.txt file. :param packages: The list of packages or the path to the requirements.txt file.
Example: ["tqdm>=2.1", "scikit-learn"] or "./requirements.txt"
Example: ["tqdm>=2.1", "scikit-learn"] or "./requirements.txt" or ""
Use an empty string (packages="") to clear the requirements section (remote execution will use
requirements.txt from the git repository if the file exists)
""" """
if not packages or running_remotely(): if running_remotely() or packages is None:
return return
self._wait_for_repo_detection(timeout=300.) self._wait_for_repo_detection(timeout=300.)
if not isinstance(packages, str) or not os.path.exists(packages):
# noinspection PyProtectedMember if packages and isinstance(packages, (str, Path)) and Path(packages).is_file():
self._update_requirements(packages) with open(Path(packages).as_posix(), "rt") as f:
return
with open(packages) as f:
# noinspection PyProtectedMember # noinspection PyProtectedMember
self._update_requirements([line.strip() for line in f.readlines()]) self._update_requirements([line.strip() for line in f.readlines()])
return
def set_repo(self, repo, branch=None, commit=None): # noinspection PyProtectedMember
# type: (str, Optional[str], Optional[str]) -> () self._update_requirements(packages or "")
def set_repo(self, repo=None, branch=None, commit=None):
# type: (Optional[str], Optional[str], Optional[str]) -> ()
""" """
Specify a repository to attach to the function. Specify a repository to attach to the function.
Allow users to execute the task inside the specified repository, enabling them to load modules/script Allow users to execute the task inside the specified repository, enabling them to load modules/script
from the repository. Notice the execution work directory will be the repository root folder. from the repository. Notice the execution work directory will be the repository root folder.
Supports both git repo url link, and local repository path (automatically converted into the remote Supports both git repo url link, and local repository path (automatically converted into the remote
git/commit as is currently checkout). git/commit as is currently checkout).
Example remote url: 'https://github.com/user/repo.git'. Example remote url: "https://github.com/user/repo.git".
Example local repo copy: './repo' -> will automatically store the remote Example local repo copy: "./repo" -> will automatically store the remote
repo url and commit ID based on the locally cloned copy. repo url and commit ID based on the locally cloned copy.
When executing remotely, this call will not override the repository data (it is ignored) When executing remotely, this call will not override the repository data (it is ignored)
:param repo: Remote URL for the repository to use, OR path to local copy of the git repository :param repo: Optional, remote URL for the repository to use, OR path to local copy of the git repository.
Example: 'https://github.com/allegroai/clearml.git' or '~/project/repo' Use an empty string to clear the repo.
:param branch: Optional, specify the remote repository branch (Ignored, if local repo path is used) Example: "https://github.com/allegroai/clearml.git" or "~/project/repo" or ""
:param commit: Optional, specify the repository commit ID (Ignored, if local repo path is used) :param branch: Optional, specify the remote repository branch (Ignored, if local repo path is used).
Use an empty string to clear the branch.
:param commit: Optional, specify the repository commit ID (Ignored, if local repo path is used).
Use an empty string to clear the commit.
""" """
if not repo or running_remotely(): if running_remotely():
return return
self._wait_for_repo_detection(timeout=300.) self._wait_for_repo_detection(timeout=300.)
with self._edit_lock: with self._edit_lock:
self.reload() self.reload()
self.data.script.repository = repo if repo is not None:
if branch: # we cannot have None on the value itself
self.data.script.branch = branch self.data.script.repository = repo or ""
if commit: if branch is not None:
self.data.script.version_num = commit # we cannot have None on the value itself
self.data.script.branch = branch or ""
if commit is not None:
# we cannot have None on the value itself
self.data.script.version_num = commit or ""
self._edit(script=self.data.script) self._edit(script=self.data.script)
def connect_configuration(self, configuration, name=None, description=None): def connect_configuration(self, configuration, name=None, description=None):