Skip to content

Commit 7f696cc

Browse files
authored
Merge pull request #228 from aliceinwire/obs_workflow
(config example): Move config example to kcidev/_data/
2 parents 7ea02ec + e657371 commit 7f696cc

File tree

3 files changed

+12
-46
lines changed

3 files changed

+12
-46
lines changed

kcidev/subcommands/config.py

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import logging
55
import os
6-
import shutil
6+
from importlib.resources import files
7+
from pathlib import Path
78

89
import click
910

@@ -36,8 +37,6 @@ def check_configuration(settings):
3637

3738

3839
def add_config(fpath):
39-
config = None
40-
example_configuration = ".kci-dev.toml.example"
4140
fpath = os.path.expandvars(fpath)
4241
fpath = os.path.expanduser(fpath)
4342
fpath = os.path.join(fpath)
@@ -56,48 +55,16 @@ def add_config(fpath):
5655
raise click.Abort()
5756

5857
kci_msg("Config file not present, adding a config file to " + fpath)
59-
# Installed with Poetry
60-
poetry_example_configuration = os.path.join(
61-
os.path.dirname(__file__), "../..", example_configuration
62-
)
63-
poetry_example_configuration = os.path.normpath(poetry_example_configuration)
64-
logging.debug(f"Checking for Poetry template at: {poetry_example_configuration}")
65-
if os.path.isfile(poetry_example_configuration):
66-
logging.info(f"Found Poetry template configuration")
67-
config = True
68-
if not os.path.exists(dpath) and dpath != "":
69-
# copy config
70-
logging.debug(f"Creating directory: {dpath}")
71-
os.makedirs(dpath)
72-
logging.info(f"Copying template configuration to: {fpath}")
73-
shutil.copyfile(poetry_example_configuration, fpath)
74-
75-
# Installed with PyPI
76-
pypi_example_configuration = os.path.join(
77-
os.path.dirname(__file__), "..", example_configuration
78-
)
79-
pypi_example_configuration = os.path.normpath(pypi_example_configuration)
80-
logging.debug(f"Checking for PyPI template at: {pypi_example_configuration}")
81-
if os.path.isfile(pypi_example_configuration):
82-
logging.info(f"Found PyPI template configuration")
83-
config = True
84-
if not os.path.exists(dpath) and dpath != "":
85-
# copy config
86-
logging.debug(f"Creating directory: {dpath}")
87-
os.makedirs(dpath)
88-
logging.info(f"Copying template configuration to: {fpath}")
89-
shutil.copyfile(pypi_example_configuration, fpath)
90-
91-
if not config:
92-
logging.error("No template configuration file found")
93-
logging.error(f"Searched at: {poetry_example_configuration}")
94-
logging.error(f"Searched at: {pypi_example_configuration}")
95-
kci_err(f"No template configfile found at:")
96-
kci_err(poetry_example_configuration)
97-
kci_err(pypi_example_configuration)
98-
raise click.Abort()
99-
else:
100-
logging.info(f"Configuration file successfully created at: {fpath}")
58+
# Install config
59+
if not os.path.exists(dpath) and dpath != "":
60+
# copy config
61+
logging.debug(f"Creating directory: {dpath}")
62+
os.makedirs(dpath)
63+
example_config = (files("kcidev._data") / "kci-dev.toml.example").read_text()
64+
Path(fpath).write_text(example_config, encoding="utf-8")
65+
os.chmod(fpath, 0o600)
66+
67+
logging.info(f"Configuration file successfully created at: {fpath}")
10168

10269

10370
@click.command(

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ packages = [
99
{include = "kcidev", format = ["sdist", "wheel"]},
1010
{include = "subcommands", from="kcidev", format = ["sdist", "wheel"]},
1111
{include = "libs", from="kcidev", format = ["sdist", "wheel"]},
12-
{include = ".kci-dev.toml.example", to="kcidev", format = ["sdist", "wheel"]},
1312
]
1413
repository = "https://github.com/kernelci/kci-dev"
1514
classifiers = [

0 commit comments

Comments
 (0)