11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
3+ from typing import Sequence , List
34
45
56def python_version_check (major = 3 , minor = 6 ):
@@ -18,8 +19,50 @@ def python_version_check(major=3, minor=6):
1819
1920from setuptools import find_packages , setup
2021
22+
23+
24+ def read_reqs (file : str , path : pathlib .Path ) -> List [str ]:
25+ """"""
26+
27+ def readlines_ignore_comments (f ):
28+ """"""
29+ return [a_ for a_ in f .readlines () if "#" not in a_ and a_ ]
30+
31+ def recursive_flatten_ignore_str (seq : Sequence ) -> Sequence :
32+ """"""
33+ if not seq : # is empty Sequence
34+ return seq
35+ if isinstance (seq [0 ], str ):
36+ return seq
37+ if isinstance (seq [0 ], Sequence ):
38+ return (
39+ * recursive_flatten_ignore_str (seq [0 ]),
40+ * recursive_flatten_ignore_str (seq [1 :]),
41+ )
42+ return (* seq [:1 ], * recursive_flatten_ignore_str (seq [1 :]))
43+
44+ def unroll_nested_reqs (req_str : str , base_path : pathlib .Path ):
45+ """"""
46+ if req_str .startswith ("-r" ):
47+ with open (base_path / req_str .strip ("-r" ).strip ()) as f :
48+ return [unroll_nested_reqs (req .strip (), base_path ) for req in readlines_ignore_comments (f )]
49+ else :
50+ return (req_str ,)
51+
52+ requirements_group = []
53+ with open (str (path / file )) as f :
54+ requirements = readlines_ignore_comments (f )
55+ for requirement in requirements :
56+ requirements_group .extend (
57+ recursive_flatten_ignore_str (unroll_nested_reqs (requirement .strip (), path ))
58+ )
59+
60+ req_set = set (requirements_group )
61+ req_set .discard ("" )
62+ return list (req_set )
63+
2164with open (
22- pathlib .Path (__file__ ).parent / "projectname " / "__init__.py" , "r"
65+ pathlib .Path (__file__ ).parent / "munin_plugin_prc " / "__init__.py" , "r"
2366) as project_init_file :
2467 content = project_init_file .read ()
2568 # get version string from module
@@ -39,7 +82,7 @@ class ProjectNamePackage:
3982 def test_dependencies (self ) -> list :
4083 path = pathlib .Path (__file__ ).parent
4184 requirements_tests = []
42- with open (path / "requirements_tests.txt" ) as f :
85+ with open (path / 'requirements' / "requirements_tests.txt" ) as f :
4386 requirements = f .readlines ()
4487
4588 for requirement in requirements :
@@ -51,7 +94,7 @@ def test_dependencies(self) -> list:
5194 def setup_dependencies (self ) -> list :
5295 path = pathlib .Path (__file__ ).parent
5396 requirements_setup = []
54- with open (path / "requirements_setup.txt" ) as f :
97+ with open (path / 'requirements' / "requirements_setup.txt" ) as f :
5598 requirements = f .readlines ()
5699
57100 for requirement in requirements :
@@ -102,7 +145,7 @@ def maintainer_email(self):
102145 @property
103146 def package_data (self ):
104147 emds = [str (p ) for p in pathlib .Path (__file__ ).parent .rglob (".md" )]
105- return {"projectname " : [* emds ]}
148+ return {"munin_plugin_prc " : [* emds ]}
106149
107150 @property
108151 def entry_points (self ):
@@ -113,28 +156,24 @@ def entry_points(self):
113156 }
114157
115158 @property
116- def extras (self ):
117-
118- path = pathlib .Path (__file__ ).parent
119- """
120- requirements_xx = []
121- with open(path / "requirements_xx.txt") as f:
122- requirements = f.readlines()
123-
124- for requirement in requirements:
125- requirements_xx.append(requirement.strip())
126- """
127-
159+ def extras (self ) -> dict :
160+ """"""
128161 these_extras = {
129- # 'ExtraGroupName':['package-name; platform_system == "System(Linux,Windows)"'
130- # "xx":requirements_xx
162+ # 'ExtraName':['package-name; platform_system == "System(Linux,Windows)"'
131163 }
132164
165+ path : pathlib .Path = pathlib .Path (__file__ ).parent / "requirements"
166+
167+ for file in path .iterdir ():
168+ if file .name .startswith ("requirements_" ):
169+ group_name_ = "_" .join (file .name .strip (".txt" ).split ("_" )[1 :])
170+ these_extras [group_name_ ] = read_reqs (file .name , path )
171+
133172 all_dependencies = []
134173
135174 for group_name in these_extras :
136175 all_dependencies += these_extras [group_name ]
137- these_extras ["all" ] = all_dependencies
176+ these_extras ["all" ] = list ( set ( all_dependencies ))
138177
139178 return these_extras
140179
0 commit comments