In the middle of the desert you can say anything you want
To Export settings, File -> Manage IDE Settings -> Export Settings 1
Interestingly the first google result was the similarly named Share your IDE settings | PyCharm, which is a feature in Pycharm Professional and is closer to syncing than to exporting.
Stumbled yet again1 on mentions of IPython and decided to look into it, prev. assumption being that it’s the same or almost the same thing as Jupyter Notebook. (Also the
ipdb stands for IPython-enabled, apparently).
It’s not., it’s a separate interactive superset of the Python cli that’s runnable by itself through
python3 -m IPython.
Which in turn feels like a better / more interactive shell that can also do magic commands (
%xxx) that I’ve seen in Google Colab / Jupyter; additionally understands bash stuff as-is and does other cool stuff. Definitely worth looking into.
ALSO the same article1 mentions a way of using IPython inside
ipdb> from IPython import embed ipdb> embed() # drop into an IPython session. # Any variables you define or modify here # will not affect program execution
To run a program with ipdb without editing the source and dropping in an ipdb prompt when if it breaks from shell:
python3 -m ipdb script.py
Took another look at the official docu 26.2. pdb — The Python Debugger — Python 2.7.18 documentation:
pprints the expression following,
In Python 3.10+, Unions (
Union[str, Path]) can be also written as
str | Path1
… And the syntax
str or Path I’ve been using and getting no errors from, apparently, doesn’t exist at all. TODO - why did it work?
Pycharm froze, killed it with killall I think, didn’t see it in the process list even (
ps aux | grep pycharm) but couldn’t start it either because it detected an already running instance and refused to start.
The Internet1 suggested
pkill -f pycharm killed whatever was remaining, and I could start it after that. Still no idea what happened though.
Pressing u / d moves you through the individual frames of the stack.
Also TODO look into using it to run stuff and debug automatically on fail, without editing the source code.1
An Inverted index - Wikipedia is a mapping from content to its location/name, as opposed to the usual case of name-to-content. One use is searching.
This is part two of 211209-1354 Python testing basics with poetry and pytest. Fixtures scopes work similarly to the various setup/teardown functions of unittest, can be per module/class/etc.
@pytest.mark.xfail(reason="Reason why it's supposed to fail") def test_...
For a specific exception, you assert that it raises that exception type and then can do asserts on the exception that is raised.
def test_whatever(): with pytest.raises(Exception) as excinfo: raise Exception("oh no") assert str(excinfo.value) == "oh no"
Regex also works (example directly from
pytest.raises() API Reference
>>> with pytest.raises(ValueError, match=r'must be \d+$'): ... raise ValueError("value must be 42") ## Services (skipped, see below) ### Creating fixtures that get used automatically ```python @pytest.fixture(autouse=True) def skip_servicetest(request, run_services): if request.... pytest.skip("skipped because X")
pyfakefs creates a fake filesystem that gets used transparently.
from pyfakefs.fake_filesystem import FakeFilesystem @pytest.fixture def common_fs(fs: FakeFilesystem): fs.create_dir(Path("/tmp/common")) fs.create_file("/tmp/common") def test_filesystem_fixture(common_filesystem): assert os.path.exists("/tmp/common") assert os.path.exists("/tmp/not_there") == False
A development approach from TDD.
Tests should be:
3A is a common pattern for structuring tests.
In a test this would look like this:
string = "ABc" result = string.upper() assert result == "ABC"
A coworker reminded be of this gem; quoting him:
The order is important. My favourite one is ‘explicit is better than implciit’
Had a big repo, wanted to clone only some folders.
The setup below automatically fetched the subfolders I added to the sparse-checkout set.
git clone --filter=blob:none --no-checkout --branch main ssh://firstname.lastname@example.org/my/repo.git cd myrepo git sparse-checkout init --cone git sparse-checkout set "activitywatch" "friends" ".task" ".timewarrior"
It boils down to creating an index (json) then using something to search in it client side
Once an index is built, Lunr seems the way to do with this: https://lunrjs.com/docs/lunr.Query.html#~Clause
It seems flexible enough, including ability to search inside taxonomies.