由于python传递使用版本3作为默认值,因此需要使用corret python解释器处理版本2代码执行.我有一个小python2项目,我用它make来配置和安装python包,所以这里是我的问题:如何在里面确定python的版本Makefile?
这是我想要使用的逻辑:if(python.version == 3)python2 some_script.py2 else python3 some_script.py3
提前致谢!
python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
python_version_major := $(word 1,${python_version_full})
python_version_minor := $(word 2,${python_version_full})
python_version_patch := $(word 3,${python_version_full})
my_cmd.python.2 := python2 some_script.py2
my_cmd.python.3 := python3 some_script.py3
my_cmd := ${my_cmd.python.${python_version_major}}
all :
@echo ${python_version_full}
@echo ${python_version_major}
@echo ${python_version_minor}
@echo ${python_version_patch}
@echo ${my_cmd}
.PHONY : all
Run Code Online (Sandbox Code Playgroud)
这是一个较短的解决方案.在你的makefile顶部写:
PYV=$(shell python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)");
Run Code Online (Sandbox Code Playgroud)
然后你可以使用它 $(PYV)
在这里,我们在继续运行 make recipes 之前检查 python 版本 > 3.5
ifeq (, $(shell which python ))
$(error "PYTHON=$(PYTHON) not found in $(PATH)")
endif
PYTHON_VERSION_MIN=3.5
PYTHON_VERSION=$(shell $(PYTHON) -c 'import sys; print("%d.%d"% sys.version_info[0:2])' )
PYTHON_VERSION_OK=$(shell $(PYTHON) -c 'import sys;\
print(int(float("%d.%d"% sys.version_info[0:2]) >= $(PYTHON_VERSION_MIN)))' )
ifeq ($(PYTHON_VERSION_OK),0)
$(error "Need python $(PYTHON_VERSION) >= $(PYTHON_VERSION_MIN)")
endif
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3888 次 |
| 最近记录: |