Skip to content

New functionality that cleans up a lot and makes this into a real python module#53

Open
Spatenheinz wants to merge 19 commits intoArtifactLabs:masterfrom
Spatenheinz:master
Open

New functionality that cleans up a lot and makes this into a real python module#53
Spatenheinz wants to merge 19 commits intoArtifactLabs:masterfrom
Spatenheinz:master

Conversation

@Spatenheinz
Copy link

This commit adds some commits from divergent Demant main branch changes.

I have a lot of stuff comming this way. I have some commits that makes list command more powerful and also I am reworking the repo to look more like a usual python module.

I am not sure if you want this to be multiple pull requests or if I should update this one.

This commit introduces create_rbgit which moves the logic
of finding nca_path out of main as to make it easier to
create RbGit instances e.g. in test cases without duplicated code.

We also enable RbGit to be context managed.
This commit fixes some bugs which occured as the these parts
did not change when the schema for artifact/meta-for-commit did.

Also includes tests to ensure this does not happen again
bug: fix wrongful meta-for-commit after new scheme

See merge request csfw/flow/git-recycle-bin!11
@Spatenheinz Spatenheinz requested a review from eisbaw September 3, 2025 09:37
@codecov
Copy link

codecov bot commented Sep 3, 2025

@Spatenheinz Spatenheinz force-pushed the master branch 3 times, most recently from 89763cc to 09abfbd Compare September 16, 2025 10:57
@Spatenheinz Spatenheinz changed the title Align open source with Demant changes New functionality that cleans up a lot and makes this into a real python module Sep 16, 2025
Copy link
Contributor

@eisbaw eisbaw left a comment

Choose a reason for hiding this comment

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

Thanks Jacob! Here is my (and Claude's) review.

Approved Commits

  • 7d78460: Excellent Nix refactoring - improves composability with callPackage pattern
  • 6e76ac3: Outstanding dict-to-dataclass refactoring - significantly improves type safety
  • ea117db: Clean custom trailers feature - good separation of concerns, backward compatible
  • db426b4: Critical bug fix for metadata reference construction with comprehensive tests

Bugs

  • 3adecc4 & 52a6a55: Infinite recursion in jq() function - immediate stack overflow
  • a1602f5: Silent failure bug - errors from download_single never captured
  • cf309ad: Missing return statements cause AttributeError at runtime
  • 088b813: Removed conditional logic breaks API contract, mutable default arguments
  • 29a0650: Resource leaks - context manager only cleans up on success
  • b8d9708: Broken function calls, incomplete implementation

Jacob's Likely Motivations

  • Library interface focus: Converting CLI-first code into reusable library functions for programmatic use
  • Batch processing efficiency: Replace one-at-a-time operations with bulk operations (e.g., download multiple artifacts)
  • Dependency injection: Make RbGit objects easier to create and test by accepting external dependencies
  • Better composability: Split monolithic functions into smaller, composable pieces
  • Type safety improvements: Move from untyped dicts to strongly-typed dataclasses
  • Query abstraction: Create flexible query system for filtering artifacts with jq integration
  • Resource control: Give callers more control over when cleanup happens vs automatic cleanup

Architecture Questions

  • rbgits dict: Why replace simple context managers with complex state dictionary? Original approach was cleaner and exception-safe
  • Silent error handling: Multiple commits use ignore_errors=True - violates fail-fast principles, should errors be surfaced instead?
  • Resource management: Several commits have cleanup issues - should we standardize on context managers throughout?
  • API breaking changes: Several parameter reorderings and removals - is backward compatibility a concern?
  • State complexity: New designs often introduce more state management - is this necessary for the library interface goals?

@Spatenheinz
Copy link
Author

Great comments, I will look at fixing the issues ASAP :D.

In regard to
rbgits dict: Why replace simple context managers with complex state dictionary? Original approach was cleaner and exception-safe
It may be a premature "optimization", but consider a case where i need to download a lot of different artifacts within the same rbgit worktree. Then we dont have to destruct and reinit every time. This also brings up another question regarding races. If i have two rbgit instances with the same working tree, there is 1. nothing stopping them from having racing remotes? and one may destroy the .rbgit folder before the other is finished. I would assume we need some sort of synchronization, but what is best suited I dont know.

In regard to API breaking changes, Its a pain but maybe a fine idea. However until a 1.0 release I dont see why we should have.

In regard to State complexity, Maybe it is more complex, idk I dont see it that way. But it also adds a lot of functionality and efficiency. IMO it is worth doing.

@Spatenheinz
Copy link
Author

@eisbaw I have added fixed for the code comments in commits added on top, since you did not get to back if I should meld them into my previous commits or put them on top.
Also I have written an answer to some of the architectural changes.

This commit refactors the code to follow a common python
package/module structure and exposes the public facing API
in the __init__.py file
This change allow all commands if run via cmdline to clean as
a "sideeffect".
On the other hand it allows for better decoupling of responsibility
in the library.
This commit allow us to do --all to show all artifacts across shas,
not only for the current sha. This composes well with filters so
we can find specifically what we need across many different shas.

We also do a bit of refactoring/cleanup for the list module
This commit makes the list filters way more powerful by
allowing to externally calling jq to filter on the meta data
This commit makes a better interface for working with the list command
in a library.
Furthermore the rewrite of queries now allow us to do conjunction queries.
This commit makes it easier to control printing of rbgit commands,
as well as having better management of destuction of rbgit objects
(its underlying git folder).

This commit however doesnt address the problem that rbgit instances
are thread unsafe, in that two processes that can use the same
underlying git folder may end up in a  situation like this:

proc a starts --- do something --- gc / delete
  Proc b starts ------------ do something ---- try but fails
This commits main purpose is to restructure create_artifact_commit
a little to be easier to read, and to analyze with tools.
We also make sure to make push easier to use from library. I.e a more
uniform interface to the other commands.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
14 Security Hotspots
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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