CWorthy-ocean / C-Star

C-Star is a python package for setting up and running ocean model simulations, with a particular focus on marine carbon dioxide removal (mCDR) applications.
https://c-star.readthedocs.io
10 stars 4 forks source link

Initializing `ROMSBaseModel()` without parameters #130

Closed NoraLoose closed 1 week ago

NoraLoose commented 1 week ago
from cstar.roms import ROMSBaseModel
roms_base_model = ROMSBaseModel()

returns the error

File /global/u2/n/nloose/C-Star/cstar/base/base_model.py:85, in BaseModel.__init__(self, source_repo, checkout_target)
     77 self.source_repo = (
     78     source_repo if source_repo is not None else self.default_source_repo
     79 )
     80 self.checkout_target = (
     81     checkout_target
     82     if checkout_target is not None
     83     else self.default_checkout_target
     84 )
---> 85 self.checkout_hash = _get_hash_from_checkout_target(
     86     self.source_repo, self.checkout_target
     87 )
     88 self.repo_basename = Path(self.source_repo).name.replace(".git", "")

File /global/u2/n/nloose/C-Star/cstar/base/utils.py:108, in _get_hash_from_checkout_target(repo_url, checkout_target)
     86 """Take a git checkout target (any `arg` accepted by `git checkout arg`) and return
     87 a commit hash.
     88 
   (...)
    104     A git commit hash associated with the checkout target
    105 """
    107 # First check if the checkout target is a 7 or 40 digit hexadecimal string
--> 108 is_potential_hash = bool(re.match(r"^[0-9a-f]{7}$", checkout_target)) or bool(
    109     re.match(r"^[0-9a-f]{40}$", checkout_target)
    110 )
    112 # Then try ls-remote to see if there is a match
    113 # (no match if either invalid target or a valid hash):
    114 ls_remote = subprocess.run(
    115     "git ls-remote " + repo_url + " " + checkout_target,
    116     shell=True,
    117     capture_output=True,
    118     text=True,
    119 ).stdout

File ~/.conda/envs/cstar_env/lib/python3.12/re/__init__.py:167, in match(pattern, string, flags)
    164 def match(pattern, string, flags=0):
    165     """Try to apply the pattern at the start of the string, returning
    166     a Match object, or None if no match was found."""
--> 167     return _compile(pattern, flags).match(string)

TypeError: expected string or bytes-like object, got '_UnionGenericAlias'

while

roms_base_model = ROMSBaseModel(
    source_repo='https://github.com/CESR-lab/ucla-roms.git',
    checkout_target='246c11fa537145ba5868f2256dfb4964aeb09a25',
)

works.

Is this expected behavior? I assumed that the source_repo and checkout_target are optional and would default to:

https://github.com/CWorthy-ocean/C-Star/blob/14fc88950016347b46eb5802314adbb8f967424b/cstar/roms/base_model.py#L26-L32

NoraLoose commented 1 week ago
roms_base_model = ROMSBaseModel(
    source_repo='https://github.com/CESR-lab/ucla-roms.git',
    checkout_target='main'
)

works as well.