Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't WARN about git config returning 1 #29

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions src/backups2datalad/adataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,34 +182,25 @@ async def is_dirty(self) -> bool:
!= ""
)

async def get_repo_config(self, key: str) -> str | None:
async def get_repo_config(self, key: str, file: str | None = None) -> str | None:
args = ["--file", file] if file is not None else []
try:
return await self.read_git("config", "--get", key)
return await self.read_git("config", *args, "--get", key, quiet_rcs=[1])
except subprocess.CalledProcessError as e:
if e.returncode == 1:
return None
else:
raise

async def get_datalad_id(self) -> str:
return await self.read_git(
"config", "--file", ".datalad/config", "--get", "datalad.dataset.id"
)
r = await self.get_repo_config("datalad.dataset.id", file=".datalad/config")
assert r is not None
return r

async def get_embargo_status(self) -> EmbargoStatus:
try:
value = await self.read_git(
"config",
"--file",
".datalad/config",
"--get",
EMBARGO_STATUS_KEY,
)
except subprocess.CalledProcessError as e:
if e.returncode == 1:
return EmbargoStatus.OPEN
else:
raise
value = await self.get_repo_config(EMBARGO_STATUS_KEY, file=".datalad/config")
if value is None:
return EmbargoStatus.OPEN
else:
return EmbargoStatus(value)

Expand Down
30 changes: 17 additions & 13 deletions src/backups2datalad/aioutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
AsyncIterator,
Awaitable,
Callable,
Collection,
Container,
Mapping,
)
Expand Down Expand Up @@ -192,7 +193,7 @@


async def aruncmd(
*args: str | Path, **kwargs: Any
*args: str | Path, quiet_rcs: Collection[int] = (), **kwargs: Any
) -> subprocess.CompletedProcess[bytes]:
argstrs = [str(a) for a in args]
desc = shlex.join(argstrs)
Expand All @@ -204,19 +205,22 @@
try:
r = await anyio.run_process(argstrs, **kwargs)
except subprocess.CalledProcessError as e:
label = "Stdout" if e.stderr is not None else "Output"
stdout = e.stdout.decode("utf-8", "surrogateescape")
if stdout:
output = f"{label}:\n\n" + textwrap.indent(stdout, " " * 4)
else:
output = f"{label}: <empty>"
if e.stderr is not None:
stderr = e.stderr.decode("utf-8", "surrogateescape")
if stderr:
output += "\n\nStderr:\n\n" + textwrap.indent(stderr, " " * 4)
if e.returncode not in quiet_rcs:
label = "Stdout" if e.stderr is not None else "Output"
stdout = e.stdout.decode("utf-8", "surrogateescape")

Check warning on line 210 in src/backups2datalad/aioutil.py

View check run for this annotation

Codecov / codecov/patch

src/backups2datalad/aioutil.py#L209-L210

Added lines #L209 - L210 were not covered by tests
if stdout:
output = f"{label}:\n\n" + textwrap.indent(stdout, " " * 4)

Check warning on line 212 in src/backups2datalad/aioutil.py

View check run for this annotation

Codecov / codecov/patch

src/backups2datalad/aioutil.py#L212

Added line #L212 was not covered by tests
else:
output += "\n\nStderr: <empty>"
log.warning("Failed [rc=%d]: %s\n\n%s", e.returncode, desc, output)
output = f"{label}: <empty>"

Check warning on line 214 in src/backups2datalad/aioutil.py

View check run for this annotation

Codecov / codecov/patch

src/backups2datalad/aioutil.py#L214

Added line #L214 was not covered by tests
if e.stderr is not None:
stderr = e.stderr.decode("utf-8", "surrogateescape")

Check warning on line 216 in src/backups2datalad/aioutil.py

View check run for this annotation

Codecov / codecov/patch

src/backups2datalad/aioutil.py#L216

Added line #L216 was not covered by tests
if stderr:
output += "\n\nStderr:\n\n" + textwrap.indent(stderr, " " * 4)

Check warning on line 218 in src/backups2datalad/aioutil.py

View check run for this annotation

Codecov / codecov/patch

src/backups2datalad/aioutil.py#L218

Added line #L218 was not covered by tests
else:
output += "\n\nStderr: <empty>"
log.warning("Failed [rc=%d]: %s\n\n%s", e.returncode, desc, output)

Check warning on line 221 in src/backups2datalad/aioutil.py

View check run for this annotation

Codecov / codecov/patch

src/backups2datalad/aioutil.py#L220-L221

Added lines #L220 - L221 were not covered by tests
else:
log.debug("Finished [rc=%d]: %s", e.returncode, desc)
raise e
else:
log.debug("Finished [rc=%d]: %s", r.returncode, desc)
Expand Down