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

Remove python2 six functionality #1072

Merged
merged 5 commits into from
Mar 2, 2022

Conversation

dorothykiz1
Copy link
Contributor

@dorothykiz1 dorothykiz1 commented Mar 2, 2022

xref #1040

This will remove six functionality in the following files;

  • asv/commands/preview.py
  • asv/graph.py
  • asv/plugins/regressions.py
  • asv/results.py
  • asv/step_detect.py
  • asv/util.py
  • test/test_results.py
  • test/test_web.py
  • test/test_workflow.py
  • test/tools.py

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Looks great. Just the raise thing is breaking the CI, and doesn't seem correct, you can simply use raise, and if the CI is green, happy to merge after that.

asv/util.py Outdated
@@ -8,6 +8,7 @@
import datetime
import json
import math
from msilib.schema import Error
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what is this, but I don't think we want it.

asv/util.py Outdated
@@ -1192,7 +1189,7 @@ def _remove_readonly(func, path, exc_info):
pass

# Reraise original error
six.reraise(*exc_info)
raise Error(*exc_info)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise Error(*exc_info)
raise

@dorothykiz1
Copy link
Contributor Author

Thanks for the suggestions @datapythonista

@datapythonista
Copy link
Member

You've got few errors you'll have to take a look at.

@@ -21,53 +18,39 @@ def check_write(value, expected, stream_encoding, preferred_encoding):
locale.getpreferredencoding = lambda: preferred_encoding

# Check writing to io.StringIO
if six.PY3:
stream = io.StringIO()
_write_with_fallback(value, stream)
Copy link
Contributor Author

@dorothykiz1 dorothykiz1 Mar 2, 2022

Choose a reason for hiding this comment

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

When I clean out PY2 lines this part breaks with the traceback below; What could i be missing?

 def check_write(value, expected, stream_encoding, preferred_encoding):
        old_getpreferredencoding = locale.getpreferredencoding
        try:
            locale.getpreferredencoding = lambda: preferred_encoding
    
            # Check writing to io.StringIO
            if six.PY3:
                stream = io.StringIO()
                with pytest.raises(TypeError):
>                   _write_with_fallback(value, stream)
E                   Failed: DID NOT RAISE <class 'TypeError'>

test/test_console.py:27: Failed
============================================ short test summary info ============================================
FAILED test/test_console.py::test_write_with_fallback - Failed: DID NOT RAISE <class 'TypeError'>

Copy link
Member

Choose a reason for hiding this comment

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

This is strange. Can you undo the specific changes that are causing the failure for now? Or if it's easier, just move the whole file with your changes to a new PR, and remove it from here. This way we can merge and forget what's working, and we can focus better on what's not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok ,let me do this

@@ -51,7 +48,7 @@ def run(cls, dest=".", top_level=None):
color_print("(2) benchmark suite in a separate repository")
color_print("")
while True:
answer = raw_input("Layout to use? [1/2] ")
answer = input("Layout to use? [1/2] ")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I change this function from python 2 raw_input() to input() I get this error. What am I doing wrong?

    def test_quickstart(tmpdir):
        tmpdir = str(tmpdir)
    
        dest = join(tmpdir, 'separate')
        os.makedirs(dest)
    
        tools.run_asv('quickstart', '--no-top-level', '--dest', dest)
    
        assert isfile(join(dest, 'asv.conf.json'))
        assert isfile(join(dest, 'benchmarks', 'benchmarks.py'))
        conf = util.load_json(join(dest, 'asv.conf.json'), js_comments=True)
        assert 'env_dir' not in conf
        assert 'html_dir' not in conf
        assert 'results_dir' not in conf
    
        dest = join(tmpdir, 'same')
        os.makedirs(dest)
    
        try:
            asv.commands.quickstart.raw_input = lambda msg: '1'
>           tools.run_asv('quickstart', '--dest', dest)

test/test_quickstart.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test/tools.py:148: in run_asv
    return args.func(args, **kwargs)
asv/commands/quickstart.py:40: in run_from_args
    return cls.run(dest=args.dest, top_level=args.top_level)
asv/commands/quickstart.py:54: in run
    answer = input("Layout to use? [1/2] ")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <_pytest.capture.DontReadFromInput object at 0x7f622daa2eb0>, args = ()

    def read(self, *args):
>       raise OSError(
            "pytest: reading from stdin while output is captured!  Consider using `-s`."
        )
E       OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.

../../../.local/lib/python3.8/site-packages/_pytest/capture.py:192: OSError
--------------------------------------------- Captured stdout call ----------------------------------------------

· Setting up new Airspeed Velocity benchmark suite.
· Edit asv.conf.json to get started.
· Setting up new Airspeed Velocity benchmark suite.

Which of the following template layouts to use:
(1) benchmark suite at the top level of the project repository
(2) benchmark suite in a separate repository

Layout to use? [1/2] 
============================================ short test summary info ============================================
FAILED test/test_quickstart.py::test_quickstart - OSError: pytest: reading from stdin while output is captured...
=============================================== 1 failed in 1.01s ===============================================

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, but same as for the other, do you mind splitting this to its own PR please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@datapythonista datapythonista merged commit bb07d9d into airspeed-velocity:master Mar 2, 2022
@datapythonista
Copy link
Member

Really nice @dorothykiz1, good job here

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