github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/clients/Makefile (about)

     1  PACKAGE_NAME := bacalhau-apiclient
     2  SWAGGER_JSON := ../docs/swagger.json
     3  VERSION := $(shell git describe --tags --abbrev=0 | tr -d v).post4
     4  
     5  #set cmd to be swagger-codegen if that doesnt exist make it the java command
     6  #swagger-codegen is supported by brew install swagger-codegen@2
     7  #the java command is supported by the docker image swaggerapi/swagger-codegen-cli
     8  SWAGGER ?= swagger-codegen
     9  ifeq ($(shell which ${SWAGGER}),)
    10  SWAGGER := $(shell echo "${HOME}/bin/swagger-codegen-cli.jar")
    11  ifeq ($(shell ls -1 ${SWAGGER}),)
    12  $(info No swagger-codegen found?)
    13  endif
    14  endif
    15  
    16  .PHONY: all
    17  all: $(patsubst %,%/,$(shell cat supported_langs)) pypi-build pypi-upload
    18  	
    19  
    20  %-config.json: config.json.template
    21  	cat $< | \
    22  		sed -e "s/VERSION/${VERSION}/g" | \
    23  		sed -e "s/PACKAGE-NAME/${PACKAGE_NAME}/g" > $@
    24  
    25  UNDERSCORE_PACKAGE_NAME=$(subst -,_,${PACKAGE_NAME})
    26  
    27  .INTERMEDIATE: python-config.json
    28  python-config.json: config.json.template
    29  	cat $< | \
    30  		sed -e "s/VERSION/${VERSION}/g" | \
    31  		sed -e "s/PACKAGE-NAME/${UNDERSCORE_PACKAGE_NAME}/g"> $@
    32  
    33  python/: python-config.json ${SWAGGER_JSON}
    34  	# swagger codegen names the generated methods after the related endpoint @ID annotation (e.g. pkg/requester/publicapi/submit)
    35  	# this results into a names that are not quite user-friendly (e.g. pkgrequesterpublicapisubmit)
    36  	# futhermore, codegen does not allow overriding the prefix name for python
    37  	# thus, we patch the swagger spec file to remove the prefix above
    38  	# TODO: remove the line below when https://github.com/swagger-api/swagger-codegen/issues/11993 is addressed
    39  	cat ${SWAGGER_JSON} | sed -e 's/model.//g;s/publicapi.//g;s/pkg\/requester//g;s/types.//g' | tee ./swagger-edited-tmp.json >> /dev/null
    40  	
    41  	jq '.info += {"version":"${VERSION}"}' ./swagger-edited-tmp.json > ./swagger-edited.json
    42  
    43  	# generate python client
    44  	rm -rf python/ && ${SWAGGER} generate \
    45  		-i ./swagger-edited.json \
    46  		-l python \
    47  		-o python/ \
    48  		-c python-config.json \
    49  		--remove-operation-id-prefix \
    50  		-Dapis -DapiTests=false -DapiDocs=true \
    51  		-Dmodels -DmodelTests=false -DmodelDocs=true \
    52  		-DsupportingFiles=true
    53  
    54  	# patch package version
    55  	cat pyproject.toml.template | sed -e "s/VERSION/${VERSION}/g" > python/pyproject.toml
    56  	# patch README
    57  	cat python/README.md | sed -e "s/Python 2.7 and 3.4+/Python 3.6+/g" | tee python/README.md
    58  
    59  	# clean up 
    60  	rm ./swagger-edited*.json || true
    61  	rm python/git_push.sh || true
    62  	rm python/.travis.yml || true
    63  	rm pyproject.toml || true
    64  	cp ../LICENSE python/LICENSE
    65  
    66  pypi-build: python/
    67  	cd python && python3 -m pip install --upgrade build && python3 -m build
    68  
    69  pypi-upload: pypi-build
    70  	cd python && \
    71  	python3 -m pip install --upgrade twine && \
    72  	python3 -m twine upload \
    73  		--non-interactive \
    74  		--disable-progress-bar \
    75  		--skip-existing \
    76  		-u __token__ -p ${PYPI_TOKEN} \
    77  		dist/*
    78  
    79  .PHONY: clean
    80  clean: $(shell find . -type d -depth 1 -not -name bacalhau_sdk)
    81  	$(RM) -r $^
    82  	$(RM) *-config.json
    83  	$(RM) ./swagger-edited.json