#10 Store temporary files in .cache directory
Closed 5 years ago by psss. Opened 5 years ago by lholecek.
fedora-ci/ lholecek/messages cache-dir  into  master

file modified
+1 -2
@@ -1,2 +1,1 @@ 

- schemas/*.json

- examples/*.test

+ /.cache/

file modified
+15 -10
@@ -1,26 +1,31 @@ 

+ CACHE_DIR=.cache

  

  # Convert, test and clean up by default.

  all: convert test clean

  

  # Convert yaml specification to json schema.

- SCHEMAS=$(shell ls schemas/*.yaml | sed 's/yaml/json/')

+ SCHEMAS=$(patsubst schemas/%.yaml,$(CACHE_DIR)/%.json,$(wildcard schemas/*.yaml))

  

- schemas/%.json: schemas/%.yaml

+ # Validate example messages against schemas.

+ EXAMPLES=$(patsubst %.json,%.test,$(wildcard examples/*.json))

+ 

+ $(CACHE_DIR)/%.json: schemas/%.yaml

  	@echo "Converting $*..."

- 	scripts/convert.py schemas/$*.yaml schemas/$*.json

+ 	@mkdir -p $(CACHE_DIR)

+ 	scripts/convert.py $< $@

  

  convert: $(SCHEMAS)

  

- # Validate example messages against schemas.

- EXAMPLES=$(shell ls examples/* | sed 's/json/test/')

- 

- examples/%.test: examples/%.json $(SCHEMAS)

+ $(CACHE_DIR)/%.test: examples/%.json $(SCHEMAS)

  	@echo "Checking $*... "

- 	scripts/validate.py schemas/$*.json examples/$*.json

- 	@touch examples/$*.test

+ 	scripts/validate.py $(CACHE_DIR)/$*.json $<

+ 	@touch $@

+ 

+ examples/%.test:

+ 	$(MAKE) $(CACHE_DIR)/$*.test

  

  test: $(EXAMPLES)

  

  # Clean up stuff.

  clean:

- 	rm -f schemas/*.json examples/*.test

+ 	rm -rf $(CACHE_DIR)

file modified
+2 -2
@@ -12,8 +12,8 @@ 

      if len(sys.argv) != 3:

          raise SystemExit('Usage: validate.py schema file')

      command, schema, path = sys.argv

-     resolver = jsonschema.RefResolver('file://{0}/../schemas/'.format(

-         os.path.dirname(os.path.realpath(__file__))), None)

+     schema_path = os.path.dirname(os.path.realpath(schema))

+     resolver = jsonschema.RefResolver('file://{0}/'.format(schema_path), None)

      try:

          jsonschema.validate(load(path), load(schema), resolver=resolver)

          print("Validation successful.")

Keeps temporary files out of the way.

/cc @ralph

Metadata Update from @psss:
- Request assigned

5 years ago

Good idea, thanks. I've modified the Makefile a bit to make the output of make test a bit more readable. Merged:

Pull-Request has been closed by psss

5 years ago