Skip to content

WIP: introduce the cache-files check#7

Draft
Hyask wants to merge 1 commit into
ubuntu:mainfrom
Hyask:skia/cache_files
Draft

WIP: introduce the cache-files check#7
Hyask wants to merge 1 commit into
ubuntu:mainfrom
Hyask:skia/cache_files

Conversation

@Hyask

@Hyask Hyask commented Jun 18, 2026

Copy link
Copy Markdown
Member

This is a port of that original MP.

Please have a look at all the XXX comments, they contain questions that need to be answered before even thinking about merging this.

@enr0n enr0n left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR! This will be a great addition. This was a quick review so please ask if anything I suggested did not make sense.

Please also consider adding some tests for this.

Comment thread ubuntu_lint/linters.py Outdated
Comment thread ubuntu_lint/linters.py Outdated


def _check_cache_files(context: Context, directory: str):
files = subprocess.check_output(["find"], cwd=directory).decode().splitlines()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems unnecessary to shell out to find here. Shouldn't os.walk or something do the trick?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should do this with transparent archive access instead: https://code.launchpad.net/~ubuntu-server/+git/ubuntu-helpers/+merge/500673

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So, for the dput hook, which is the case where we only have the .changes files, I went with some improved version of your transparent archive access, and for the CLI case, where we only have the source_dir, I went with Path.glob().
Thanks both for the input :-)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FYSA, the CLI case can still have the changes file as context.

Comment thread dput.d/profiles/ubuntu.json Outdated
Comment thread ubuntu_lint/context.py Outdated
Comment on lines +136 to +140
# XXX this needs to be better defined
# It's currently needed to be able to extract the .dsc in the
# cache-files check, but that extraction should probably be handled
# more generally in that Context class.
self._changes_path = changes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it makes sense to make .dsc an attribute of Context, just like the changes file, source dir, etc. You can add some sensible defaults to try and derive it by default (see the logic for changes file).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the end, when implementing the "transparent access" that jj suggested, I didn't need the .dsc anymore, only the path to the .changes, so I implemented properly that property, and the dput entry-point is making use of it.
I guess this could spark further refactor where we could actually only provide the path, and the Context would then go read it to populate Context.changes, but I believe that would belong to some subsequent refactor. What do you think?

Comment thread ubuntu_lint/linters.py Outdated
Comment thread ubuntu_lint/linters.py
@Hyask Hyask force-pushed the skia/cache_files branch 3 times, most recently from b7540b4 to 6ea1475 Compare July 10, 2026 10:54
@Hyask Hyask force-pushed the skia/cache_files branch from 6ea1475 to 07c39ea Compare July 10, 2026 11:36
Comment thread ubuntu_lint/linters.py
Comment on lines +23 to +33
for cache_file in [
# General
"CACHEDIR.TAG",
".direnv",
"/.git/", # XXX: that one is kind of a problem when `ubuntu-lint` is invoked as a CLI in a git repo. Maybe we should see to activate that only for the `dput` hook?
# Python
".pyc",
".egg-info",
".tox",
"__pycache__",
]:

@TheJJ TheJJ Jul 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

to avoid reconstructing them and for faster lookups, this bad-name list could be defined outside the _get_bad_files function as a set. and there should be a easy way to extend this list, for example to add ruff_cache or mypy_cache files.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

By "easy way to extend", do you mean a configuration file of sorts? If so, that's probably out of scope for now, but I would eventually like to have something like that.

Comment thread ubuntu_lint/context.py
def __init__(
self,
changes: str | deb822.Changes | None = None,
changes_path: str | Path | None = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm, this feels a bit redundant since changes already accepts a path (though maybe the type annotation should be updated to make that more clear).

I think I would rather do one of the following:

  1. Add a files parameter to context, and pass those paths directly in the dput hook with changes.get_files(). Or;
  2. Keep the changes_path property, but set it when changes is a path, and not raw data. Then, in the dput hook start passing the absolute file path with changes.get_changes_file() instead of passing the raw data.

What do you think?

Comment thread ubuntu_lint/linters.py
Comment on lines +40 to +58
try:
# Case where we directly have the source_dir
files = [str(p) for p in Path(context.source_dir).absolute().glob("**")]
print(files)
bad_files += _get_bad_files(files)
except MissingContextException:
pass

try:
# Case of a .changes file and we need to read the tarballs
changes_files = context.changes.get("Files")
if changes_files:
for item in changes_files:
if ".tar." in item["name"]:
file_path = context.changes_path.parent / item["name"]
with tarfile.open(file_path, "r") as tar:
bad_files += _get_bad_files(tar.getnames())
except MissingContextException:
pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't these be mutually exclusive cases? Or, I guess there needs to be some consistency check as is done in other places where data can come from multiple context sources.

Comment thread ubuntu_lint/linters.py
pass

if bad_files:
context.lint_warn(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be lint_fail(). The callers can decide to downgrade or not. I.e. I see in the CLI you configured this to be warning by default.

Comment thread ubuntu_lint/linters.py
Comment on lines +23 to +33
for cache_file in [
# General
"CACHEDIR.TAG",
".direnv",
"/.git/", # XXX: that one is kind of a problem when `ubuntu-lint` is invoked as a CLI in a git repo. Maybe we should see to activate that only for the `dput` hook?
# Python
".pyc",
".egg-info",
".tox",
"__pycache__",
]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

By "easy way to extend", do you mean a configuration file of sorts? If so, that's probably out of scope for now, but I would eventually like to have something like that.

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.

3 participants