January 29, 2021How to Count Number of Selected Lines in VscodeToday I wrote a CSV export with many, many columns, where in my Python code each column was calculated on a single line. So, in order to get the number of columns, I selected all related lines and in the status bar I saw the number of all selected chars! wat? solutions After some searching on Google and StackOverflow I came to the conclusion… Either a) you have to install an outdated plugin...
January 19, 2021How Can You Convert an Adobe Illustrator File (AI) to an Encapsulated Postscript File (eps)One of my web applications is using RML to render PDFs. For one PDF document template I received a new logo file which was produced with Adobe Illustrator (file extension .ai). The RML library cannot handle ai-files, but eps-files. In order to convert the file I used Ghostscript as following: gs -dNOPAUSE -dBATCH -sDEVICE=eps2write -sOutputFile=out.eps input.ai where -dNOPAUSE means “no pause after page” -dBATCH means “exit after last file” -sDEVICE selects the device -sOutputFile is the name of the - you can guess it - output file P....
January 19, 2021Which Image Formats Are Supported by ReportLab's PDF LibraryReportLab is an open source library for generating PDFs, written in Python. While ReportLab is absolutely battle tested, even Wikipedia uses it for PDF generation, documentation lacks a bit. I could not find a reliable source for supported image formats. Also, there is both an open source and a commercial license for ReportLab, with different feature sets. The latter one is supposed to be able to treat PDFs as image files, which then can be embedded....
January 11, 2021How to Install a Python Package Directly From a Git Branch From GitHubBernát Gábor is currently working on a complete rewrite for tox. I alpha-tested the latest release (4.0.0a2), and reported a couple of problems. Within a day Bernát published some fixes on the rewrite branch, and asked me to test it. That means there is no new package on PyPI, yet. So, I had to install tox directly from GitHub, to be exact, from the rewrite branch: pip install git+https://github.com/tox-dev/tox@rewrite or more general...
December 4, 2020How to Check Support Status for Installed PackagesWhen you install a package from the package repository on Ubuntu LTS, the package will be maintained for 5 years, right? No! At least, not necessarily. Basically, you need to understand that there are different repository types for Ubuntu: type maintained by canonical floss guaranteed support in years main yes yes 5 restricted yes no ? universe no yes ? multiverse no no ? (There are more than those listed (e....
December 3, 2020What Is the Difference Between Invoking `pytest` and `python -m pytest`Yesterday, I was recommended to have a look at Shopyo - Open inventory management and Point of sales. As I am passionate about testing and CI, I always have a look at configuration files for newly discovered projects. After I cloned the repository, I tried to run the tests. So, without having a look into the documentation ( :-/ ), I created a virtual env installed the dependencies ran pytest from the root of the project … and got a ModuleNotFoundError The friendly maintainers of the projects pointed me in the right direction on how to run tests for this project:...
November 18, 2020How to Delete Complete Lines With Search ReplaceFor many years now, I had been using Jetbrain’s IntelliJ Idea Ultimate happily also for my Python development. Due to “legacy issues”, I had to apply many # noinspection annotations to my source code. Now, that I switched to VS Code, I want to get rid of actually 821 # noinspection annotations :-) A simple search for # noinspection.* and a replacement with basically nothing would work, but that would leave behind many blank lines....
November 16, 2020How to Configure Git for Testingbatou is a configuration management and deployment tool, comparable to Ansible. With batou you can deploy applications, also from git repositories. For this batou uses the git binary - so this has to be tested somehow. One test looks like this… def test_git_remote_init_pull(tmpdir): source = tmpdir.mkdir("source") dest = tmpdir.mkdir("dest") with source.as_cwd(): remote_core.cmd("git init") source.join("foo.txt").write("bar") remote_core.cmd("git add foo.txt") remote_core.cmd("git commit -m bar") remote_core.ensure_repository(str(dest), "git-bundle") remote_core.git_pull_code(str(source), "master") remote_core.git_update_working_copy("master") assert "bar" == dest.join("foo.txt").read() … and worked in some environments, even on Travis, but failed on my Ubuntu box, and later also on GH Actions:...
November 13, 2020How to Group Data Easily With SimpleNamespaceWhile you could use the usual suspects, like a dictionary, a NamedTuple, a dataclass, or even an “empty” class, there is yet another way: SimpleNamespace. >>> from types import SimpleNamespace >>> simple_ns = SimpleNamespace(a=1, b="two") >>> simple_ns namespace(a=1, b='two') >>> simple_ns.a 1 >>> simple_ns.b 'two' >>> implementation This builtin is implemented in C, but the Python docs show how it would look like in Python: class SimpleNamespace: def __init__(self, /, **kwargs): self....
October 30, 2020How to Fix Broken Tests on Travis for PyPyThe xenial build of pypy on Travis CI links against OpenSSL 1.0.2, which causes pip install cryptography to fail with RuntimeError: You are linking against OpenSSL 1.0.2, which is no longer supported by the OpenSSL project. To use this version of cryptography you need to upgrade to a newer version of OpenSSL. For this version only you can also set the environment variable CRYPTOGRAPHY_ALLOW_OPENSSL_102 to allow OpenSSL 1.0.2. Marius found the solution, see https://github....