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

Add console module #1948

Merged
merged 11 commits into from
Jun 21, 2024
Merged

Add console module #1948

merged 11 commits into from
Jun 21, 2024

Conversation

JimMadge
Copy link
Member

Closes #1945

@JimMadge JimMadge requested a review from a team as a code owner June 19, 2024 14:04
@jemrobinson
Copy link
Member

I agree that logging and writing to console are distinct actions, but I was wondering whether there's a sufficiently broad module name that could cover them both. They're more similar to one another than e.g. logging is to deploying Pulumi infrastructure. What do you think @JimMadge?

@JimMadge
Copy link
Member Author

I don't like the idea of both in a module at the same level, like output.logger.info() and output.pretty_print. Having nested modules, like output.logging.logger and output.console.pretty_print, seems over complicated.

@jemrobinson
Copy link
Member

I guess I was imagining something like:

from data_safe_haven.output import get_logger, console

logger = get_logger()
logger.info("message")
console.print("message")

to replace

from data_safe_haven.logging import get_logger
from data_safe_haven.console import console

logger = get_logger()
logger.info("message")
console.print("message")

Not a big difference, but might make the code a bit easier to understand for new developers.

Copy link

github-actions bot commented Jun 20, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  data_safe_haven/administration/users
  user_handler.py
  data_safe_haven/commands
  cli.py
  config.py
  context.py
  pulumi.py
  data_safe_haven/console
  __init__.py
  format.py
  pretty.py
  data_safe_haven/external/api
  azure_cli.py 75
  graph_api.py 1112
  data_safe_haven/utility
  __init__.py
Project Total  

This report was generated by python-coverage-comment-action

data_safe_haven/commands/cli.py Outdated Show resolved Hide resolved
data_safe_haven/commands/pulumi.py Outdated Show resolved Hide resolved
data_safe_haven/console/pretty.py Outdated Show resolved Hide resolved
@JimMadge
Copy link
Member Author

I also should add tests for the parts that aren't covered given that I have had a look at them here.

@JimMadge
Copy link
Member Author

JimMadge commented Jun 21, 2024

@jemrobinson I'm still not keen on collecting logging and printing in one module.

Would something like

from data_safe_haven.logging import get_logger
from data_safe_haven.console import console, prompts

logger = get_logger()
logger.info("hello")
console.print("hello")  # console is a rich.console.Console
prompts.confirm("yes or no?")

be better?

@jemrobinson
Copy link
Member

jemrobinson commented Jun 21, 2024

I think that looks OK (did you mean to import prompts? I think you wouldn't need to in this case). Essentially, I think it would be helpful to have console.method calls which look like logger.method calls so you can easily see "ah, this is being logged but this is going straight to the console".

N.B. I don't mean that we need console.info etc., console.print is fine.

@JimMadge
Copy link
Member Author

Oh, I made a mistake, I've updated the code block.

@jemrobinson
Copy link
Member

jemrobinson commented Jun 21, 2024

OK, what do you think of:

from data_safe_haven.logging import get_logger
from data_safe_haven.console import console

logger = get_logger()
logger.info("hello")
console.print("hello")
console.confirm("yes or no?")

instead?

@JimMadge
Copy link
Member Author

Yes we can do that. The only thing that is a little annoying about that is we are making a wrapper for rich.Console.print instead of just exposing a rich.Console. Not a big deal though and it does make the API much cleaner.

@jemrobinson
Copy link
Member

I agree, it's a bit annoying - maybe we can use this chance to provide an adaptor for the console.print arguments that fits our needs better (e.g. we probably don't use all the arguments at the moment)?

@JimMadge JimMadge requested a review from jemrobinson June 21, 2024 13:56
Copy link
Member

@jemrobinson jemrobinson left a comment

Choose a reason for hiding this comment

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

LGTM. Does it work? :)

@JimMadge
Copy link
Member Author

Yes, as far as I can tell.

I'm still not sure what is happening in #1954. I can't reproduce it with dsh config upload ....

@JimMadge JimMadge merged commit 736d9c0 into develop Jun 21, 2024
11 checks passed
@JimMadge JimMadge deleted the console branch June 21, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Console module
2 participants