Skip to content

Allow to override /etc dir location #6163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion avocado/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from pkg_resources import resource_exists, resource_filename

from avocado.core.settings_dispatcher import SettingsDispatcher
from avocado import paths


def sorted_dict(dict_object):
Expand Down Expand Up @@ -407,7 +408,7 @@ def _append_user_config(self):
self.all_config_paths.append(self._config_path_local)

def _prepare_base_dirs(self):
cfg_dir = "/etc"
cfg_dir = os.path.join(paths.ETCPREFIX, "/etc")
user_dir = os.path.expanduser("~")

if "VIRTUAL_ENV" in os.environ:
Expand Down
4 changes: 3 additions & 1 deletion avocado/core/utils/path.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from avocado import paths

from pkg_resources import get_distribution


Expand Down Expand Up @@ -32,7 +34,7 @@ def system_wide_or_base_path(file_path):
if os.path.isabs(file_path):
abs_path = file_path
else:
abs_path = os.path.join(os.path.sep, file_path)
abs_path = os.path.join(paths.ETCPREFIX, file_path)
if os.path.exists(abs_path):
return abs_path
return prepend_base_path(file_path)
2 changes: 2 additions & 0 deletions avocado/paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# To be overriden by setup.py
ETCPREFIX = "/"
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from subprocess import CalledProcessError, run

import setuptools.command.develop
import setuptools.command.install
from setuptools import Command, find_packages, setup

# pylint: disable=E0611
Expand Down Expand Up @@ -203,6 +204,27 @@ def run(self):
self.handle_uninstall()


class Install(setuptools.command.install.install):
"""Custom install command."""

user_options = setuptools.command.install.install.user_options + [
("etcprefix=", None, "The etc directory prefix [default: /]"),
]

def initialize_options(self):
super().initialize_options()
self.etcprefix = "/usr/local" # pylint: disable=W0201

def run(self):
pkg_dir = os.path.join(self.build_lib, 'avocado')
os.makedirs(pkg_dir, exist_ok=True)

with open(os.path.join(pkg_dir, 'paths.py'), 'w') as f:
f.write(f'ETCPREFIX = "{self.etcprefix}"')

super().run()


class SimpleCommand(Command):
"""Make Command implementation simpler."""

Expand Down Expand Up @@ -504,6 +526,7 @@ def run(self):
cmdclass={
"clean": Clean,
"develop": Develop,
"install": Install,
"lint": Linter,
"man": Man,
"plugin": Plugin,
Expand Down