Skip to content

Commit 7788a44

Browse files
committed
Merge branch 'feature/stub_python_package'
Initial stub parser package to build off from: - Basic build/metadata in `pyproject.toml`. - Dynamic versioning from last Git tag (via: https://github.com/pypa/setuptools_scm/). - Stub parser file and unittest. - Updated `README.md` on basic install steps. Fixes #5.
2 parents dba0c2e + 00881e9 commit 7788a44

File tree

6 files changed

+127
-0
lines changed

6 files changed

+127
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# python_homework_config_file_parser
22
Coding Test for parsing config files from first principles
3+
4+
# Dev Notes
5+
6+
## Pre-Reqs.
7+
8+
1. Suggest configuring your python virtual environment of choice. eg.
9+
10+
```bash
11+
python -m venv .venv
12+
source .venv/bin/activate
13+
```
14+
15+
2. Install package: `pip install .`.
16+
3. _[OPTIONAL]_ Install optional dependencies: `pip install . [<group>]`, where
17+
`<group>` is one of:
18+
* `test`.
19+
20+
## Usage
21+
22+
**TODO**
23+
24+
## Testing:
25+
26+
* From repo root directory: `pytest`.

pyproject.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[project]
2+
name = "config_file_parser"
3+
dynamic = ["version"]
4+
license = {file = "LICENSE"}
5+
authors = [
6+
{ name="Craig Astill", email="[email protected]" },
7+
]
8+
description = "A small example package."
9+
readme = "README.md"
10+
requires-python = ">=3.7"
11+
keywords = ["config", "parser"]
12+
classifiers = [
13+
"Programming Language :: Python :: 3",
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: OS Independent",
16+
]
17+
18+
[project.urls]
19+
"Homepage" = "https://github.com/jackson15j/python_homework_config_file_parser"
20+
"Bug Tracker" = "https://github.com/jackson15j/python_homework_config_file_parser/issues"
21+
22+
[project.optional-dependencies]
23+
test = [
24+
"pytest >= 7.2.1",
25+
"pytest-cov >= 4.0.0",
26+
"pytest-html >= 3.2.0",
27+
]
28+
29+
[build-system]
30+
requires = ["setuptools>=62.6", "setuptools_scm[toml]>=6.2"]
31+
build-backend = "setuptools.build_meta"
32+
33+
[tool.setuptools_scm]
34+
# Version number construction and guessing based off most recent tag is done
35+
# with the following config. Going with a simple dev format, instead of the
36+
# opinonated versioning based off branches (which would be more useful on a
37+
# Release/Feature managed product.
38+
# See: https://github.com/pypa/setuptools_scm#version-number-construction.
39+
local_scheme = 'no-local-version'
40+
version_scheme = 'no-guess-dev'
41+
42+
[tool.setuptools.dynamic]
43+
# Config for dynamic versioning from last Git tag. See:
44+
# https://github.com/pypa/setuptools_scm/
45+
version = { attr = "setuptools_scm.get_version" }
46+
47+
[tool.pytest.ini_options]
48+
# Directories that are not visited by pytest collector:
49+
norecursedirs = [
50+
"*.egg",
51+
".eggs",
52+
"dist",
53+
"build"
54+
]
55+
junit_suite_name = "tests"
56+
junit_logging = "all"
57+
junit_family = "xunit2"
58+
python_files = [
59+
"test_*.py",
60+
"*_test.py",
61+
"tests.py"
62+
]
63+
# Report coverage and test output in JUnit format for CI to display, as well as
64+
# a human readable HTML.
65+
# Also dump 10 slowest tests on CLI runs for local debugging.
66+
addopts = "-ra --durations=10 --junitxml=build/test-reports/py_unittests.xml --html=build/test-reports/py_unittests.html --self-contained-html"

src/config_file_parser/__init__.py

Whitespace-only changes.

src/config_file_parser/parser.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Stub Parser to get initial testing and CI off the ground."""
2+
from typing import Union
3+
4+
5+
def get(path: str) -> Union[None, dict, tuple, list, str, int]:
6+
"""Getter than is used to look up the single/section value(s) in the parsed
7+
config from a supplied dot path.
8+
9+
:param str path: Dot notation path into the parsed config. eg.
10+
"key1.subkey7".
11+
:returns: The value of the key, whether it is a single value or a section.
12+
"""
13+
return

tests/__init__.py

Whitespace-only changes.

tests/test_parser.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Stub Parser tests."""
2+
from src.config_file_parser import parser
3+
4+
# TODO: move test data to a fixture!
5+
PARSED_DICT = {
6+
"environment": "production",
7+
"database": {
8+
"host": "mysql",
9+
"port": 3306,
10+
"username": "divido",
11+
"password": "divido",
12+
},
13+
"cache": {"redis": {"host": "redis", "port": 6379}},
14+
}
15+
16+
17+
class TestParserInitialRequirements:
18+
"""Parser tests from the initial requirements page."""
19+
20+
def test_get_returns_single_value(self):
21+
assert parser.get("database.host") == PARSED_DICT["database"]["host"]
22+
23+
def test_get_returns_section_value(self):
24+
assert parser.get("cache") == PARSED_DICT["cache"]

0 commit comments

Comments
 (0)