Skip to content

Fixing import paths of memap.py when excuted as a script #7673

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

Merged
merged 1 commit into from
Aug 25, 2018

Conversation

bridadan
Copy link
Contributor

@bridadan bridadan commented Aug 1, 2018

Description

This allows the memap.py script to be executed directly. On master, it currently throws an error:

$python mbed-os\tools\memap.py --help
Traceback (most recent call last):
  File "mbed-os\tools\memap.py", line 20, in <module>
    from .utils import (argparse_filestring_type, argparse_lowercase_hyphen_type,
ValueError: Attempted relative import in non-package

This patch was tested with Python version 2.7.13.

FYI @dlfryar

Pull request type

[x] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

@dlfryar-zz
Copy link
Contributor

cc: @jflynn129

@cmonr
Copy link
Contributor

cmonr commented Aug 2, 2018

LGTM, but what I don't get is why other tools aren't affected in the same way. An example: https://github.com/ARMmbed/mbed-os/blob/master/tools/build_api.py#L36

@bridadan
Copy link
Contributor Author

bridadan commented Aug 2, 2018

I believe its because those files aren't directly invoked. Instead, they're imported by the "front-line" scripts (make.py, build.py, etc). memap.py can be one of these "front-line" scripts, however its typically just called by make.py via the build_project() function:

mbed-os/tools/build_api.py

Lines 566 to 582 in 8755e56

memap_instance = getattr(toolchain, 'memap_instance', None)
memap_table = ''
if memap_instance:
# Write output to stdout in text (pretty table) format
memap_table = memap_instance.generate_output('table', stats_depth)
notify.info(memap_table)
# Write output to file in JSON format
map_out = join(build_path, name + "_map.json")
memap_instance.generate_output('json', stats_depth, map_out)
# Write output to file in CSV format for the CI
map_csv = join(build_path, name + "_map.csv")
memap_instance.generate_output('csv-ci', stats_depth, map_csv)
map_html = join(build_path, name + "_map.html")
memap_instance.generate_output('html', stats_depth, map_html)

The frontline scripts add the proper directories to the path so all the imported files get the same path.

tools/memap.py Outdated
@@ -18,7 +23,7 @@
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment

from .utils import (argparse_filestring_type, argparse_lowercase_hyphen_type,
from tools.utils import (argparse_filestring_type, argparse_lowercase_hyphen_type,
argparse_uppercase_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct indentation 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.

Ok, I updated it to match build_api.py.

@bridadan bridadan force-pushed the allow_memap_script_to_execute_alone branch from 25e5135 to 59427db Compare August 2, 2018 19:37
@cmonr
Copy link
Contributor

cmonr commented Aug 2, 2018

Interesting. @bridadan please take a look at the travis failure.
@geky Would you happen to know why this PR failed the particular littlefs test?

@geky
Copy link
Contributor

geky commented Aug 2, 2018

Would you happen to know why this PR failed the particular littlefs test?

Do you mean the equeue test?

It's a little test of the internal event queue logic using POSIX calls. This was probably a mistake, because if Travis is under heavy load or just not processing jobs, the timing functions can sway >100ms and cause the tests to fail. Last time this happened was ~5 months ago. We should move the equeue tests to just simulate the timer on a tick.

@cmonr
Copy link
Contributor

cmonr commented Aug 14, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

Build : SUCCESS

Build number : 2797
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7673/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 14, 2018

/morph test

@cmonr
Copy link
Contributor

cmonr commented Aug 17, 2018

Crud. Looks like this needs a rebase.

@bridadan bridadan force-pushed the allow_memap_script_to_execute_alone branch from 59427db to b5a187d Compare August 20, 2018 14:05
@bridadan
Copy link
Contributor Author

Rebased!

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 20, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 20, 2018

Build : SUCCESS

Build number : 2844
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7673/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 20, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 21, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 21, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 21, 2018

Timing failure points to issue not being with PR.

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 22, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 24, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 24, 2018

@adbridge
Copy link
Contributor

adbridge commented Sep 7, 2018

Based on top of changes that only went into 5.10 and this fix will already be present there.

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.

8 participants