Skip to content

Commit

Permalink
chore: Run unit tests with coverage in GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
umanamente committed Jan 16, 2024
1 parent 6ade539 commit 5acc851
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 149 deletions.
50 changes: 46 additions & 4 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,56 @@ name: Semantic Release
on:
push:
branches:
- master
- '**'
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel build pytest pytest-cov coverage
- name: Build package before tests
run: |
python -m build
pip install dist/*.whl
- name: Run tests with coverage
run: |
coverage run -m pytest tests
coverage xml
- name: Coverage report
run: coverage report

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

release:
runs-on: ubuntu-latest
concurrency: release
needs: test
if: github.ref == 'refs/heads/master'
permissions:
id-token: write
contents: write
Expand All @@ -28,9 +72,6 @@ jobs:
python -m pip install --upgrade pip
pip install setuptools wheel build # Add other dependencies if needed
- name: Build package before release
run: python -m build

- name: Python Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@master
Expand All @@ -53,3 +94,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}

41 changes: 26 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
.. These are examples of badges you might want to add to your README:
please update the URLs accordingly
.. image:: https://api.cirrus-ci.com/github/<USER>/ConfigModel.svg?branch=main
:alt: Built Status
:target: https://cirrus-ci.com/github/<USER>/ConfigModel
.. image:: https://readthedocs.org/projects/ConfigModel/badge/?version=latest
:alt: ReadTheDocs
:target: https://ConfigModel.readthedocs.io/en/stable/
.. image:: https://img.shields.io/coveralls/github/<USER>/ConfigModel/main.svg
:alt: Coveralls
:target: https://coveralls.io/r/<USER>/ConfigModel
.. image:: https://img.shields.io/pypi/v/ConfigModel.svg
:alt: PyPI-Server
:target: https://pypi.org/project/ConfigModel/
.. image:: https://img.shields.io/conda/vn/conda-forge/ConfigModel.svg
:alt: Conda-Forge
:target: https://anaconda.org/conda-forge/ConfigModel
Expand All @@ -23,9 +11,21 @@
:alt: Twitter
:target: https://twitter.com/ConfigModel
.. image:: https://img.shields.io/badge/-PyScaffold-005CA0?logo=pyscaffold
:alt: Project generated with PyScaffold
:target: https://pyscaffold.org/
.. image:: https://img.shields.io/coveralls/github/umanamente/ConfigModel/main.svg
:alt: Coveralls
:target: https://coveralls.io/r/umanamente/ConfigModel
.. image:: https://img.shields.io/pypi/v/ConfigModel.svg
:alt: PyPI-Server
:target: https://pypi.org/project/ConfigModel/

.. image:: https://readthedocs.org/projects/py-configmodel/badge/?version=latest
:target: https://py-configmodel.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://coveralls.io/repos/github/umanamente/py-configmodel/badge.svg?branch=coverage_test
:target: https://coveralls.io/github/umanamente/py-configmodel?branch=coverage_test


===========
Expand Down Expand Up @@ -130,3 +130,14 @@ Note that
#. Section names (``[account_password]``) of nested classes are automatically generated from class names, if no instances of this class are created.
#. You can reuse nested classes (``GoogleApi``) in different places of your config.



Installation
============

You can install **ConfigModel** using ``pip``:

.. code-block:: bash
pip install ConfigModel
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "alabaster"
# html_theme = "alabaster"
html_theme = "classic"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -247,7 +248,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "user_guide.tex", "ConfigModel Documentation", "VM", "manual")
("index", "user_guide.tex", "ConfigModel Documentation", "Vasily Maslyukov", "manual")
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
103 changes: 2 additions & 101 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,104 +1,5 @@
===========
ConfigModel
===========

**ConfigModel** is a Python package that allows you create a config for your
project quickly and easily.



:?: But why should I use **ConfigModel** instead of just using `configparser`?


ConfigModel offers several key advantages over the standard `configparser`:

- **Intellisense bonus**: Your IDE will be able to autocomplete your config parameters, since they are defined as class attributes.

- **Structured Configuration**: Define configurations as nested Python classes, allowing for clear, hierarchical organization.

- **Default Values**: Specify default values within class definitions, ensuring consistency and allowing to generate "distro" configs.

- **Automatic File Generation**: Automatically generate configuration files from class definitions, saving time and reducing manual errors.



Example
=======

Here is a quick example of how to use **ConfigModel**.

First, define a config for your app:

.. code-block:: python
from configmodel import ConfigModel, config_file, nested_field
# ============================
# define a config for your app
# ============================
@config_file("config.ini")
class AppConfig(ConfigModel):
color_scheme = "dark"
font_size = 12
class AccountInfo(ConfigModel):
username = "guest"
password = ""
last_login = ""
class GoogleApi(ConfigModel):
client_id = "<put your client id here>"
secret = "<put your secret here>"
photos_api = GoogleApi()
maps_api = GoogleApi()
Then, use your config:

.. code-block:: python
# ============================
# use your config
# ============================
def main():
# get config parameter
print(AppConfig.AccountInfo.username)
# set config parameters
AppConfig.AccountInfo.last_login = "2024-01-01"
AppConfig.photos_api.client_id = "1234"
AppConfig.maps_api.client_id = "5678"
It will create a config file ``config.ini`` with the following content:

.. code-block:: ini
[Global]
color_scheme = dark
font_size = 12
[account_info]
username = guest
password =
last_login = 2024-01-01
[photos_api]
client_id = 1234
secret = <put your secret here>
[maps_api]
client_id = 5678
secret = <put your secret here>
Note that

#. You can specify config file name with ``@config_file`` decorator.
#. Section names (``[account_password]``) of nested classes are automatically generated from class names, if no instances of this class are created.
#. You can reuse nested classes (``GoogleApi``) in different places of your config.
.. _readme:
.. include:: ../readme.rst


Contents
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# Tool configuration
# ==============================

[tool.pytest.ini_options]
pythonpath = [
"src",
"tests",
]


[build-system]
# AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD!
requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5"]
Expand Down
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ long_description_content_type = text/x-rst; charset=UTF-8
url = https://github.com/umanamente/py-configmodel/
# Add here related links, for example:
project_urls =
Documentation = https://github.com/umanamente/py-configmodel/
Documentation = https://py-configmodel.readthedocs.io/
Source = https://github.com/umanamente/py-configmodel/
# Changelog = https://pyscaffold.org/en/latest/changelog.html
# Tracker = https://github.com/pyscaffold/pyscaffold/issues
Changelog = https://py-configmodel.readthedocs.io/en/latest/changelog.html
Tracker = https://github.com/umanamente/py-configmodel/issues
# Conda-Forge = https://anaconda.org/conda-forge/pyscaffold
# Download = https://pypi.org/project/PyScaffold/#files
# Twitter = https://twitter.com/PyScaffold
Expand Down Expand Up @@ -66,6 +66,7 @@ testing =
setuptools
pytest
pytest-cov
coverage

[options.entry_points]
# Add here console scripts like:
Expand Down
4 changes: 2 additions & 2 deletions src/configmodel/ConfigModel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import copy
from typing import Dict, Any, Union
from typing import Dict, Any, Union, List

from configmodel.FieldBase import FieldBase
from configmodel.Logger import Log
Expand Down Expand Up @@ -218,7 +218,7 @@ def _get_field(self, field_name) -> Union[FieldInstance, None]:
return None
return self._fields[field_name]

def _get_all_fields_recursive(self) -> list[FieldInstance]:
def _get_all_fields_recursive(self) -> List[FieldInstance]:
"""
Get all fields recursively
"""
Expand Down
20 changes: 0 additions & 20 deletions src/configmodel/GlobalConfigManager.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/configmodel/SerializersFactory.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from typing import List, Type

from configmodel.SerializerIni import SerializerIni


class SerializersFactory:

SUPPORTED_SERIALIZERS: list[list[Type[SerializerIni] | list[str]]] = [
SUPPORTED_SERIALIZERS = [
[SerializerIni, [".ini"]]
]

Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

0 comments on commit 5acc851

Please sign in to comment.