File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import sys
3+ from copy import copy
4+ from configparser import ConfigParser
5+ from pathlib import Path
6+ from packaging .requirements import Requirement , SpecifierSet
7+
8+ repo_root = Path (__file__ ).parent .parent
9+ setup_cfg = repo_root / "setup.cfg"
10+ reqs = repo_root / "requirements.txt"
11+ min_reqs = repo_root / "min-requirements.txt"
12+
13+ config = ConfigParser ()
14+ config .read (setup_cfg )
15+ requirements = [Requirement (req )
16+ for req in config .get ("options" , "install_requires" ).strip ().splitlines ()]
17+
18+ script_name = Path (__file__ ).relative_to (repo_root )
19+
20+ def to_min (req ):
21+ if req .specifier :
22+ req = copy (req )
23+ min_spec = [spec for spec in req .specifier if spec .operator in ('>=' , '~=' )][0 ]
24+ min_spec ._spec = ('==' , ) + min_spec ._spec [1 :]
25+ req .specifier = SpecifierSet (str (min_spec ))
26+ return req
27+
28+ lines = [f"# Auto-generated by { script_name } " , "" ]
29+
30+ # Write requirements
31+ lines [1 :- 1 ] = [str (req ) for req in requirements ]
32+ reqs .write_text ("\n " .join (lines ))
33+
34+ # Write minimum requirements
35+ lines [1 :- 1 ] = [str (to_min (req )) for req in requirements ]
36+ min_reqs .write_text ("\n " .join (lines ))
You can’t perform that action at this time.
0 commit comments