Skip to content

[feat] Git sparse checkout for sourcesdir#3629

Open
victorusu wants to merge 4 commits intoreframe-hpc:developfrom
victorusu:sparse_checkout
Open

[feat] Git sparse checkout for sourcesdir#3629
victorusu wants to merge 4 commits intoreframe-hpc:developfrom
victorusu:sparse_checkout

Conversation

@victorusu
Copy link
Contributor

@victorusu victorusu commented Feb 23, 2026

This expands the sourcesdir syntax to include a dictionary format. In this case, the git url is passed via the url key.
Additional command options can be added via the opts key. This capability was previously available in the git_clone function, but not accessible to the sourcesdir git clone interface.

The git sparse-checkout path is available when one defines the files keys with a list of files to checkout.
In this case, instead of emitting a git clone ... command the framework will emit the following set of commands

git clone --no-checkout --depth=1 ...
git sparse-checkout set --no-cone ${file list}
git checkout

where, ${file list} is the list of files defined in the files list.

An example test is this.

@rfm.simple_test
class git_clone_test(rfm.CompileOnlyRegressionTest):
    sourcesdir = {
         'url': 'https://github.com/eth-cscs/alps-gh200-reproducers.git',
         'files' : ['intranode-pinned-host-comm'],
         'opts' : ['--no-optional-locks', '--no-advice', '--no-pager']
    }
    build_system = 'SingleSource'
    sourcepath = 'intranode-pinned-host-comm/intranode_pinned_host_comm.cpp'
    valid_systems = ['*']
    valid_prog_environs = ['*']

Please note that I haven't added any unit tests because the framework does not include any unit tests for the original git_clone function.

closes #3627
closes #3053

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.32%. Comparing base (62babc6) to head (ea7a888).
⚠️ Report is 53 commits behind head on develop.

Files with missing lines Patch % Lines
reframe/core/pipeline.py 46.15% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3629      +/-   ##
===========================================
+ Coverage    91.25%   91.32%   +0.06%     
===========================================
  Files           62       62              
  Lines        13587    13532      -55     
===========================================
- Hits         12399    12358      -41     
+ Misses        1188     1174      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@victorusu victorusu requested review from ekouts and vkarak February 25, 2026 08:14
@vkarak vkarak added this to the ReFrame 4.10 milestone Feb 25, 2026
@vkarak vkarak changed the title Git sparse checkout for sourcesdir [feat] Git sparse checkout for sourcesdir Feb 25, 2026
#: Default value is now conditionally set to either ``'src'`` or
#: :class:`None`.
sourcesdir = variable(str, type(None), value='src')
sourcesdir = variable(str, typ.Dict, type(None), value='src')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourcesdir = variable(str, typ.Dict, type(None), value='src')
sourcesdir = variable(str, typ.Dict[str, object], type(None), value='src')

Comment on lines +1998 to +2014
srcdir = self.sourcesdir
if isinstance(srcdir, dict):
if 'url' not in srcdir:
raise ReframeError(f'{srcdir} misses the url key')

url = srcdir['url']
if not osext.is_url(url):
raise ReframeError(f'The dictionary syntax only supports '
'git repositories')

self._clone_to_stagedir(url,
files=srcdir[url]['files'] if 'files'
in srcdir[url] else None,
opts=srcdir[url]['opts'] if 'opts'
in srcdir[url] else None)
elif osext.is_url(srcdir):
self._clone_to_stagedir(srcdir)
Copy link
Contributor

@vkarak vkarak Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat ugly. Ideally, I would see the keys of the sourcesdir correspond the arguments of the target function. You could do something along these lines:

if not isinstance(self.sourcesdir, dict):
    # Convert it to dict passing the default values
    self.sourcesdir = {'url': self.sourcesdir, ...}

try:
    self._clone_to_stagedir(**self.sourcesdir)
except TypeError as err:
    raise ReframeSyntaxError('invalid syntax for sourcesdir') from err



def git_clone(url, targetdir=None, opts=None, timeout=5):
def git_clone(url, targetdir=None, opts=None, timeout=5, files=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, fine tune the options to match those from _clone_stagedir(). Technically, it's vice-versa: _clone_stagedir() should follow the options of this one and sourcesdir the options in _clone_stagedir().

@github-project-automation github-project-automation bot moved this from Todo to In Progress in ReFrame Backlog Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

only clone a subdirectory of a git repo Consider using depth of 1 when automatically cloning a git repo

2 participants