Skip to content

Commit

Permalink
Add workaroudn for default instalation from PyPI
Browse files Browse the repository at this point in the history
Running list-rulesets will fail for pacakge installed from PyPI

[root@b04c448e74fc /]# dnf install -y -e0 -d0 podman python3-pip
//snip

[root@b04c448e74fc /]# pip install colin==0.5.2
//snip

[root@b04c448e74fc /]# python3 -c 'import colin; print(colin.__path__)'
['/usr/local/lib/python3.9/site-packages/colin']
[root@b04c448e74fc /]# ls -l /usr/local/share/colin/rulesets/
total 8
-rw-r--r--. 1 root root  582 Mar  1 16:52 default.json
-rw-r--r--. 1 root root 1611 Mar  1 16:52 fedora.json

[root@b04c448e74fc /]# /usr/local/bin/colin list-rulesets
Ruleset directory cannot be found.
An error occurred: ColinRulesetException('Ruleset directory cannot be found.')
Error: Ruleset directory cannot be found.

There does not seems to be any trivial and reliable way how to identify
where `data_files` are installed by setuptools. There are way how to get
pkg_data but that is something different.
There fore I decided to special case /usr/local
  • Loading branch information
Lukas Slebodnik authored and lslebodn committed Mar 8, 2022
1 parent 63371c3 commit e691d11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion colin/core/ruleset/ruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,17 @@ def get_ruleset_dirs():
logger.debug("Local ruleset directory found ('%s').", local_share)
ruleset_dirs.append(local_share)

usr_local_share = os.path.join(sys.prefix, RULESET_DIRECTORY)
usr_local_share = os.path.join("/usr/local", RULESET_DIRECTORY)
if os.path.isdir(usr_local_share):
logger.debug("Global ruleset directory found ('%s').", usr_local_share)
ruleset_dirs.append(usr_local_share)

if sys.prefix != "/usr/local":
global_share = os.path.join(sys.prefix, RULESET_DIRECTORY)
if os.path.isdir(global_share):
logger.debug("Global ruleset directory found ('%s').", global_share)
ruleset_dirs.append(global_share)

if not ruleset_dirs:
msg = "Ruleset directory cannot be found."
logger.warning(msg)
Expand Down
1 change: 1 addition & 0 deletions docs/list_of_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Colin can use ruleset-files in the following directories:

- ``./rulesets/`` (subdirectory of the current working directory)
- ``~/.local/share/colin/rulesets/`` (user installation)
- ``/usr/local/share/colin/rulesets/`` (system-wide installation if `sys.prefix` is not `/usr/local`)
- `sys.prefix`_\ ``/share/colin/rulesets/`` (system-wide installation)

.. _sys.prefix: https://docs.python.org/3/library/sys.html?highlight=sys%20prefix#sys.prefix
Expand Down

0 comments on commit e691d11

Please sign in to comment.