-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix argparse integration requiring progressbar #87
Conversation
Right now, you cannot use the `argparse` integration without satisfying the requirements for the `progressbar` integration as well (tbielawa#86). To avoid this problem in the future, I separated the integrations into a module per integration. Now you can import only a specific integration: from bitmath.integrations.argparse import BitmathType This change is non-invasive, as the old import command will still work (and still lead to the error). Hence, no changes to tests are required.
…bielawa#86) I added a reqression test for this fix, although this could probably be done better. One should probably use different tests for different integrations. Maybe in the future it could be done like `requests` does it: enabling integrations with `extra_requirements`, so that you can install `bitmath` with `progressbar` integration via: pip install bitmath[progressbar]
The `ModuleNotFoundError` was introduced in Python 3.6.
WOW! This is quite a well thought out PR. This is one of the things I love about open source projects. Thank you for submitting this. I have errands to run this morning. I will give this a thorough review today. It looks great from what I saw already, I'm excited to try this out. A note about the progress bar stuff. Don't worry too much about it because the Fedora package universe has deprecated the old abandoned However, if you are interested in getting involved with that, there's more details in these two bugs: I haven't looked too closely into this yet. So it's entirely possible that it's a simple fix and change of dependencies. As for that travis failure. Uh. I am surprised.
I wonder what's locking it down to that strange specific level... Oh well. More fun mysteries to unravel later. Again, thank you for contributing. Stuff like this is what makes maintaining an open source project worth the effort :-) |
The Travis error you quoted occurs in the successful builds as well. It probably can be fixed by setting the coverage version explicitly in I did not look into the Python 2 build failure, as I have not used Python 2 for a very long time. I am not really interested in the |
Hi again @blochberger I was scratching my head this morning trying to pin down two errors that stood out to me.
and
it made no sense at all that Make sure diff --git a/Makefile b/Makefile
index 6267447..7d32f3e 100644
--- a/Makefile
+++ b/Makefile
@@ -210,10 +210,10 @@ ci-unittests2:
@echo "# Running Unit Tests in virtualenv"
@echo "# Using python: $(shell ./bitmathenv2/bin/python --version 2>&1)"
@echo "#############################################"
- . $(NAME)env2/bin/activate && export PYVER=PY2X && nosetests -v --with-coverage --cover-html --cover-min-percentage=90 --cover-package=bitmath tests/
+ . $(NAME)env2/bin/activate && export PYVER=PY2X && nosetests --nocapture -v --with-coverage --cover-html --cover-min-percentage=90 --cover-package=bitmath tests/
@echo "Testing argparse integration without progressbar dependency (#86)"
. $(NAME)env2/bin/activate && pip uninstall -y progressbar231
- . $(NAME)env2/bin/activate && export PYVER=PY2X && nosetests -v --with-coverage --cover-html --cover-min-percentage=90 --cover-package=bitmath tests/test_argparse_type.py
+ . $(NAME)env2/bin/activate && export PYVER=PY2X && nosetests -v --nocapture --with-coverage --cover-html --cover-min-percentage=90 --cover-package=bitmath tests/test_argparse_type.py
ci-list-deps2:
@echo "#############################################"
diff --git a/bitmath/integrations/argparse.py b/bitmath/integrations/argparse.py
index bd5fdb2..01958ad 100644
--- a/bitmath/integrations/argparse.py
+++ b/bitmath/integrations/argparse.py
@@ -26,7 +26,7 @@
import bitmath
import argparse
-
+print argparse.__file__
def BitmathType(bmstring):
"""An 'argument type' for integrations with the argparse module. And then I ran
When I have a suggestion which I tested and appeared to work just now:
--- a/bitmath/integrations/__init__.py
+++ b/bitmath/integrations/__init__.py
@@ -25,10 +25,10 @@
-from .argparse import BitmathType
+from .bmargparse import BitmathType
try:
- from .progressbar import BitmathFileTransferSpeed
+ from .bmprogressbar import BitmathFileTransferSpeed
diff --git a/tests/test_argparse_type.py b/tests/test_argparse_type.py
index 6cfba41..14ec4f6 100644
--- a/tests/test_argparse_type.py
+++ b/tests/test_argparse_type.py
@@ -30,7 +30,7 @@ Test the argparse 'BitmathType' integration
from . import TestCase
import bitmath
-from bitmath.integrations.argparse import BitmathType
+from bitmath.integrations.bmargparse import BitmathType
import argparse
import shlex
diff --git a/tests/test_progressbar.py b/tests/test_progressbar.py
index 148eeaf..304e14e 100644
--- a/tests/test_progressbar.py
+++ b/tests/test_progressbar.py
@@ -30,7 +30,7 @@ Test the progressbar 'FileTransferSpeed' integration
from . import TestCase
import bitmath
-from bitmath.integrations.progressbar import BitmathFileTransferSpeed
+from bitmath.integrations.bmprogressbar import BitmathFileTransferSpeed
import mock
import progressbar After I did that (and updated diff --git a/requirements-py3.txt b/requirements-py3.txt
index d239691..a777639 100644
--- a/requirements-py3.txt
+++ b/requirements-py3.txt
@@ -1,5 +1,5 @@
+coverage==4.0.3
python-coveralls
-coverage
mock
nose
nose-cover3
diff --git a/requirements.txt b/requirements.txt
index 863b3e7..a83f10c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
+coverage==4.0.3
python-coveralls
-coverage
mock
nose
pyflakes Thanks for submitting your bug report and this PR, Max. And more importantly, thanks for your patience while I got around to getting back to you. |
There is an error message stating that coveralls is not compatible with recent versions of the coverage dependency: ERROR: python-coveralls 2.9.1 has requirement coverage==4.0.3, but you'll have coverage 4.5.3 which is incompatible.
In Python 2.7 the integrations apparently try to import itself rather than the system libraries with the same module name [1]. Hence, a prefix was added to avoid this problem. This hopefully fixes Python 2.7 compatibility. [1] tbielawa#87 (comment)
Thanks for figuring it out, @tbielawa. Looks good now. |
@blochberger thank you so much for your contribution! This looks great. |
I split this pull request into two separate commits.
First, I separated the integrations into a module per integration. Now you can import only a specific integration:
This change is non-invasive, as the old import command will still work (and still lead to the error described in #86 ). Hence, no changes to tests are required.
Second, I added a reqression test for this fix, although this could probably be done better. One should probably use different tests for different integrations.
Maybe in the future it could be done like
requests
does it: enabling integrations withextra_requirements
, so that you can installbitmath
withprogressbar
integration via: