Skip to content

Adding helper_lib#207

Merged
MaximilianSoerenPollak merged 5 commits into
eclipse-score:mainfrom
MaximilianSoerenPollak:MSP_add_git_lib
Aug 14, 2025
Merged

Adding helper_lib#207
MaximilianSoerenPollak merged 5 commits into
eclipse-score:mainfrom
MaximilianSoerenPollak:MSP_add_git_lib

Conversation

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor

Added helper lib that contains some often used functions

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

/consumer-test

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 13, 2025

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run //src:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.3.0) and connecting to it...
INFO: Invocation ID: 63465927-f53b-4dc1-86bb-461e0fd1fed0
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Loading: 0 packages loaded
    currently loading: src
Analyzing: target //src:license-check (1 packages loaded, 0 targets configured)
Analyzing: target //src:license-check (1 packages loaded, 0 targets configured)

Analyzing: target //src:license-check (73 packages loaded, 9 targets configured)

Analyzing: target //src:license-check (80 packages loaded, 17 targets configured)

Analyzing: target //src:license-check (126 packages loaded, 2252 targets configured)

Analyzing: target //src:license-check (134 packages loaded, 2472 targets configured)

Analyzing: target //src:license-check (135 packages loaded, 2473 targets configured)

INFO: Analyzed target //src:license-check (137 packages loaded, 4488 targets configured).
INFO: Found 1 target...
Target //src:license.check.license_check up-to-date:
  bazel-bin/src/license.check.license_check
  bazel-bin/src/license.check.license_check.jar
INFO: Elapsed time: 14.622s, Critical Path: 0.37s
INFO: 13 processes: 4 disk cache hit, 9 internal.
INFO: Build completed successfully, 13 total actions
INFO: Running command line: bazel-bin/src/license.check.license_check src/formatted.txt <args omitted>
[main] INFO Querying Eclipse Foundation for license data for 84 items.
[main] INFO Found 58 items.
[main] INFO Querying ClearlyDefined for license data for 26 items.
[main] ERROR Error response from ClearlyDefined 429

@github-actions
Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

@AlexanderLanin
Copy link
Copy Markdown
Member

Can you check against eclipse-score/tooling#30 please

@@ -356,35 +359,35 @@ def test_group_by_need_empty_list():
def test_parse_git_output_ssh_format():
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.

move these tests? (separate PR?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, need to move these yep.

Comment thread src/helper_lib/__init__.py Outdated
Comment on lines +56 to +58
# fallback to cwd when building with python -m sphinx docs _build -T
if recoursion_break:
return None
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.

Is it possible to write that loop somehow differently? I still don't get it. And there is no fallback to cwd?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Basically,

In Esbonio or other executions it can happen that it reaches the home directory '/' and there is still no .git.
If this happens it would just loop indifferently without stopping. Therefore if we found the '/' then we tell it that it already did find it and break.

There might be a better way to write this, I have another look at it.

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.

Consider while + else. No idea whether that will make it better, but it sounds like a perfect fit.

Comment thread src/helper_lib/__init__.py Outdated
Unlike other funcions, this function behaves the same for the following commands:

'bazel run' => str
'bazel build' => str
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.

bazel build should not have .git in the sandbox? And it could run remotely where there is definitely no .git.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did print the statements inside of the conf.py and accumulated the behaviour via that.

I have not tested it yet as a remote / imported thing.

Comment thread src/helper_lib/__init__.py Outdated

def get_github_repo_info(git_root_cwd: Path) -> str:
"""
Unlike other funcions, this function behaves the same for the following commands:
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.

Suggested change
Unlike other funcions, this function behaves the same for the following commands:
Query git for the github remote repository (based on heuristic).
Unlike other funcions, this function behaves the same for the following commands:

Comment thread src/helper_lib/__init__.py Outdated
return repo


def get_git_root(git_root: Path = Path()) -> Path:
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.

get_git_root vs find_git_root is unclear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Funny you mention that. I too am struggling to remember why we had this.
Was copied from the place we had those functions before.

I know it makes testing possible, but there might be a nicer way or better way to name those.

Comment thread src/helper_lib/__init__.py Outdated
return passed_git_root


def get_github_base_url(git_root: Path = Path()) -> str:
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.

Suggested change
def get_github_base_url(git_root: Path = Path()) -> str:
def get_github_pages_url(git_root: Path = Path()) -> str:

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

/consumer-test

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

/consumer-test

f"{get_github_link(ws_root, n)}<>{n.file}:{n.line}" for n in needlinks
)
def make_source_link(needlinks):
return ", ".join(f"{get_github_link(n)}<>{n.file}:{n.line}" for n in needlinks)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems that both formaters disagree on this.

Ruff (via multitool) fixed it to be like the old style.
Then our formatter fixed it again to be like the right.

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.

what is "our formatter"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the one that we run via format.fix bazel run //src:format.fix

with open(golden_file) as f2:
json2 = json.load(f2, object_hook=needlink_test_decoder)
assert len(json1) == len(json2), (
f"{file1}'s lenth are not the same as in the golden file lenght. "
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit:

Suggested change
f"{file1}'s lenth are not the same as in the golden file lenght. "
f"{file1}'s lenth is not the same as the golden file. "

Comment on lines +28 to +30
- 'bazel run' => ✅ Full workspace path
- 'bazel build' => ❌ None (sandbox isolation)
- 'direct sphinx' => ❌ None (no Bazel environment)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unsure if Icons are a good idea, but I didn't want to bother to remove them.

f"Got wrong input line from 'get_github_repo_info'. Input: {str_line}. "
+ "Expected example: 'origin git@github.com:user/repo.git'"
)
return ""
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit/Next PR:

Look through this file to find out where we actually can throw exceptions etc.
As this 'empty' return might actually do more harm than good.

Comment thread src/helper_lib/__init__.py
Comment thread src/helper_lib/__init__.py Outdated
assert all(c in "0123456789abcdef" for c in decoded_result)
return decoded_result
except Exception as e:
LOGGER.warning(f"Unexpected error: {git_root}", exc_info=e)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit:

Suggested change
LOGGER.warning(f"Unexpected error: {git_root}", exc_info=e)
LOGGER.warning(f"Unexpected error while trying to get git_hash. Exceuted in: {git_root}", exc_info=e)

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

/consumer-test

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

Overall it looks alright, I did check and don't see any ruff errors in the helper_lib as far as I can tell. Just so I don't introduce new linter warnnings while we try to reduce old ones.

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

@MaximilianSoerenPollak
Copy link
Copy Markdown
Contributor Author

MaximilianSoerenPollak commented Aug 14, 2025

Fun.. It breaks consumer-tests.

https://github.com/eclipse-score/docs-as-code/actions/runs/16977114074/job/48128734948

Testing it locally, seems like a simple-ish fix.

Edit:
Seeing some of these errors locally.

WARNING: External need 'PROCESS_wp__tool_verification_report' in
PosixPath('/home/maxi/.cache/bazel/_bazel_maxi/3cd7bd6002cd113bb4e19889316e3ec2/execroot/_main/bazel-out/k8-fastbuild/bin/docs.runfiles/score_process+/needs_json/_build/needs/needs.json') could not be added: A need with ID
'PROCESS_wp__tool_verification_report' already exists.
WARNING: External need 'PROCESS_wp__training_path' in
PosixPath('/home/maxi/.cache/bazel/_bazel_maxi/3cd7bd6002cd113bb4e19889316e3ec2/execroot/_main/bazel-out/k8-fastbuild/bin/docs.runfiles/score_process+/needs_json/_build/needs/needs.json') could not be added: A need with ID
'PROCESS_wp__training_path' already exists

I'm guessing the consumer tests then aren't cleaning properly? Not sure where this comes from?
Could only explain it to myself if there is a re-import?

@MaximilianSoerenPollak MaximilianSoerenPollak merged commit 71a1ec1 into eclipse-score:main Aug 14, 2025
7 of 8 checks passed
MaximilianSoerenPollak added a commit to MaximilianSoerenPollak/docs-as-code that referenced this pull request Aug 14, 2025
MaximilianSoerenPollak added a commit to MaximilianSoerenPollak/docs-as-code that referenced this pull request Aug 18, 2025
MaximilianSoerenPollak added a commit that referenced this pull request Aug 18, 2025
* Followup PR to integrate nits of #207
arnoox pushed a commit to arnoox/score-docs-as-code that referenced this pull request Feb 20, 2026
Adding a helper_lib which adds some common used functionality.

Added following functions: 
- find workspace root (based on bazel workspace environment var)
- find git root
- get & parse git remote repo
- get git hash
arnoox pushed a commit to arnoox/score-docs-as-code that referenced this pull request Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants