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 exception if the distribution is not found #472

Closed
wants to merge 3 commits into from

Conversation

Projects
None yet
2 participants
@s4heid
Copy link
Contributor

commented Mar 12, 2019

When the distribution of Cerberus cannot be found, catch the exception
instead of raising an error and exiting the program. This allows to
consume the package without installing it, e.g. as a git submodule. In
the exception case the version string is set to unknown.

Fixes #471

@funkyfuture
Copy link
Member

left a comment

looks mostly good. can you please also update the AUTHORS and CHANGES.rst document?

are you familiar with pytest's monkeypatch fixture? that would be the only feasible way to test your addition. as the problem is small here, it's actually a good opportunity to get a grip on it.

Show resolved Hide resolved cerberus/__init__.py Outdated
@funkyfuture

This comment has been minimized.

Copy link
Member

commented Mar 14, 2019

sorry, i forgot that the code to be tested it executed at module evaluation. the unit-testable approach would be to put the questionable in a function and call that from the module body. i'd say do as you like.

s4heid added a commit to s4heid/cerberus that referenced this pull request Mar 14, 2019

@s4heid

This comment has been minimized.

Copy link
Contributor Author

commented Mar 14, 2019

Agreed; I also had this in mind at the beginning. Another solution would be to mock the pkg_resources.get_distribution method and patch the builtin import function. @funkyfuture wdyt?

s4heid added some commits Mar 11, 2019

Catch exception if the distribution is not found
When the distribution of Cerberus cannot be found, catch the exception
instead of raising an error and exiting the program. This allows to
consume the package without installing it, e.g. as a git submodule. In
the exception case the __version__ string is set to `unknown`.

Fixes #471

@s4heid s4heid force-pushed the s4heid:handle-distribution-error branch from 79b6c7c to 77ec23a Mar 14, 2019

@funkyfuture
Copy link
Member

left a comment

i was quiet distracted during the review, please excuse if i may have confused something on the way.

Show resolved Hide resolved cerberus/tests/conftest.py Outdated
Show resolved Hide resolved cerberus/tests/test_init.py Outdated
Show resolved Hide resolved cerberus/tests/conftest.py Outdated
Show resolved Hide resolved cerberus/tests/test_init.py Outdated
Refactor the tests for the distribution version
This includes:
* moving the tests from test_init.py into test_assorted.py
* rely on PYTHON_VERSION variable rather than the nested try/except
* monkeypatch inside the test function and get rid of cerberus fixture
@s4heid

This comment has been minimized.

Copy link
Contributor Author

commented Mar 15, 2019

Thanks for the review, @funkyfuture. Your suggestions made perfect sense to me.

@funkyfuture
Copy link
Member

left a comment

that's perfect.

@funkyfuture

This comment has been minimized.

Copy link
Member

commented Mar 16, 2019

merged w/ 7896257

@funkyfuture

This comment has been minimized.

Copy link
Member

commented Mar 16, 2019

thanks a lot for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.