-
Notifications
You must be signed in to change notification settings - Fork 37
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
added poethepoet package to manage repetitive development tasks #304
Conversation
added lint to firmware/scripts/rgbconv.py
Improved some docstrings in src/krux/context.py
…adability of long lines
…at lead to additional limitrof characters
added black formating to test/test_encryption.py
added a docstring to tests/test_format.py
I didn't to the time to review this PR, but while crossing my eyes over it I got afraid about the amount amount of text and comments. Will we adopt things like "param", "return" on every docstring? Redundant information confuses me, makes it harder to find things, scrolling or using "ctrl+F, H". If we go this way would rather lock the params and return types at the function declaration themselves, without comments about them. My background in programing and good practices is poor, so I would like to hear from @tadeubas and @jdlcdl too. |
@odudex, thank you for your attention. Here are some justifications:
Some of the comments are
I thinked to that lock the params and return types is better than add them to docstrings, but was afraid break the things if micropython support or not support it. If you agree, I am happy to remove the references in the docstrings and try to add them to the function declarations.
I will avoid 🤞🏾 The most of the changes were to docstrings (I can remove them as proposed above). Any changes to their functionality was avoided. Changes to the main code only occurred when pylint warned, such as calling a variable with the same name as those pre-defined by python itself. |
@odudex, checked some of the merge conflicts and fixed them according what i saw in the selfcustody/integrated_changes. Removed some of the |
I started fixing tests now, so probably some more conflicts may show up. |
Regarding Again I think if we need to comment on this, it's a sign that we need to refactor this code, change its name, its parameters, the parameter names, change the way the function/class works, break it into small pieces and/or put it in different files. |
|
||
# TODO: what this script do? | ||
""" | ||
Some documentation about this script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is self explanatory I think, it minifies the files passed as arguments. The output is the file minified (without extra new lines or code comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i wanted more details how this is done (and projected it), sorry
""" | ||
|
||
# TODO: this throw a pylint warn C0123: Use isinstance() rather than type() for a typecheck. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @qlrd These are just helpers (scripts) to serve as a tool to do something not direct related to the Krux code (like creating values to put those on code, or to help with the build process). These scripts will not ship into the Krux device... I think if you really want to change this, you could use isinstance() without any problems. We already use it a lot on the code, see for example the file wallet.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this because pylint was warning
""" | ||
return (2**number_of_bits) - 1 | ||
|
||
# TODO: this throw a pylint warn C0123: Use isinstance() rather than type() for a typecheck. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz see the comment above
|
||
|
||
if __name__ == '__main__': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those type of changes (from single quotes to double quotes), it is nice to read about it here. Basically I think we already uses single quotes for fixed small strings or constants, and double quotes to the other uses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was black
autoformating 😵💫
] | ||
|
||
# m5stickv | ||
simulate-sequence-m5stickv-about = "python simulator/simulator.py --sequence simulator/sequences/about.txt --device maixpy_m5stickv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use more the variables and less fixed names, so we have more code reuse instead of copy/paste. For example, when you use a simulator sequence you use the start of the name of the file and hit tab to use the terminal autocomplete feature, that way you don't need to figure the exact name of the file. I don't know if the terminal will autocomplete this name simulate-sequence-m5stickv-bitcoin-options
but we could remember about simulate-sequence
and then only pass the parameters (the sequence file and the device). Or simulate-sequence-m5stickv
and only pass the sequence file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can fix this changing the .sh
files, but i was afraid to break the procedures. So i coded in this manner to see what would you say.
@@ -36,48 +36,76 @@ | |||
DOCK: (440, 820), | |||
} | |||
|
|||
|
|||
def with_prefix(device): | |||
################################## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this docs or a simple comment? if it is docs, we should use triple quotes """
device = with_prefix(device) | ||
if device not in fonts: | ||
# Get the current dir of current file | ||
# to dynamically get the absolute path of bdf font |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much comments, the dirname
already tells it will return the name of the directory of the file passed. abspath
already tells it will return the absolute path of the file passed.
@@ -78,32 +79,51 @@ | |||
board.register_device(args.device) | |||
|
|||
if args.sd: | |||
# pylint: disable=unused-import |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can customize pylint so we don't have to pollute the code with all these comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
@@ -113,14 +133,25 @@ | |||
sensor.register_sequence_executor(sequence_executor) | |||
ft6x36.register_sequence_executor(sequence_executor) | |||
|
|||
################################## | |||
# Handle absolute path for files # | |||
################################## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this box, it make this looks like docs but it is a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this only to clarify that for the simulator to work on calls in the current working directory
, the full path was needed
|
||
def __init__(self, ctx): | ||
super().__init__(ctx, None) | ||
self.ctx = ctx | ||
self.utils = Utils(self.ctx) | ||
|
||
# TODO: Is it worth to define the functions inside as protected members of PubkeyView? | ||
# (to aim a better readability) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a discussion that may happen on a discussion or an issue, not on the code. But what you mean by define the function inside as protected? what functions? _save_xpub_to_sd
, _pub_key_text
, _pub_key_qr
? They are already defined in a protected manner, the function public_key()
is used and need to be callable inside the class PubkeyView
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this because pylint warns. I called protected
in the definition used by pylint, those object methods that starts _
, inside a class definition, but outside from another method. I was following the pylint standards and wanted all pass in poetry run poe lint
command. But we don't need to follow, if you prefer
def _region_legend(self, row, column): | ||
""" | ||
<DOCUMENTATION HERE> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add documentation without adding documentation plz 😆 This will make pylint to pass and nobody will see this anymore!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
return mock.mock_open(read_data=content).return_value | ||
raise OSError("(mock) Unable to open {filename}") | ||
|
||
return mock.MagicMock(side_effect=open_mock) | ||
|
||
|
||
def statvfs(_): | ||
""" | ||
TODO: proper documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to cover the tests with all this rigor, as we do with the code. And plz don't add a code docs with TODO add docs 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added TODO because i created a poe
task to follow TODOS in all the code. But wither way, agreed
b"\xb7\xb7\xe9\xc7z\xdf}\xdb\xe5\xc6\xdc\xdf\xdd4\xd3M4\xd3M4}\xf7\xdf}\xf7\xdf\xd3V", | ||
b"\xb4\xe5\xa7\x9a\xd1\xbd4\xd3M4\xd3M}\xef\xa6\xbd\xd7\x87\xdf{\xd74\xd3\xadt\xf7", | ||
b"\xb7\x1c\xdd\xbe\xb7\xe9\xfd\x9coN:\xd1\xf6\xb8}\xce6\xed\xdd\x9b\xe3\x9f<i\xcd4", | ||
b"\xd3M4\xd3M4\xd3]5\xdbOy\xe5\xe7\x9a\xd1\xbd4\xd3M4\xd3M{k\xddx\xeb~9\xdbM\x1f\xeb", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These consts are copied and pasted once to use on code as tests, so it is harder to format them like you did. They are just consts for tests, we don't need to format them that way, I think wha you did will not help anyone understand better what this const is and what it's value... we should rely on the name of the variable or a helpful comment to add better understanding of those consts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formated these because pylint
SNAP_HISTOGRAM_FAIL, | ||
# TODO: fix W0611: Unused SNAP_HISTOGRAM_FAIL imported from shared_mocks | ||
# this will be used in a near future or can be removed? | ||
# SNAP_HISTOGRAM_FAIL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is unused, just remove. If we need it in the future, we will add it again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was afraid to break a future (or wanted) implementation...
So i put the comment to just to warn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a test file, just execute the tests before your change and after poetry run pytest --cache-clear .\tests\test_camera.py
If everything it the same, it was a safe change... so you can remove this TODO comment
Thanks @tadeubas,
Maybe this can be fixed with typings in function declarations?
I put it more as a proposal from someone who is seeing the code for the first time and, when using editors or IDEs, I like to hover over a method and a class and see which inputs are valid or not, what it does, etc. (but it's my demand, it may not be from others...) |
Sure, I think we can specify the type of a parameter and the type of the return of a function, like we see on this discussion. We should just make one test to see if this will be a problem when compiling to micropython and putting on the device |
Found this From what i understand, is possible using primitives like those defined in CPython, e.g.:
But for more specialized arguments, Another comment: The MicroPython compiler itself supports type annotations, so in principle the typing module will work |
Closing PR since we need to break commits in smaller PRs |
Description
Poe the poet
Poethepoet is a nice task runner that works well with poetry.
We can define a
[tool.poe.tasks]
section onpyproject.toml
and many tasks with the followingformat:
Where the prepended
_
means that specific task cannot be called directly and commands can be nested in a array; and a task without_
can be called by:Maybe its save some time for developers, mainly in formatting, lint, testing and simulation commands.
If approved, it's worth to update
README
with these "tasks"Simulator
To enable the poe task manager in the simulator, it was necessary to change the way in which it looked for the path of some modules, from a relative way, to an absolute way.
Simulator tasks
Was added many simulator sequences that can be activated by
Where
<device>
can be one of the supported and<op>
the operation to be sequencedLint tests
When wrapping lint into multiple folders, we include some lints in the testing directory
Docstrings
Added many docstrings on test files.
What is the purpose of this pull request?