Skip to content

Commit

Permalink
trying and failing to get logging-on-demand by tools/entrypoint scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jun 24, 2022
1 parent 498530c commit 31866fe
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
6 changes: 3 additions & 3 deletions apis/python/README-dev.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
* Most things are configured using GitHub Actions at `../../.github/workflows`
* Pre-push suggestions:
* `black .`
* `isort .`
* `flake8`
* `black . tools/[a-z]*`
* `isort . tools/[a-z]*`
* `flake8 . tools/[a-z]*`
* `python -m pytest tests`
* PyPI:
* https://pypi.org/project/tiledbsc/
Expand Down
8 changes: 7 additions & 1 deletion apis/python/examples/uniformizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ def main() -> int:
parser = _create_args_parser()
args = parser.parse_args()

# XXX
if args.verbose:
# tiledbsc.logging.logger.setLevel(logging.INFO)
# logger = logging.getLogger('tiledbsc')
# logger.setLevel(logging.INFO)
# logging.getLogger("tiledbsc").setLevel(logging.INFO)
# Not able to get any of the above to 'stick'. The following sets level for the whole app,
# not just the tiledbsc library, but that's an acceptable workaround since this CLI does
# nothing except invoke the tiledbsc library.
logging.basicConfig(level=logging.INFO)

uniformizer = Uniformizer(
Expand Down
3 changes: 3 additions & 0 deletions apis/python/src/tiledbsc/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import logging

logger = logging.getLogger(__name__) # Nominally __name__ is 'tiledbsc'
25 changes: 19 additions & 6 deletions apis/python/tools/ingestor
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import tiledb

import tiledbsc
import tiledbsc.io
import tiledbsc.logger
import tiledbsc.logging
import tiledbsc.util


Expand Down Expand Up @@ -98,7 +98,16 @@ select `relative=True`. (This is the default.)
soma_options = tiledbsc.SOMAOptions()

write_soco = args.soco
# XXX verbose = not args.quiet
verbose = not args.quiet
if verbose:
# tiledbsc.logging.logger.setLevel(logging.INFO)
# logger = logging.getLogger('tiledbsc')
# logger.setLevel(logging.INFO)
# logging.getLogger("tiledbsc").setLevel(logging.INFO)
# Not able to get any of the above to 'stick'. The following sets level for the whole app,
# not just the tiledbsc library, but that's an acceptable workaround since this CLI does
# nothing except invoke the tiledbsc library.
logging.basicConfig(level=logging.INFO)

if args.relative is not None:
relative = args.relative[0]
Expand Down Expand Up @@ -208,7 +217,9 @@ def ingest_one(
else:
if os.path.exists(output_path):
if ifexists == "continue":
tiledbsc.logger.info(f"Already exists; continuing: {output_path}")
tiledbsc.logging.logger.info(
f"Already exists; continuing: {output_path}"
)
return
elif ifexists == "abort":
logging.error(f"Already exists; aborting: {output_path}")
Expand All @@ -229,7 +240,7 @@ def ingest_one(
# Do the ingest into TileDB.
tiledbsc.io.from_h5ad(soma, input_path)

tiledbsc.logger.info(f"Wrote {output_path}")
tiledbsc.logging.logger.info(f"Wrote {output_path}")

if write_soco:
soco = tiledbsc.SOMACollection(soco_dir, soma_options=soma_options)
Expand All @@ -238,8 +249,10 @@ def ingest_one(
raise Exception(f"Could not create SOCO at {soco.uri}")
soco.add(soma)

tiledbsc.logger.info("")
tiledbsc.logger.info(f"Added SOMA {soma.name} to SOMACollection {soco_dir}")
tiledbsc.logging.logger.info("")
tiledbsc.logging.logger.info(
f"Added SOMA {soma.name} to SOMACollection {soco_dir}"
)


# ================================================================
Expand Down
16 changes: 13 additions & 3 deletions apis/python/tools/outgestor
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import tiledb

import tiledbsc
import tiledbsc.io
import tiledbsc.logger
import tiledbsc.logging
import tiledbsc.util


Expand Down Expand Up @@ -76,11 +76,21 @@ def main():
if not os.path.exists(outdir):
os.mkdir(outdir)

# XXX verbose = not args.quiet
verbose = not args.quiet
if verbose:
# tiledbsc.logging.logger.setLevel(logging.INFO)
# logger = logging.getLogger('tiledbsc')
# logger.setLevel(logging.INFO)
# logging.getLogger("tiledbsc").setLevel(logging.INFO)
# Not able to get any of the above to 'stick'. The following sets level for the whole app,
# not just the tiledbsc library, but that's an acceptable workaround since this CLI does
# nothing except invoke the tiledbsc library.
logging.basicConfig(level=logging.INFO)

soma = tiledbsc.SOMA(input_path)
tiledbsc.io.to_h5ad(soma, output_path)

tiledbsc.logger.info(f"Wrote {output_path}")
tiledbsc.logging.logger.info(f"Wrote {output_path}")


if __name__ == "__main__":
Expand Down

0 comments on commit 31866fe

Please sign in to comment.