Coverage for /home/pradyumna/Languages/python/packages/pyprojstencil/pyprojstencil/configure.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python3
2# -*- coding:utf-8; mode:python; -*-
3#
4# Copyright 2021 Pradyumna Paranjape
5# This file is part of pyprojstencil.
6#
7# pyprojstencil is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Lesser General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# pyprojstencil is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with pyprojstencil. If not, see <https://www.gnu.org/licenses/>.
19#
20"""
21Read yaml configuration
22"""
24import os
25from dataclasses import dataclass
26from datetime import datetime
27from pathlib import Path
28from typing import Optional
30import xdgpspconf
32CONFIG_DISC = xdgpspconf.ConfDisc('ppstencil')
35@dataclass
36class PyConfig():
37 """
38 Configuration for Python project stencil.
39 Values for commonly declared variables in python projects.
40 The author must add the rest by hand.
42 Attributes:
43 project: project name
44 version: project version
45 description: project description
46 years: copyright years
47 license: project license [LGPLv3]
48 license_header: project license header [LGPLv3]
49 pyversion: compatible python version
50 author: author's displayed name
51 uname: author's user name
52 email: author's email
53 githost: host [remote] website for git
54 branch: git's initial branch [default: `pagan`]
55 url: project's url
56 keys: all class key names
57 """
58 project: Path
59 license: Path
60 license_header: str = ('#\n' +
61 '# Contact the author(s) for License terms\n' +
62 '#\n')
63 version: str = '0.0dev1'
64 description: str = 'project - description'
65 years: str = str(datetime.now().year)
66 pyversion: str = "3"
67 author: str = os.environ.get('USER', 'AUTHOR')
68 email: Optional[str] = None
69 url: Optional[str] = None
70 uname: str = author.lower().replace(" ", "_")
71 githost: str = "gitlab"
72 branch: str = "pagan"
74 def __repr__(self) -> str:
75 """
76 Representation of object
77 """
78 output = ['']
79 for key, value in self.__dict__.items():
80 output.append(f"{key}: {value}")
81 output.append('')
82 return '\n '.join(output)
85def read_config(project: Path, **kwargs) -> PyConfig:
86 """
87 Read standard configuration for project
88 """
89 project_args = list(
90 CONFIG_DISC.read_config(flatten=True,
91 custom=kwargs.get('config')).values())[0]
93 kwargs['config'] = None
95 # remove unsupplied values
96 kwargs = {key: val for key, val in kwargs.items() if val is not None}
98 project_args.update(**kwargs)
99 config = PyConfig(project=project, **project_args)
100 return config