Skip to content

Commit a310877

Browse files
committed
Clean up code structure located under python_gardenlinux_lib
Signed-off-by: Tobias Wolf <[email protected]>
1 parent d988445 commit a310877

File tree

24 files changed

+47
-1504
lines changed

24 files changed

+47
-1504
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Features:
2020

2121
**Inclusion via poetry**:
2222

23-
`gardenlinux = { git = "https://github.com/gardenlinux/python_gardenlinux_lib", rev="0.6.0" }`
23+
`gardenlinux = { git = "https://github.com/gardenlinux/python_gardenlinux_lib", rev="0.7.0" }`
2424

2525
```python
2626
from gardenlinux.features import Parser

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33

44
sys.path.insert(0, os.path.abspath("../src"))
5-
import python_gardenlinux_lib
65

76

87
# Configuration file for the Sphinx documentation builder.

docs/index.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
contain the root `toctree` directive.
55
66
python-gardenlinux-lib documentation
7-
================================
8-
.. automodule:: python_gardenlinux_lib.parse_features
7+
====================================
8+
.. automodule:: gardenlinux.apt
99
:members:
10-
.. automodule:: python_gardenlinux_lib.package_repo_info
10+
.. automodule:: gardenlinux.features
11+
:members:
12+
.. automodule:: gardenlinux.flavors
13+
:members:
14+
.. automodule:: gardenlinux.git
15+
:members:
16+
.. automodule:: gardenlinux.oci
1117
:members:
1218
.. toctree::
13-
:maxdepth: 2
19+
:maxdepth: 3
1420
:caption: Contents:
1521

1622
Indices and tables

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Contains tools to work with the features directory of gardenlinux
55
authors = ["Garden Linux Maintainers <[email protected]>"]
66
license = "Apache-2.0"
77
readme = "README.md"
8-
packages = [{include = "gardenlinux", from="src"}, {include = "python_gardenlinux_lib", from="src"}]
8+
packages = [{include = "gardenlinux", from="src"}]
99

1010
[tool.poetry.dependencies]
1111
python = "^3.13"

src/gardenlinux/flavors/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# -*- coding: utf-8 -*-
33

44
from argparse import ArgumentParser
5-
from git import Git
65
import json
76
import os
87
import sys
98

9+
from ..git import Git
10+
1011
from .parser import Parser
1112

1213

@@ -93,7 +94,7 @@ def parse_args():
9394
def main():
9495
args = parse_args()
9596

96-
repo_path = Git(".").rev_parse("--show-superproject-working-tree")
97+
repo_path = Git().root
9798
flavors_file = os.path.join(repo_path, "flavors.yaml")
9899

99100
if not os.path.isfile(flavors_file):

src/gardenlinux/git/git.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# -*- coding: utf-8 -*-
22

3+
import sys
4+
from git import Repo
35
from git import Git as _Git
6+
from os import PathLike
47
from pathlib import Path
5-
import sys
68

79
from ..logger import LoggerSetup
810

911

10-
class Git:
12+
class Git(object):
1113
"""Git operations handler."""
1214

13-
def __init__(self, logger=None):
15+
def __init__(self, git_directory=".", logger=None):
1416
"""Initialize Git handler.
1517
1618
Args:
@@ -20,11 +22,29 @@ def __init__(self, logger=None):
2022
if logger is None or not logger.hasHandlers():
2123
logger = LoggerSetup.get_logger("gardenlinux.git")
2224

25+
if not isinstance(git_directory, PathLike):
26+
git_directory = Path(git_directory)
27+
28+
if not git_directory.is_dir():
29+
raise RuntimeError(f"Git directory given is invalid: {git_directory}")
30+
31+
self._git_directory = git_directory
2332
self._logger = logger
2433

25-
def get_root(self):
34+
@property
35+
def commit_id(self):
36+
"""Get the commit ID for Git `HEAD`."""
37+
return str(self.root_repo.head.commit)
38+
39+
@property
40+
def root(self):
2641
"""Get the root directory of the current Git repository."""
27-
root_dir = Git(".").rev_parse("--show-superproject-working-tree")
28-
self.log.debug(f"Git root directory: {root_dir}")
42+
root_dir = _Git(self._git_directory).rev_parse("--show-superproject-working-tree")
43+
self._logger.debug(f"Git root directory: {root_dir}")
2944

3045
return Path(root_dir)
46+
47+
@property
48+
def root_repo(self):
49+
"""Get the root Git `Repo` instance."""
50+
return Repo(self.root)

src/python_gardenlinux_lib/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/python_gardenlinux_lib/features/__init__.py

Whitespace-only changes.

src/python_gardenlinux_lib/features/package_repo_info.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/python_gardenlinux_lib/features/parse_features.py

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)