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

Explicitly catch the InvalidGitRepositoryError when trying to the repo information. #276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sww
Copy link

@sww sww commented Jun 3, 2024

If pytextrank is installed via pip, importing pytextrank prints out the root directory where it's installed.

Steps To Reproduce

With Docker using the python:3.12 image, run:

$ pip install pytextrank
$ python -c "import pytextrank"
/usr/local/lib/python3.12/site-packages
$ pip freeze | grep pytextrank
pytextrank==3.3.0

Discussion

The code

try:
repo_path: pathlib.Path = pathlib.Path(dirname(abspath(__file__)))
repo: Repo = Repo(repo_path.parents[0])
REPO_HASH = str(repo.head.commit)
REPO_TAGS = repo.tags
except Exception as ex: # pylint: disable=W0703
print(ex)
is trying to load git information from the installed location, but since there isn't a git repo there, it just prints the InvalidGitRepositoryError exception arguments, which is just a path.

By explicitly catching that exception, it should no longer print out some unnecessary information. This PR will still raise an other unexpected exceptions, though.

…o information.

Before, when importing pytextrank installed via pip, it would print the path
to the library.
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.

1 participant