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

Add commit hash/version in footer #323

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

fstachura
Copy link
Collaborator

No description provided.

elixir/web_utils.py Outdated Show resolved Hide resolved
if re.match('^[0-9a-f]{5,12}$', version) or version.startswith('v'):
return f'https://github.com/bootlin/elixir/tree/{ version }'
else:
return f'https://github.com/bootlin/elixir/'
Copy link
Member

Choose a reason for hiding this comment

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

I am not convinced this is useful. I'd vote for always returning the standard repo link and trust people can navigate to find the repo version / hash being displayed on the page.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is useful, and when I see a commit hash, I would expect to be redirected to a particular commit. The link to a particular version can be separate if you think this helps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only problem is that the linked version may not exist in the upstream repo if someone hosts their own. But maybe this is actually good, it signifies that it's a custom instance

)

if return_code == 0:
return result.decode('utf-8')
Copy link
Member

Choose a reason for hiding this comment

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

If return code is non-zero but nothing is emitted to stderr, we get no error log and return the default "v2.2" silently.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

run_cmd logs errors

Copy link
Member

@tleb tleb Oct 29, 2024

Choose a reason for hiding this comment

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

No: run_cmd() logs only when something is emitted to stderr. Something can fail (return_code != 0) but not emit anything on stderr.

I think get_elixir_version_string() should be more like (this is a proof-of-concept, not tested):

def get_elixir_version_string():
    version = os.environ.get('ELIXIR_VERSION')
    if version is not None and len(version) != 0:
        return version

    try:
        # try to get Elixir version from git
        result, return_code = run_cmd('git',
            '-C', ELIXIR_DIR,
            '-c', f'safe.directory={ os.path.normpath(ELIXIR_DIR) }',
            'rev-parse', '--short', 'HEAD'
        )

        if return_code != 0:
            raise ValueError(f"git rev-parse returned {return_code}")

        return result.decode('utf-8')
    except Exception as e:
        logging.exception(f"failed to get elixir commit hash: {e}")

    return ''

Edit: or it could be run_cmd() that is modified to log whenever p.returncode is non-zero.

@fstachura fstachura force-pushed the commit-hash-in-footer branch 2 times, most recently from 1323f65 to 3923b4c Compare October 7, 2024 15:00
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