Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use wildcards in python setup.cfg?

Tags:

python

I have a setup.cfg configuration script in which I list a bunch local files to be installed, i.e. like following:

[files]
packages = tests
           utils

scripts = utils/Communication.ComModule.dll
    utils/Communication.DeployerLib.Controls.dll
    utils/Communication.DeployerLib.dll
    utils/Communication.RModule.Data.dll
    utils/Communication.RModule.dll
    utils/Communication.Serial.dll
    utils/Components.dll
    utils/Converters.dll
    utils/Data.dll
    utils/Log.dll
    utils/Log.Log4Net.dll
    ....

So instead of listing every single file, can I use a wildcard in order to install every dll file? Is this possible? Can I just use something like the following (to install all dll and all exe)?

[files]
packages = tests
           utils

scripts = utils/*.dll
    utils/*.exe
like image 400
Alex Avatar asked Sep 15 '25 23:09

Alex


2 Answers

No, it seems that currently neither wildcards/globbing nor something like the find: directives is supported for scripts key (https://setuptools.pypa.io/en/latest/userguide/declarative_config.html). So I don't see any other option as listing all scripts or switch back to setup.py.

However, given you want to ship .dll files living within our package, one of the following alternatives might be worth considering:

[options]
packages = utils
zip_safe = False

[options.package_data]
* = *.dll
    *.exe

or

[options]
include_package_data = True
zip_safe = False

(the latter requires to have a MANIFEST.in containing the file patterns to include). See https://setuptools.pypa.io/en/latest/userguide/datafiles.html for details. If you later need to locate a .dll installed that way from within your utils Python module, use something like

from pathlib import Path
package_path = Path(__file__).parent
dll_name = str(package_path / "Communication.Serial.dll")

or, for newer Python versions, use the functionality from importlib.

like image 168
phispi Avatar answered Sep 17 '25 15:09

phispi


You can if you add the glob module. Example:

import glob

wildcard_path = "/some/directory/*.dll"

file_list = glob.glob(wildcard_path)

The variable file_list will now be a list of all the *.dll files in /some/directory. So put your wildcard path in the config file and use glob to retrieve the actual file names.

Keep in mind that you'll need to be careful how you enter paths in the config file though. I would recommend using absolute paths in the config file so your results are consistent no matter where you run the script from. If you pass a relative path to glob, it will look for that path from the current working directory.

like image 41
skrrgwasme Avatar answered Sep 17 '25 13:09

skrrgwasme