diff --git a/CMakeLists.txt b/CMakeLists.txt index a3e36ae..0e4948f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Get Build Revision ############################## +set(LIBLOOT_PY_VERSION_MAJOR 4) +set(LIBLOOT_PY_VERSION_MINOR 0) +set(LIBLOOT_PY_VERSION_PATCH 2) + find_package(Git) IF (GIT_FOUND) @@ -25,10 +29,12 @@ ELSE() SET (GIT_COMMIT_STRING "unknown") ENDIF () +message(STATUS "LOOT API Python version: ${LIBLOOT_PY_VERSION_MAJOR}.${LIBLOOT_PY_VERSION_MINOR}.${LIBLOOT_PY_VERSION_PATCH}") message(STATUS "Git revision: ${GIT_COMMIT_STRING}") # Write to file. configure_file("${CMAKE_SOURCE_DIR}/src/wrapper_version.cpp.in" "${CMAKE_BINARY_DIR}/generated/wrapper_version.cpp" @ONLY) +configure_file("${CMAKE_SOURCE_DIR}/python/setup.py" "${CMAKE_BINARY_DIR}/generated/setup.py" @ONLY) ####################################### # pybind11 @@ -117,17 +123,23 @@ add_test(NAME python ######################################## install(TARGETS loot_api - DESTINATION "." + DESTINATION "loot_api" CONFIGURATIONS Release RelWithDebInfo) install(FILES "${LIBLOOT_EXTRACTED_PATH}/${LIBLOOT_SHARED_LIBRARY}" - "${CMAKE_SOURCE_DIR}/docs/README.md" + "${CMAKE_SOURCE_DIR}/python/loot_api/__init__.py" + DESTINATION "loot_api" + CONFIGURATIONS Release RelWithDebInfo) + +install(FILES "${CMAKE_SOURCE_DIR}/docs/README.md" + "${CMAKE_BINARY_DIR}/generated/setup.py" + "${CMAKE_SOURCE_DIR}/LICENSE" DESTINATION "." CONFIGURATIONS Release RelWithDebInfo) IF (MSVC) install(FILES $ - DESTINATION . + DESTINATION "loot_api" OPTIONAL CONFIGURATIONS RelWithDebInfo RENAME loot_api_python.pdb) @@ -155,12 +167,7 @@ ELSE() SET (GIT_DESCRIBE_STRING "unknown-version") ENDIF () -if (CMAKE_SYSTEM_NAME MATCHES "Windows") - set(CPACK_GENERATOR "7Z") -else() - set(CPACK_GENERATOR "TXZ") -endif() - +set(CPACK_GENERATOR "ZIP") set(CPACK_PACKAGE_VERSION "${GIT_DESCRIBE_STRING}-python$ENV{PYTHON_VERSION}") set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/package") diff --git a/README.md b/README.md index 3891b8e..c8352dc 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ A Python module that wraps libloot, generated by [pybind11](https://github.com/p Snapshot builds are available on [Bintray](https://bintray.com/loot/snapshots/loot-api-python). The snapshot build archives are named like so: ``` -loot_api_python--python-win.7z +loot_api_python--python-win.zip ``` -For example `loot_api_python-94de368-python2.7-win32.7z` was built using the revision with shortened commit ID `94de368`. +For example `loot_api_python-94de368-python2.7-win32.zip` was built using the revision with shortened commit ID `94de368`. ## Documentation diff --git a/appveyor.yml b/appveyor.yml index 845a4fd..7866cee 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -44,12 +44,10 @@ test_script: after_test: - cd %APPVEYOR_BUILD_FOLDER%\build - cpack -C %CONFIGURATION% - # AppVeyor checks out a specific commit, but that means the archive script - # can't tell which branch it's on, so rename the 7z archives. - ps: $env:GIT_DESCRIBE = ((git describe --tags --long --always) | Out-String) -replace "`n|`r", "" artifacts: - - path: build\package\loot_api_python-$(GIT_DESCRIBE)_$(APPVEYOR_REPO_BRANCH)-python$(PYTHON_VERSION)-win$(ARCHITECTURE).7z + - path: build\package\loot_api_python-$(GIT_DESCRIBE)_$(APPVEYOR_REPO_BRANCH)-python$(PYTHON_VERSION)-win$(ARCHITECTURE).zip name: loot_api_python deploy: diff --git a/python/loot_api/__init__.py b/python/loot_api/__init__.py new file mode 100644 index 0000000..59c3088 --- /dev/null +++ b/python/loot_api/__init__.py @@ -0,0 +1 @@ +from .loot_api import * diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000..5da6d20 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,89 @@ +import itertools +import os +import platform +import subprocess +import sys +import tempfile +import threading +import time +from contextlib import contextmanager + +from setuptools import Distribution, find_packages, setup + +try: # python 3 + import winreg + from urllib.request import urlretrieve +except ImportError: # python 2 + import _winreg as winreg + from urllib import urlretrieve + + +MSVC_MIN_VERSION = (14, 0, 24215) + + +class BinaryDistribution(Distribution): + def has_ext_modules(foo): + return True + + +def is_msvc_redist_installed(major, minor, build): + if platform.machine().endswith("64"): # check if os is 64bit + sub_key = "SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64" + else: + sub_key = "SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x86" + try: + key_handle = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, sub_key) + runtime_installed = winreg.QueryValueEx(key_handle, "Installed")[0] + installed_major = winreg.QueryValueEx(key_handle, "Major")[0] + installed_minor = winreg.QueryValueEx(key_handle, "Minor")[0] + installed_build = winreg.QueryValueEx(key_handle, "Bld")[0] + return ( + runtime_installed != 0 + and installed_major >= major + and installed_minor >= minor + and installed_build >= build + ) + except WindowsError as exc: + return False + +with open("README.md", "r") as fh: + long_description = fh.read() + +def install_msvc_redist(): + url = ( + "https://download.microsoft.com/download/6/A/A/" + "6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x86.exe" + ) + dl_dir = tempfile.mkdtemp() + dl_file = os.path.join(dl_dir, "vc_redist.exe") + urlretrieve(url, dl_file) + subprocess.call([dl_file, "/quiet"]) + # trying to remove the temp folder triggers + # an error during py2 pip install + + +if not is_msvc_redist_installed(*MSVC_MIN_VERSION): + install_msvc_redist() + +# The version string is substituted in by CMake. +setup( + name="loot-api", + version="@LIBLOOT_PY_VERSION_MAJOR@.@LIBLOOT_PY_VERSION_MINOR@.@LIBLOOT_PY_VERSION_PATCH@", + description="A Python module that wraps the LOOT API.", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/loot/loot-api-python", + packages=find_packages(), + include_package_data=True, + package_data={"loot_api": ["loot_api*.pyd", "loot.dll"]}, + distclass=BinaryDistribution, + classifiers=[ + 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: C++' + 'Operating System :: Microsoft :: Windows', + 'Intended Audience :: Developers', + ], + python_requires='>=2.7', +) diff --git a/src/wrapper_version.cpp.in b/src/wrapper_version.cpp.in index 0250ad9..7220147 100644 --- a/src/wrapper_version.cpp.in +++ b/src/wrapper_version.cpp.in @@ -25,9 +25,9 @@ #include "wrapper_version.h" namespace loot { -const unsigned int WrapperVersion::major = 4; -const unsigned int WrapperVersion::minor = 0; -const unsigned int WrapperVersion::patch = 2; +const unsigned int WrapperVersion::major = @LIBLOOT_PY_VERSION_MAJOR@; +const unsigned int WrapperVersion::minor = @LIBLOOT_PY_VERSION_MINOR@; +const unsigned int WrapperVersion::patch = @LIBLOOT_PY_VERSION_PATCH@; const std::string WrapperVersion::revision = "@GIT_COMMIT_STRING@"; std::string WrapperVersion::string() {