Skip to content

Commit

Permalink
Always load api-paste.ini from config directory
Browse files Browse the repository at this point in the history
The file is not a python code but is actually a config file, so it
should be placed in /etc .

This migration allows us to get rid of pkg_resources which was removed
in Python 3.12 .
  • Loading branch information
kajinamit committed Oct 3, 2024
1 parent abd2359 commit f811ee6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
13 changes: 11 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import pkg_resources
import importlib.metadata

from oslo_config import cfg

ROOT = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..')
cfg.CONF.import_opt('api_paste', 'gnocchi.opts', 'api')
cfg.CONF.set_override(
name='api_paste',
override=os.path.join(ROOT, 'etc', 'gnocchi', 'api-paste.ini'),
group='api')

# -- General configuration -----------------------------------------------------

Expand Down Expand Up @@ -38,7 +47,7 @@
# built documents.
#
# The short X.Y version.
release = pkg_resources.get_distribution('gnocchi').version
release = importlib.metadata.version('gnocchi').version

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions gnocchi/rest/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import pkg_resources
import threading
import uuid

Expand Down Expand Up @@ -165,9 +164,7 @@ def load_app(conf, not_implemented_middleware=True):
cfg_path = conf.find_file(cfg_path)

if cfg_path is None or not os.path.exists(cfg_path):
LOG.debug("No api-paste configuration file found! Using default.")
cfg_path = os.path.abspath(pkg_resources.resource_filename(
__name__, "api-paste.ini"))
raise RuntimeError("No api-paste configuration file found!")

config = dict(conf=conf,
not_implemented_middleware=not_implemented_middleware)
Expand Down
7 changes: 6 additions & 1 deletion gnocchi/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ def setUp(self):
logging_level=logging.DEBUG,
skip_log_opts=True)

self.conf.set_override(
'paste_config',
os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..',
'etc', 'gnocchi', 'api-paste.ini')),
group='api')
self.index = indexer.get_driver(self.conf)

self.coord = metricd.get_coordinator_and_start(
str(uuid.uuid4()),
self.conf.coordination_url)
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ classifier =
Programming Language :: Python :: 3.11
Topic :: System :: Monitoring

[files]
data_files =
etc/gnocchi =
etc/gnocchi/api-paste.ini

[options]
packages =
gnocchi
Expand Down

0 comments on commit f811ee6

Please sign in to comment.