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

feat: summarise 'charmcraft analyse' results #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tonyandrewmeyer
Copy link
Owner

New summary script that:

  1. Packs the charm
  2. Runs charmcraft analyse on the resulting charm files
  3. Summarises the output

Copy link
Collaborator

@james-garner-canonical james-garner-canonical left a comment

Choose a reason for hiding this comment

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

Seems cool! I've done some nitpicking though haha

# Remove the build environment - otherwise, this ends up using a huge amount
# of disk space (in /var/snap/lxd).
subprocess.run(["charmcraft", "clean"], check=True, cwd=repo)
continuation = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

type hint could be good here
I guess it's
tuple[Path, str, str] | None
?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
continuation = None
continuation: tuple[Path, str, str] | None = None

tools/summarise_analyse.py Show resolved Hide resolved
Comment on lines +55 to +56
full_line = f"{continuation[2]} {line}"
logger.warning("%s (%s): %s", *continuation[:-1], full_line)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unpack for readability?

repo, charm_name, prev_line = continuation
full_line = f'{prev_line} {line}'
logger.warning("%s (%s): %s", repo, charm_name, full_line)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
full_line = f"{continuation[2]} {line}"
logger.warning("%s (%s): %s", *continuation[:-1], full_line)
repo, charm_name, prev_line = continuation
full_line = f"{prev_line} {line}"
logger.warning("%s (%s): %s", repo, charm_name, full_line)

tools/summarise_analyse.py Show resolved Hide resolved
)

total = 0
overall_results = collections.defaultdict(lambda: collections.Counter())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can use collections.Counter without the lambda

Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
overall_results = collections.defaultdict(lambda: collections.Counter())
overall_results = collections.defaultdict(collections.Counter)

tools/summarise_analyse.py Show resolved Hide resolved
# of disk space (in /var/snap/lxd).
subprocess.run(["charmcraft", "clean"], check=True, cwd=repo)
continuation = None
for charm in repo.glob("*.charm"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you run with the repack option, and there are already .charm files with different names, this will get both, right? But I guess the expectation is that the only charm file is the one you made?

It doesn't seem like you can set the output filename, but you could use charmcraft pack's --output flag to set an output directory and remove the directory before repacking ... ./.cache/$charm/.packed/ maybe? or maybe a parallel structure like ./.packed-cache/$charm/ would be more convenient since you can easily remove all the packed charms in one operation

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah, I'm somewhat assuming that the cache folder is only used by these tools, or is cleaned up to be that way. And yes, I really wanted to just get the output name but it doesn't seem possible, probably because of the history of charmcraft being able to produce multiple charms in a pack.

Putting them all somewhere else is an interesting idea, though.

@james-garner-canonical
Copy link
Collaborator

Oh also I know namespaces are a honking great idea, but it might be nice to import Path, defaultdict and Counter directly. Just a personal taste thing though

@tonyandrewmeyer
Copy link
Owner Author

Oh also I know namespaces are a honking great idea, but it might be nice to import Path, defaultdict and Counter directly. Just a personal taste thing though

I think we discussed this elsewhere but my personal taste is very much the opposite :)

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.

2 participants