How to run python in multiple versions with tox, pip and pip-tools

Environment MacOS Catalina 10.15.7 Python 3.7.8, 3.8.6, 3.9.7 Directory structure: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 concurrent-api-client ├── .python-version ├── README.md ├── MANIFEST.in ├── requirements.in ├── requirements.testing.in ├── requirements.txt ├── setup.py ├── setup.cfg ├── tox.ini ├── src │ └── api_client │ ├── __init__.py │ ├── api_client.py │ └── ... └── tests ├── __init__.py ├── test_api_formatter.

Python dependency management by pip and pip-tools

For surviving hell of dependency management in python project, it’d good to use python toolkit libraries for dependency management like pip, pip-tools, setuptools (pytest, and tox). At this post, I write about pip, pip-tools and setuptools(setup.py). Environment MacOS Catalina 10.15.7 Python 3.9.7 Guides Python packaging user guide | tool recommendation is fine document. Tool pyenv can install multiple python versions and switch python interpreter venv can create and switch to a python virtual environment for the package package project pip : pip is the package installer for Python.

Pytest set up - How to solve ModuleNotFound error with recommended directory structure

Problem On running pytest with configuring strongly recommended directory structure in good practices in docs.pytest.org, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 setup.py src/ mypkg/ __init__.py app.py view.py tests/ __init__.py foo/ __init__.py test_view.py bar/ __init__.py test_view.py In my sample case, the directory is like: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 concurrent-api-client ├── README.

SQLite ProgrammingError - objects created in a thread can only be used in that same thread

Environment MacOS Catalina 10.15.7 Python 3.9.7 Flask 2.0.1 SQLte3 3.28.0 Problem On connecting to SQLite from Flask application , sqlite3.ProgrammingError is raised. This does not happen every time but rarely raise error after bunch of requesting calls are succeeded. The error says SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145517748224 and this is thread id 123145534537728.

Consideration about python logging and file configuration(2)

Former article (Consideration about python logging and file configuration(1)) has concerns to be updated. There is more space to improve the usage for logging library with module naming space with __name__. setting configuration by config.fileConfig is older and limited in features (e.g. filter setting is not supported) (ref. document). Instead, it’s better to use config.dictConfig and load configuration file in .json or .yml format, a format that can be loaded as python' dictionary format.

Some ways to add python path

For running python code as modules under root a package, sys.path needs to have a full absolute path in the list of it that python can recognize the package location. There are some ways to do that as below. Related post is Consideration about python logging and file configuration(2) Environment MacOS Catalina 10.15.7 Python 3.9.7 1. Append path to sys.path from python code For checking sys.path, just print it.