what does python3 -tt myscript.py do? - python-3.8

I just want to know what to expect when I run python3 -tt. Where can I find the information on python3 switches such as this? I looked on-line and in my python docs.
Thank you, sherman

This was only an argument for python2:
From the python2 docs:
Issue a warning when a source file mixes tabs and spaces for indentation in a way that makes it depend on the worth of a tab expressed in spaces. Issue an error when the option is given twice (-tt).
Since python3 doesn't allow tabs and spaced mixed this argument does not do anything.

Related

How to build numpy from source and be able to debug it in a live application?

I am currently reading the documentation for numpy, however to get a more thorough understanding of the library, it would be helpful if there was a way to debug the workflow of the library as I call a particular function.
I have tried debugging when numpy was imported as a third party module. However, when I try to step into it, it is actually stepping over.
Therefore, I am building it from source and thereby trying to build it locally in an attempt to run it.
I find the documentation provided in the numpy website for developers to be a bit vague for beginners like me.
I would highly appreciate any comments that would set me on the right path, as I have tried everything that I know of.
Thanks!
I am currently reading the documentation for numpy, however to get a more thorough understanding of the library, it would be helpful if there was a way to debug the workflow of the library as I call a particular function.
Unless you plan to fix a bug in Numpy, help Numpy developpers or you are a contributor, you should not debug Numpy directly.
I have tried debugging when numpy was imported as a third party module. However, when I try to step into it, it is actually stepping over.
By default, Numpy enable compiler optimizations like -O2 or -O3 or even using annotations in the code so to tell the compiler to use a given optimization level (so to better vectorize it for example). Such optimizations tends to make debugging harder and unreliable. The maximal optimization level for debugging should be -Og and the minimal one is -O0. Using -O1/-O2/-O3 tends to causes issues. You also need to enable debugging informations with -g.
The standard way to run and debug Numpy is to use gdb --args python runtests.py -g --python mytest.py. The -g flag should compile Numpy with compiling options -O0 -ggdb. Adding --debug-info may help you to understand if everything is built correctly. For more information see this and that. You can also see the above informations in the runtests.py script.
If you still have issues with the above method, the last desperate option is to add printf directly in the code (and take care to flush stdout frequently). It is not very clean and force Numpy to be frequently recompiled which is a bit slow but it is a pretty good solution when gdb is unstable (ie. crashes or just bogus) for example.
Thank you for contributing to Numpy.

How to stop the PNG warning: iCCP: known incorrect sRGB profile printing to console?

I am trying to run some code which cannot be altered in functionality, but it would be great if I can somehow ignore the warnings or prevent them from being printed to the console, as it congests it and makes it unreadable. Thank you.
You can try tf.autograph.set_verbosity it's used to control how much info tensorflow logs as indicated in their docs for TF2.6
tf.autograph.set_verbosity(
level=0, alsologtostdout=False
)
Check also the answers here which covers solutions for multiple versions of tensorflow and python.

ghdl-yosys-plugin compilation failed

I am about to test GHDL and Yosys as a replacement of EDA proprietary design flows, for my students. My point is about VHDL synthesis.
I have a fresh install of several tools : trellis (ECP5), yosys, nexpnr, fujprog (ulx3s).
GHDL is also installed for a longer time but it is supposed to include synthesis also (--synth option works).
ghdl -v
GHDL 1.0-dev (v0.37.0-208-g2c66a8bd) [Dunoon edition]
Compiled with GNAT Version: Community 2019 (20190517-83)
llvm code generator
It seems that I also need ghdl-yosys-plugin. However, the install does not work for me.
I get a bunch of error messages :
make GHDL=/opt/ghdl/bin/ghdl
yosys-config --exec --cxx -c --cxxflags -o ghdl.o src/ghdl.cc -fPIC -DYOSYS_ENABLE_GHDL -I/opt/ghdl/include -O
src/ghdl.cc:361:2: error: unknown type name 'Attribute'
Attribute attr = get_first_attribute (inst);
^
src/ghdl.cc:361:19: error: use of undeclared identifier 'get_first_attribute'
Attribute attr = get_first_attribute (inst);
^
src/ghdl.cc:379:7: error: use of undeclared identifier 'Id_Posedge'; did you mean 'Id_Edge'?
case Id_Posedge:
^~~~~~~~~~
Id_Edge
etc
I am missing something. Can someone help ?
Thanks in advance
JCLL
As I suspected (despite versioning that seemed correct), a fresh new install of GHDL fixed the issue.
i did some investigating: ghdl has undergone some restructuring, for proper FHS compliance. for example this commit https://github.com/ghdl/ghdl/commit/66cd5e0aa897b947533d269535fde4c0852472c2 and further commits show some renaming which ensures compliance with FHS conventions. files that used to be installed as /usr/local/include/ghdhsynth.h are now in /usr/local/include/ghdl
however because there are two completely separate pieces of software involved here (ghdl and yosys-ghdl-plugin) you have to (a) keep them in sync and (b) ensure that prior-installed ghdl headers are manually cleared out HOWEVER
manually deleting the installed files in /usr/local/include and reinstalling may not help if you cross over the threshold of commits from stable to developer releases on one but not the other, because older versions of yosys-ghdl-plugin were also not FHS convention-compliant. or, if you don't get them exactly right (i had to check the git log commit timestamps for both ghdl and ghdl-yosys-plugin in order to get a match), you get the general idea
if you really want to use a mis-matched version of ghdl and ghdl-yosys-plugin (YMMV here) then there are a few solutions:
manually copy the files in /usr/local/include/ghdl into /usr/local/include. this is a really dreadful hack that will need repeating each time you re-install ghdl.
modify the yosys-ghdl-plugin Makefile to include "-I/usr/local/include/ghdl" in CFLAGS or ALL_CFLAGS
in ghdl/synth.h and anywhere you see ghdl/synth.h used replace it with just "synth.h", likewise with synth_gates.h.
bear in mind that all of these are absolutely awful, totally not guaranteed to work, and you are way better off making sure that the versions being used are properly in sync.
it also does not help that some things from yosys latest master are also being removed, on which yosys-ghdl-plugin relies, to compile! as of writing i have found that tag yosys-1.13, ghdl-plugin commit c9b05e481423c, and ghdl commit 263c843ed49 will compile and work. however if i update to latest ghdl master (0e46300) microwatt fails to build, so i am sticking with 263c843 for now.
YMMV, hopefully however that gives you some insights rather than considering these complex and fantastically useful pieces of interlinked software to be opaque black boxes.

Intellij git bash terminal tilde key

I set git-bash for windows as default terminal in Intellij IDEA. It works but I am unable to write tilde (~) character there (Shift+~). Tried changing different options in settings but without any luck.
versions:
Windows 10
Intellij IDEA 2017.2.5
git version 2.14.2.windows.3
path to shell: "C:\Program Files (x86)\Git\bin\sh.exe" --login -i
Does anyone had similar problem and know the solution?
It is really annoying when I have to copy this character or work in seperate terminal in situation where direct view on code is preferable.
Not really a solution, but probably a more convenient workaround: you can use ALT + 126 to print tilde character.
(while keep press Alt, on your keyboard type the number 126).
I have the same issue.
I accidentally clicked on 'F6' today and this added ~ in my console.
It isn't resolve, but I guess that easier workaround.
I solved this issue by enabling the keyboard type called eliminate dead keys. In my case it is Swedish and the keyboard type on Linux Elementary OS I'm using is called Swedish (eliminate dead keys).
It is available in other languages as well including Norwegian and German.
The disadvantage is that you cannot combine these to make characters anymore.
I don't know the solution nor given in other answers work for me, so I will just share workaround I use. It's ugly, but better than copying tilde from other Window.
In ~/.bashrc file I added alias T='echo ~' (and invoked source ~/.bashrc after, to apply changes) so now everytime I need tilde I use $(T), for example ls $(T).
As other said upvoting this problem in youtrack may bring solution sooner or later - https://youtrack.jetbrains.com/issue/IDEA-152703

Key binding to interactively execute commands from Python interpreter history in order?

I sometimes test Python modules as I develop them by running a Python interactive prompt in a terminal, importing my new module and testing out the functionality. Of course, since my code is in development there are bugs, and frequent restarts of the interpreter are required. This isn't too painful when I've only executed a couple of interpreter lines before restarting: my key sequence when the interpreter restart looks like Up Up Enter Up Up Enter... but extrapolate it to 5 or more statements to be repeated and it gets seriously painful!
Of course I could put my test code into a script which I execute with python -i, but this is such a scratch activity that it doesn't seem quite "above threshold" for opening a text editor :) What I'm really pining for is the Ctrl-r behaviour from the bash shell: executing a sequence of 10 commands in sequence in bash involves finding the command in history (repeated Up or Ctrl-r for a search -- both work in the Python interpreter shell) and then just pressing Ctrl-o ten times. One of my favourite bash shell features.
The problem is that while lots of other readline binding functionality like Ctrl-a, Ctrl-e, Ctrl-r, and Ctrl-s work in the Python interpreter, Ctrl-o does not. I've not been able to find any references to this online, although perhaps the readline module can be used to add this functionality to the python prompt. Any suggestions?
Edit: Yes, I know that using the interactive interpreter is not a development methodology that scales beyond a few lines! But it is convenient for small tests, and IMO the interactiveness can help to work out whether a developing API is natural and convenient, or too heavy. So please confine the answers to the technical question of whether readline history-stepping can be made to work in python, rather than the side-opinion of whether one should or shouldn't choose to (sometimes) work this way!
Edit: Since posting I realised that I am already using the readline module to make some Python interpreter history functions work. But the Ctrl-o binding to the operate-and-get-next readline command doesn't seem to be supported, even if I put readline.parse_and_bind("Control-o: operate-and-get-next") in my PYTHONSTARTUP file.
I often test Python modules as I develop them by running a Python interactive prompt in a terminal, importing my new module and testing out the functionality.
Stop using this pattern and start writing your test code in a file and your life will be much easier.
No matter what, running that file will be less trouble.
If you make the checks automatic rather than reading the results, it will be quicker and less error-prone to check your code.
You can save that file when you're done and run it whenever you change your code or environment.
You can perform metrics on the tests, like making sure you don't have parts of your code you didn't test.
Are you familiar with the unittest module?
Answering my own question, after some discussion on the python-ideas list: despite contradictory information in some readline documentation it seems that the operate-and-get-next function is in fact defined as a bash extension to readline, not by core readline.
So that's why Ctrl-o neither behaves as hoped by default when importing the readline module in a Python interpreter session, nor when attempting to manually force this binding: the function doesn't exist in the readline library to be bound.
A Google search reveals https://bugs.launchpad.net/ipython/+bug/382638, on which the GNU readline maintainer gives reasons for not adding this functionality to core readline and says that it should be implemented by the calling application. He also says "its implementation is not complicated", although it's not obvious to me how (or whether it's even possible) to do this as a pure Python extension to the readline module behaviour.
So no, this is not possible at the moment, unless the operate-and-get-next function from bash is explicitly implemented in the Python readline module or in the interpreter itself.
This isn't exactly an answer to your question, but if that is your development style you might want to look at DreamPie. It is a GUI wrapper for the Python terminal that provides various handy shortcuts. One of these is the ability to drag-select across the interpreter display and copy only the code (not the output). You can then paste this code in and run it again. I find this handy for the type of workflow you describe.
Your best bet will be to check that project : http://ipython.org
This is an example with a history search with Ctrl+R :
EDIT
If you are running debian or derivated :
sudo apt-get install ipython