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

Dictionary for log messages #55

Merged
merged 38 commits into from
Jul 31, 2018
Merged

Dictionary for log messages #55

merged 38 commits into from
Jul 31, 2018

Conversation

Christian-B
Copy link
Member

Part of SpiNNakerManchester/spinnaker_tools#75
Does not break if merged earlier

--
Code to convert c files by replacing log_ messages

As well as code to put it back.

@coveralls
Copy link

coveralls commented May 1, 2018

Pull Request Test Coverage Report for Build 566

  • 347 of 401 (86.53%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.2%) to 91.667%

Changes Missing Coverage Covered Lines Changed/Added Lines %
spinn_utilities/make_tools/replacer.py 34 38 89.47%
spinn_utilities/executable_finder.py 1 7 14.29%
spinn_utilities/make_tools/converter.py 70 89 78.65%
spinn_utilities/make_tools/file_converter.py 240 265 90.57%
Totals Coverage Status
Change from base Build 540: -1.2%
Covered Lines: 1914
Relevant Lines: 2088

💛 - Coveralls

from .file_convertor import FileConvertor

__all__ = [
"FileConvertor"]
Copy link
Contributor

Choose a reason for hiding this comment

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

converter vs convertor ???

Copy link
Member Author

Choose a reason for hiding this comment

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

Ug the pain when even @alan-stokes notices spelling mistakes.

Fixed


class Convertor(object):
# __slots__ = [
# "_dest", "_dest_basename", "_src", "_src_basename"]
Copy link
Contributor

Choose a reason for hiding this comment

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

why commented out?

Copy link
Member Author

Choose a reason for hiding this comment

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

Planned on doing when I stopped changing my mine and then forgot.

Fixed

# __slots__ = [
# "_dest", "_dest_basename", "_src", "_src_basename"]

def __init__(self, src, dest, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

docs on what these params are would be useful. plus its a constructor, docs on its inputs always usful

Copy link
Member Author

Choose a reason for hiding this comment

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

ok done!

print("Unexpected file {}".format(source))

def _get_id(self):
RANGE_PER_DIR = 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

magic number inside function, push to class level.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok. Picky

raise Exception("mkdir failed {}".format(destination))

def _find_common_based_on_environ(self):
if 'SPINN_DIRS' not in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

make into magic_param as then if we ever change it, you only need change it in one place. this method has 2 of each already

Copy link
Member Author

Choose a reason for hiding this comment

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

"{} {}\n" Here I disagree with making this a CONSTANT or even a magic. Keep the line needing parameters with the code that provides them.

def run(self):
self._mkdir(self._dest)
with open(self._dict, 'w') as dict_f:
dict_f.write("Id,Preface,Original\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

create text as magic param

Copy link
Member Author

Choose a reason for hiding this comment

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

there called CONSTANTS

def _get_id(self):
RANGE_PER_DIR = 1000

rangefile = os.path.join(RANGE_DIR, "log.ranges")
Copy link
Contributor

Choose a reason for hiding this comment

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

log.ranges (magic name?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added CONSTANT as don't do magic

self._too_many_lines = 2
self._status = NORMAL_CODE
for self._line_num, self._text in enumerate(src_f):
if self._too_many_lines > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

self._too_many_lines not created during constructor, nor in slots

Copy link
Contributor

Choose a reason for hiding this comment

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

same for _status, _line_num, _test, _comment_start,

Copy link
Member Author

Choose a reason for hiding this comment

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

added to slots. CRITICAL!

Did not add to init as I actually prefer the never created error over the null pointer error.

Copy link
Contributor

Choose a reason for hiding this comment

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

phft to you. ill bring in rowley tomorrow and we can have a mediator on whom is right

Copy link
Member

Choose a reason for hiding this comment

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

A quick check shows that too_many_lines is set on line 60 then used in the next few lines within the same function. There is one reference outside the function where this variable is added to - however this addition seems to then be ignored... this seems incorrect; the variable can probably either be local or should be dealt with correctly later.

Copy link
Member

Choose a reason for hiding this comment

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

_text looks lime it should be passed in to the processing functions - this makes tracing it easier and the code easier to follow.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like _line_num can also be passed down?

Copy link
Member

Choose a reason for hiding this comment

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

_comment_start looks to be write-only

Copy link
Member Author

Choose a reason for hiding this comment

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

too_many_lines is added to in
_write_log_method which is called from
_process_line_in_log (and others) which is called from
_process_line (and others) which is called from
inside the for loop which does skip lines in based on -_too_many_lines

but so far falls over on a TOKEN in a /* */ style comment.
If needed could be altered to handle those as well.

Also note that is is just a safety check and not stricktly required.
Copy link
Contributor

Choose a reason for hiding this comment

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

strictly vs stricktly

Copy link
Member Author

Choose a reason for hiding this comment

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

nuked whole method

import re
import sys

TOKEN = chr(30) # Record Sperator
Copy link
Contributor

Choose a reason for hiding this comment

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

Sperator vs separator

Copy link
Contributor

Choose a reason for hiding this comment

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

chr(40) is the ( symbol. not a record separator/TOKEN. not sure if this is a good name for what your looking for

Copy link
Member

Choose a reason for hiding this comment

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

30 != 40

Copy link
Member

Choose a reason for hiding this comment

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

Technically, the correct separator would be the Unit Separator, chr(31), as that was intended to be the separator between fields (why “unit”? I don't know…) but practically it could be anything unlikely to otherwise occur in normal output so it isn't worth changing.

assert self._status == NORMAL_CODE
return self._process_line_normal_code(dest_f)

def _check_token(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole method isnt used anywhere that i can find (and wouldnt work for a function definition).

Copy link
Member Author

Choose a reason for hiding this comment

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

nuked dead code that was confusing Alan.

return self._process_line_in_log(dest_f)

def _process_line_normal_code(self, dest_f):
# Fast check
Copy link
Contributor

Choose a reason for hiding this comment

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

dont think you need the faster one. when your doing both and the second covers the first.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nuked faster method as wasted more time remembering it then it will ever save


There is aslo the assumption that the start status is not COMMENT

:param dest_f:
Copy link
Contributor

Choose a reason for hiding this comment

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

fill in docs


def _write_log_method(self, dest_f, tail=""):
self._message_id += 1
self._log_full = self._log_full.replace('""', '')
Copy link
Contributor

Choose a reason for hiding this comment

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

missing in constructor self._log_full

Copy link
Contributor

Choose a reason for hiding this comment

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

missing self._log_lines in constructor

Copy link
Member Author

Choose a reason for hiding this comment

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

Added to slots but rather not add to init

# Writing an extra newline here so need to recover that ASAP
self._too_many_lines += 1
end = tail + "\n"
if (self._log_lines <= 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant brackets

self._line_num + 1,
original[1:-1]))

def _process_chars(self, dest_f):
Copy link
Contributor

Choose a reason for hiding this comment

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

this method is way too big, break up into status level processes.


def __init__(self, dict_pointer):
self._messages = {}
rest, extension = os.path.splitext(dict_pointer)
Copy link
Contributor

Choose a reason for hiding this comment

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

extension redundant, replace with _

Copy link
Member Author

Choose a reason for hiding this comment

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

nuked



if __name__ == '__main__':
replacer = Replacer()
Copy link
Contributor

Choose a reason for hiding this comment

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

needs filling in, wont work currently. missing parameters

Copy link
Member Author

Choose a reason for hiding this comment

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

nuked broken main not needed

logger.error("Unable to find a dictionary file at {}"
.format(dict_path))

def replace(self, short):
Copy link
Contributor

Choose a reason for hiding this comment

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

am yet to find whats calling this...... more a comment to chase this up

Copy link
Contributor

Choose a reason for hiding this comment

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

buffer extractor

@Christian-B Christian-B dismissed alan-stokes’s stale review May 30, 2018 10:46

changes requested done or disagreed with.

Copy link
Member

@rowleya rowleya left a comment

Choose a reason for hiding this comment

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

Just a point of clarification...

self._log_full += (";")
self._write_log_method(dest_f, line_num)
pos = text.index(";") + 1
write_flag == pos
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be write_flag = pos?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

@rowleya rowleya merged commit eadf067 into master Jul 31, 2018
@rowleya rowleya deleted the convertor branch July 31, 2018 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants