PK!WSioLICENSECopyright (c) 2019 Mark Gemmill. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PK!y&3 README.md### xini - eXtract pyproject.toml configs to INI `pyproject.toml` is a fantastic idea. I want all my tool configurations in my pyproject.toml file. Not all my tools support a `pyproject.toml` configuration option though, but why wait? `xini` pulls configurations from a `pyproject.toml` file for: * pytest * flake8 * coverage * pylint And generates the appropriate ini-config files. ### Install ... pip install xini #### How Does It Work? 1. Write tool configuration in the `pyproject.toml` under the appropriate "[tool.toolname]" section. This becomes the standard location for your configurations. Keep `pyproject.toml` in source control as normal. 2. Run `xini` in the root project directory where the `pyproject.toml` file exits. (`xini` does not search for `pyproject.toml` files anywhere but the current directory.) 3. `xini` generates standard named ini-config files in the current directory (e.g. .flake8, .coveragerc, etc.). Tools that use old-style ini file formats can then run using the generated config file. **No need to maintain these ini-config files in source control.** 4. Make config changes in `pyproject.toml` and run `xini` to regnerate ini-config files. #### The Future It is my sincere hope that there is no future for this project. I wish all tool developers to build support for `pyproject.toml` as a configuration option so a tool like `xini` is unnecessary. PK! 6 xini/__init__.py""" xini Extract pyproject.toml configs to ini. Usage: xini [--help] [--version] Options: -h --help Show this help message. -v --version Show xini version. """ import sys from pathlib import Path import docopt import toml __version__ = "0.2.2" class INIWriter: def __init__(self, toml_section_name, tool_inifile_name): self.toml_section_name = toml_section_name self.tool_inifile_name = tool_inifile_name self.filepath = Path.cwd() / self.tool_inifile_name self._output = [] def _write(self, content): self._output.append(content) def get_section_from_toml(self, toml_cfg): # print(toml_cfg) print(f"Searching for `{self.toml_section_name}` section...") section = toml_cfg for name in self.toml_section_name.split("."): section = section.get(name) if not section: print(f" [{self.toml_section_name}] does not exist.") break return name, section # pylint: disable=undefined-loop-variable def write_section(self, name): self._write(f"[{name}]") def _convert(self, key, value): # pylint: disable=no-else-return if isinstance(value, str): return value elif isinstance(value, bool): return "true" if value is True else "false" elif isinstance(value, (int, float)): return str(value) elif isinstance(value, (list, tuple)): slst = [self._convert(key, val) for val in value] if len(slst) <= 5: return ",".join(slst) # if there's more than 5 items in the list, place them # on separate lines, and left-align with the placement # the first value after the `key = `. joiner = f",\n" + (" " * (len(key) + 3)) return joiner.join(slst) return def write_keyvalue(self, key, value): _v = self._convert(key, value) self._write(f"{key} = {_v}") def write_ini(self, section_name, toml_cfg): if not toml_cfg: return self.write_section(section_name) for k, v in toml_cfg.items(): if isinstance(v, dict): self.write_ini(k, v) else: self.write_keyvalue(k, v) def extract_config(self, toml_cfg): section_name, section_cfg = self.get_section_from_toml(toml_cfg) if section_cfg: print(f" Extracting {self.tool_inifile_name}.") self.write_ini(section_name, section_cfg) def __str__(self): return "\n".join(self._output) def save(self): with self.filepath.open(mode="w") as _fh: _fh.write(str(self)) print(f" Saved to: {self.tool_inifile_name}.") INI_FILES = { "flake8": INIWriter("tool.flake8", ".flake8"), "pytest": INIWriter("tool.pytest", "pytest.ini"), "coverage": INIWriter("tool.coverage", ".coveragerc"), "pylint": INIWriter("tool.pylint", ".pylintrc"), } def load_toml(path_string="pyproject.toml"): pyproject = Path(path_string) if not pyproject.exists(): print("Could not find pyproject.toml file.") sys.exit(1) return toml.load(pyproject) def toml_2_ini(): toml_cfg = load_toml() for ini_cfg in INI_FILES.values(): ini_cfg.extract_config(toml_cfg) ini_cfg.save() def main(): docopt.docopt(__doc__, version=__version__) toml_2_ini() PK!iC]xini/__main__.pyimport xini xini.main() PK!Hl;v!"%xini-0.2.2.dist-info/entry_points.txtN+I/N.,()˴Vy\\PK!WSioxini-0.2.2.dist-info/LICENSECopyright (c) 2019 Mark Gemmill. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PK!HڽTUxini-0.2.2.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Hxini-0.2.2.dist-info/METADATAUQo7 ~ׯ &vRvjl5fESu;*QMGg}9$G#IT`Åk5p>BĶU~7εXtbÚ dmhI:_M 4$LדVB?FeqYmT (jA-4s۟gڵ~c(>ؖy})Ư^ȩ` .6kܐ`>K(`t:]YB[b X9I߬`u}cyo}ѻ+NV^*r}A=^>ni͡tu߼+y1~5/fS9MVY2[btr)޺TA*>:3=MRJwgFY\\zݎj];1UP^ q{| &Ē2LJ T@c_^%VAnۘ%\#!v|#Tp9eƪ:;bG2.6yL6޵OgFaΙ0aӨ-kcI-B7ŴTd )z9LosDRBg:6·*v#x`yE-8?9Cd '9F/_ B%D'CI\sS?$l| }8\J-o)&؁g]s*uU B§ha␌w,J Msktxog|+S-T^י,wR O_ q)Tp(Rhy"}R'x(JE7Wc@򌛒jEk\SvMVAɭ"Vʑl\zJdK3 ,1/~x{T}LC+/$)[CaoRj.Tf6Ԑzzj78#V%/G!x&XC85UrL7lyn7%MYfB-Y*oN")I/dp5<5:/PK!H0xini-0.2.2.dist-info/RECORDK@ཿlY#0M E(y1^unr_N5=}E*H|.㴱!4558ocg LϮ /ƃn-V)OÔ` h1tn\ ; f(o&T$y%Mm3cx ?ӓ4>o0;jfƭ5 `p t>řlSzw5p`?2Sw״[:nJeY4ӌSQW,||o|[4C>6\TN*b ;֭JusYZa*,xt:(>Hƣ^qg,WBR[Fd PK!WSioLICENSEPK!y&3 README.mdPK! 6  xini/__init__.pyPK!iC]xini/__main__.pyPK!Hl;v!"%xini-0.2.2.dist-info/entry_points.txtPK!WSioaxini-0.2.2.dist-info/LICENSEPK!HڽTU xini-0.2.2.dist-info/WHEELPK!H!!xini-0.2.2.dist-info/METADATAPK!H0"%xini-0.2.2.dist-info/RECORDPK a&