Skip to content
This repository was archived by the owner on Sep 8, 2024. It is now read-only.

Bugfix/issue 2727 #2740

Closed
wants to merge 11 commits into from
Closed

Bugfix/issue 2727 #2740

wants to merge 11 commits into from

Conversation

dzekem
Copy link
Contributor

@dzekem dzekem commented Oct 27, 2020

No description provided.

@pep8speaks
Copy link

pep8speaks commented Oct 27, 2020

Hello @dzekem! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 136:13: E128 continuation line under-indented for visual indent

Line 102:44: W291 trailing whitespace

Line 76:80: E501 line too long (82 > 79 characters)
Line 77:80: E501 line too long (89 > 79 characters)

Line 86:80: E501 line too long (84 > 79 characters)

Comment last updated at 2020-11-18 15:57:29 UTC

@devops-mycroft devops-mycroft added the CLA: Needed Need signed CLA from https://mycroft.ai/cla label Oct 27, 2020
@devops-mycroft
Copy link

Hello, @dzekem, thank you for helping with the Mycroft project! We welcome everyone
into the community and greatly appreciate your help as we work to build an AI
for Everyone.

To protect yourself, the project, and users of Mycroft technologies we require
a Contributor Licensing Agreement (CLA) before accepting any code
contribution. This agreement makes it crystal clear that along with your
code you are offering a license to use it within the confines of this project.
You retain ownership of the code, this is just a license.

Please visit https://mycroft.ai/cla to initiate this one-time signing. Thank
you!

@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

@krisgesling
Copy link
Contributor

Hi Dzekem, thanks for flagging this and creating a PR to fix it!

I'm wondering if it's worth us adding a small helper function to mycroft.util, something like create_temp_path() that takes in 1 or more strings, returning these as a single path inside tempfile.gettempdir()?

Maybe something like:

import os
import tempfile 

def create_temp_path(*args):
    try:
        path = os.path.join(tempfile.gettempdir(), *args)
    except TypeError:
        path = None
	LOG.error('Could not create a temp path, create_temp_path() only accepts Strings')
    return path

This would mean we can use it across Mycroft in a more simplified fashion:

from mycroft.util import create_temp_path

temp_directory = create_temp_path('mycroft')
temp_file = create_temp_path('somefile.ext')

I haven't seen a CLA request come through so please let me know if you run into any problems or have questions about it.

I also saw the Github weirdness on this PR, it's really easy to do and happens to all of us. I'd suggest rebasing your PR off the dev branch. There's instructions for this in our contributing guidelines but again shout out if you run into problems.

For the PEP8 issues I'd suggest using an automated tool like autopep8 to check and fix these. They all seem like tiny issues, but enforcing this helps us keep the codebase smaller, cleaner and more consistent which makes it easier to read.

If you aren't already feel free to join us in Mycroft Chat, the dev channel is a good place to ask questions on all of the above.

Thanks

@krisgesling krisgesling added the Status: Work in progress PR being actively worked on, not yet ready for review. label Oct 28, 2020
@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

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

Generally looks great, thanks for fixing these issues!

I had a couple of nit-picks to keep the coding style in line with the current file. The big issues I saw was a changed path and a small typo in a function call

mixer.setvolume(prev_vol)
play_wav("/tmp/test.wav").communicate()
play_wavv(os.path.join(tempfile.gettempdir(), "test.wav").communicate()
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo, should be play_wav

new_config = {'opt_in': enable}
user_config = LocalConf(USER_CONFIG)
new_config={'opt_in': enable}
user_config=LocalConf(USER_CONFIG)
Copy link
Collaborator

Choose a reason for hiding this comment

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

spaces around = signs. Here and a lot of places

Copy link
Contributor

Choose a reason for hiding this comment

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

something is confusing autopep8 in this file, it intentionally removes the white spaces here...
I've just spent far too long messing with my config but it only seems to happen for this file.

Going to resort to manually hitting the space bar 🤯

Copy link
Contributor

Choose a reason for hiding this comment

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

and the problem was OBVIOUSLY (read - not obviously) a missing closing parentheses on line 134 🤦

also apologies to @dzekem when I peeked into this PR I thought you hadn't responded to the change requests, but I see now that you ran autopep8 on everything it was just masked by this obscure typo!

@@ -98,7 +99,8 @@ class Lock: # python 3+ 'class Lock'

#
# Class constants
DIRECTORY = '/tmp/mycroft'
DIRECTORY = os.path.join(tempfile.gettempdir(),
"mycroft", "ipc") # '/tmp/mycroft'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to change the directory from /tmp/mycroft to /tmp/mycroft/ipc

import sys
from datetime import datetime
from time import time

Copy link
Collaborator

Choose a reason for hiding this comment

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

This space should remain here I think since above are builtin packages and msm is a non-system package but not included in the mycroft module

if exists('/tmp/mycroft'):
rmtree('/tmp/mycroft')
if exists(os.path.join(tempfile.gettempdir(), "mycroft")):
rmtree(os.path.join(tempfile.gettempdir(), "mycroft"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

use ' like the rest of the file to keep it consistent. (here and other places in this file)

@forslund
Copy link
Collaborator

@krisgesling we do have a similar function in the utils ensure_directory_exists() which will create a directory if missing.

'-f', '--filename', dest='filename', default="/tmp/test.wav",
help="Filename for saved audio (Default: /tmp/test.wav)")
'-f', '--filename', dest='filename', default=os.path.join(tempfile.gettempdir(), "test.wav"),
help="Filename for saved audio (Default: os.path.join(tempfile.gettempdir(), "test.wav")")
Copy link
Collaborator

Choose a reason for hiding this comment

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

here you should probably do
Saw this flagged by travis, it should probably be

         help="Filename for saved audio (Default: {}".format(os.path.join(tempfile.gettempdir(), "test.wav")))

@krisgesling krisgesling linked an issue Oct 30, 2020 that may be closed by this pull request
@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

1 similar comment
@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

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

Seems to be a couple of minor issues still. But we're getting there :)

import sys
import os
import tempfile
Copy link
Collaborator

Choose a reason for hiding this comment

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

imported twice now?

@@ -220,7 +223,7 @@ class EnclosureWriter(Thread):
Note: A command has to end with a line break
"""

def __init__(self, serial, bus, size=16):
def __init__(self, serial, bus, size = 16):
Copy link
Collaborator

Choose a reason for hiding this comment

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

In function-calls there should be no spaces around =.

It's weird but that's the pep8 style :/

mixer.setvolume(prev_vol)
play_wav("/tmp/test.wav").communicate()
play_wav(os.path.join(tempfile.gettempdir(), 'test.wav').communicate()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this line is missing a closing parenthesis )

@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

@@ -135,7 +134,7 @@ def process(self, data):
time.sleep(0.5) # Prevents recording the loud button press
record(os.path.join(tempfile.gettempdir(), 'test.wav'), 3.0)
mixer.setvolume(prev_vol)
play_wav(os.path.join(tempfile.gettempdir(), 'test.wav').communicate()
play_wav(os.path.join(tempfile.gettempdir(), 'test.wav').communicate())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about this but I think it should be

            play_wav(os.path.join(tempfile.gettempdir(), 'test.wav')).communicate()

since play_wav returns a subprocess object we want to communicate with to ensure it's finished.

@dzekem dzekem force-pushed the bugfix/issue-2727 branch from 862cdce to 9c2c93c Compare November 8, 2020 20:22
@devops-mycroft
Copy link

Voight Kampff Integration Test Succeeded (Results)

1 similar comment
@devops-mycroft
Copy link

Voight Kampff Integration Test Succeeded (Results)

@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

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

Found two small typos in the PR.

mixer.setvolume(prev_vol)
play_wav("/tmp/test.wav").communicate()
play_wav(creat_temp_path('test.wav')).communicate()
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be create_temp_path

from threading import Event
from unittest import TestCase, mock

from mycroft.util.download import (download, _running_downloads,
_get_download_tmp)
from mycroft.util import create_temp_path
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be from mycroft.util.file_utils import create_temp_path

@devops-mycroft
Copy link

Voight Kampff Integration Test Succeeded (Results)

@dzekem
Copy link
Contributor Author

dzekem commented Nov 12, 2020

@krisgesling @forslund

I've sent a CLA request and it's been days no reply yet.

Also thank you for the suggestion of using a function which I have made use of where necessary in the code

@krisgesling
Copy link
Contributor

Hey sorry about that, there's still some manual steps in our CLA process and I missed the email.

You should now have an email from HelloSign. Let me know if it doesn't show up or you have any questions about it :)

@dzekem
Copy link
Contributor Author

dzekem commented Nov 12, 2020

Thank you I've signed and submitted it.

@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

@devs-mycroft devs-mycroft added CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) and removed CLA: Needed Need signed CLA from https://mycroft.ai/cla labels Nov 18, 2020
@devops-mycroft
Copy link

Voight Kampff Integration Test Failed (Results)

@PureTryOut
Copy link
Contributor

Can't this be closed now #2892 is merged?

@krisgesling
Copy link
Contributor

Indeed - thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) hacktoberfest-accepted Status: Work in progress PR being actively worked on, not yet ready for review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replacing hard coded /tmp/ for some instances in the code
7 participants