How to get `setup.cfg` metadata at the command line (Python)
Maybe using the ConfigParser Python module ? python -c “from configparser import ConfigParser; cf = ConfigParser(); cf.read(‘setup.cfg’); print(cf[‘metadata’][‘name’])”
Maybe using the ConfigParser Python module ? python -c “from configparser import ConfigParser; cf = ConfigParser(); cf.read(‘setup.cfg’); print(cf[‘metadata’][‘name’])”
To print the list of compatible tags with current versions of pip : $ path/to/pythonX.Y -m pip debug –verbose The pip debug subcommand is available since v19.2 (July 2019). To get the list of compatible tags from Python code, I recommend using the packaging library and its packaging.tags.sys_tags() function: import packaging.tags tags = packaging.tags.sys_tags() print(‘\n’.join([f'{tag.interpreter}-{tag.abi}-{tag.platform}’ … Read more
Nevermind, I solved it: src/ main.py mod/ __init__.py components/ __init__.py expander.py language_id.py utilities/ __init__.py functions.py main.py then refers to the subpackages as: from mod.components.expander import * from mod.utilities.functions import * expander.py and language_id.py have access to functions.py with: from ..utilities.functions import * But the interesting thing is that I had a text file inside the … Read more
I’ve found this snippet as an alternative solution. It’s a more graceful removal of libraries than remaking the virtualenv: pip freeze | xargs pip uninstall -y In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below): pip freeze | grep -v … Read more
After fiddling with it a bit more, I realized how to set it up, and for the sake of specificity I won’t use foo bar names. My project directory is set up as… tools/ core/ object_editor/ # files that need to use ntlib.py editor.py # see example at bottom __init__.py state_editor/ # files that need … Read more
Try to avoid calling setup.py directly, it will not properly tell pip that you’ve installed your package. With pip install -e: For local projects, the “SomeProject.egg-info” directory is created relative to the project path. This is one advantage over just using setup.py develop, which creates the “egg-info” directly relative the current working directory. More: docs … Read more
Recommended approach for pytest>=7: use the pythonpath setting Recently, pytest has added a new core plugin that supports sys.path modifications via the pythonpath configuration value. The solution is thus much simpler now and doesn’t require any workarounds anymore: pyproject.toml example: [tool.pytest.ini_options] pythonpath = [ “src” ] pytest.ini example: [pytest] pythonpath = src The path entries … Read more
There are many ways to import a python file, all with their pros and cons. Don’t just hastily pick the first import strategy that works for you or else you’ll have to rewrite the codebase later on when you find it doesn’t meet your needs. I’ll start out explaining the easiest example #1, then I’ll … Read more
I’ve found this snippet as an alternative solution. It’s a more graceful removal of libraries than remaking the virtualenv: pip freeze | xargs pip uninstall -y In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below): pip freeze | grep -v … Read more
setup.py is a python file, the presence of which is an indication that the module/package you are about to install has likely been packaged and distributed with Distutils, which is the standard for distributing Python Modules. This allows you to easily install Python packages. Often it’s enough to write: $ pip install . pip will … Read more