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

Catch case of nonexistent IRDB package root dir #290

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

teutoburg
Copy link
Contributor

@teutoburg teutoburg added bug Something isn't working tests Related to unit or integration tests labels Oct 31, 2023
@teutoburg teutoburg marked this pull request as ready for review October 31, 2023 16:25
@teutoburg
Copy link
Contributor Author

Should be trivial, I'll merge...

@teutoburg teutoburg merged commit e4ce56d into dev_master Oct 31, 2023
20 checks passed
@teutoburg teutoburg deleted the fh/bugreportpksfix branch October 31, 2023 16:37
@hugobuddel
Copy link
Collaborator

Thanks. Let's see tomorrow whether it worked!

@hugobuddel
Copy link
Collaborator

So close! https://github.com/AstarVienna/ScopeSim_Data/actions/runs/6715938272/job/18251458780

File /tmp/tmp.BV6rC3Nx40/ScopeSim/scopesim/utils.py:468, in _write_bug_report(stream)
    466 pkgs_path = Path(rc.__config__["!SIM.file.local_packages_path"])
    467 installed_pkgs = _get_all_irdb_pkgs(pkgs_path)
--> 468 maxkeylen = max(len(pkg.stem) for pkg in installed_pkgs)
    469 for pkg_path in installed_pkgs:
    470     pkg_ver = _get_irdb_pkg_version(pkg_path)

ValueError: max() arg is an empty sequence

perhaps

maxkeylen = max(len(pkg.stem) for pkg in installed_pkgs + [""])

or

maxkeylen = max(len(pkg.stem) for pkg in installed_pkgs) if installed_pkgs else 0

or maybe 1 if 0 is too short for some reason.

Now I wonder, are there programming languages where this would just work? That is, a good type system could infer that we're taking the maximum of the length of strings. And it seems feasible to somehow encode in a type system that the maximum of an empty list should be the lowest possible maximum, which in this case is definable as 0.

I was wondering because both the above solutions are ugly. However, writing this useless comment gave me the time to reflect, and there is a third option that is not ugly (in my eyes), because it comes closest to what I tried to convey above:

maxkeylen = max((len(pkg.stem) for pkg in installed_pkgs), default=0)

hugobuddel added a commit that referenced this pull request Nov 1, 2023
@hugobuddel hugobuddel mentioned this pull request Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tests Related to unit or integration tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants