From 4101f69cd467132e81492d77fe5cb7768aeb0844 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Sun, 14 Jun 2020 11:05:08 -0300 Subject: [PATCH] Added support for compressed YAML files. --- CHANGELOG.md | 1 + README.md | 3 ++- kiplot/__main__.py | 10 ++++++++-- tests/test_plot/test_position.py | 4 +++- tests/utils/context.py | 8 +++++--- .../simple_position_inches_csv.kiplot.yaml | 15 --------------- .../simple_position_inches_csv.kiplot.yaml.gz | Bin 0 -> 279 bytes 7 files changed, 19 insertions(+), 22 deletions(-) delete mode 100644 tests/yaml_samples/simple_position_inches_csv.kiplot.yaml create mode 100644 tests/yaml_samples/simple_position_inches_csv.kiplot.yaml.gz diff --git a/CHANGELOG.md b/CHANGELOG.md index 0714ef0e..34f1d450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - Better debug information when a BoM fails to be generated. +- Support for compressed YAML files. ### Changed - Allowed operations that doesn't involve a PCB now can run if the PCB file is missing or corrupted. diff --git a/README.md b/README.md index 2c086d18..5920285b 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,9 @@ Kiplot uses a configuration file where you can specify what *outputs* to generate. By default you'll generate all of them, but you can specify which ones from the command line. -The configuration file should be named **.kiplot.yaml*. The format used is +The configuration file should be named **.kiplot.yaml**. The format used is [YAML](https://yaml.org/). This is basically a text file with some structure. +This file can be compressed using *gzip* file format. ### The header diff --git a/kiplot/__main__.py b/kiplot/__main__.py index d571cab5..dd67cd59 100644 --- a/kiplot/__main__.py +++ b/kiplot/__main__.py @@ -9,6 +9,7 @@ __status__ = 'beta' import argparse import os import sys +import gzip from glob import glob # Import log first to set the domain @@ -91,8 +92,13 @@ def main(): cr = config_reader.CfgYamlReader(board_file) - with open(plot_config) as cf_file: - cfg = cr.read(cf_file) + try: + # The Python way ... + with gzip.open(plot_config) as cf_file: + cfg = cr.read(cf_file) + except gzip.BadGzipFile: + with open(plot_config) as cf_file: + cfg = cr.read(cf_file) # relative to CWD (absolute path overrides) outdir = os.path.join(os.getcwd(), args.out_dir) diff --git a/tests/test_plot/test_position.py b/tests/test_plot/test_position.py index 82b6b040..f961b855 100644 --- a/tests/test_plot/test_position.py +++ b/tests/test_plot/test_position.py @@ -11,6 +11,7 @@ We test (both CSV and ASCII): - without 'comment' field - with coloured logs - in quiet mode + - compressed YAML file For debug information use: pytest-3 --log-cli-level debug @@ -133,7 +134,8 @@ def test_3Rs_position_unified_th_csv(): def test_3Rs_position_inches_csv(): - ctx = context.TestContext('3Rs_position_inches_csv', '3Rs', 'simple_position_inches_csv', POS_DIR) + """ Also test a compressed configuration YAML file """ + ctx = context.TestContext('3Rs_position_inches_csv', '3Rs', 'simple_position_inches_csv', POS_DIR, yaml_compressed=True) ctx.run() pos_top = ctx.get_pos_top_csv_filename() pos_bot = ctx.get_pos_bot_csv_filename() diff --git a/tests/utils/context.py b/tests/utils/context.py index 520cb1d1..f2a1ced8 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -19,7 +19,7 @@ MODE_PCB = 0 class TestContext(object): - def __init__(self, test_name, board_name, yaml_name, sub_dir): + def __init__(self, test_name, board_name, yaml_name, sub_dir, yaml_compressed=False): # We are using PCBs self.mode = MODE_PCB # The name used for the test output dirs and other logging @@ -29,7 +29,7 @@ class TestContext(object): # The actual board file that will be loaded self._get_board_file() # The YAML file we'll use - self._get_yaml_name(yaml_name) + self._get_yaml_name(yaml_name, yaml_compressed) # The actual output dir for this run self._set_up_output_dir(pytest.config.getoption('test_dir')) # Where are we expecting to get the outputs (inside test_name) @@ -54,8 +54,10 @@ class TestContext(object): this_dir = os.path.dirname(os.path.realpath(__file__)) return os.path.join(this_dir, '../yaml_samples') - def _get_yaml_name(self, name): + def _get_yaml_name(self, name, yaml_compressed): self.yaml_file = os.path.abspath(os.path.join(self._get_yaml_dir(), name+'.kiplot.yaml')) + if yaml_compressed: + self.yaml_file += '.gz' logging.info('YAML file: '+self.yaml_file) assert os.path.isfile(self.yaml_file) diff --git a/tests/yaml_samples/simple_position_inches_csv.kiplot.yaml b/tests/yaml_samples/simple_position_inches_csv.kiplot.yaml deleted file mode 100644 index 6a01bf6f..00000000 --- a/tests/yaml_samples/simple_position_inches_csv.kiplot.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Example KiPlot config file for a basic 2-layer board -kiplot: - version: 1 - -outputs: - - - name: 'position' - comment: "Pick and place file" - type: position - dir: positiondir - options: - format: CSV # CSV or ASCII format - units: inches # millimeters or inches - separate_files_for_front_and_back: true - only_smd: true diff --git a/tests/yaml_samples/simple_position_inches_csv.kiplot.yaml.gz b/tests/yaml_samples/simple_position_inches_csv.kiplot.yaml.gz new file mode 100644 index 0000000000000000000000000000000000000000..3c2e91e9827d914623c407dbf4463c5e0db67735 GIT binary patch literal 279 zcmV+y0qFi8iwFoLEX7^|19NF@aBO8?aBp*IbZKvHUukY*Xk~L>V{>*cYiV$7Z*(qs zVQp*xMUT5~!!Qg*cYno2GGxloj@pW#L(nBafUW{9(=B1WAjw7Z_oY=AorHUINL?NA z`b{Bw#+%%HYH%se@_|_t&8dJeQWb~iv!@3ajETxLERt0=1MtPAN{R+g!;sdN*H+D- z{ESF}4Nf^#X=4<5SG9$Dx9#yXm${1Xiwro5$UdcamT zkS@O5-+^O4wEoNea=q?%ySPTtj*#d+xvCk&dkNh1BiqC;-`&cY3N^M{y=rxjolA<% dYH>S~TMSxRdAC#a4_m{u!yh7M`QKat005c2gY5tS literal 0 HcmV?d00001