Include setup.py and __init__.py in archive for pip

So that the wrapper library can be installed with `pip install
<archive>`. The setup.py is Windows-specific, but CI only
produces Windows builds so that's not currently an issue.

The __init__.py re-exports the .pyd module so that the .pyd and
.dll can be installed into a subdirectory of site-packages for
neatness, and so that the installed module isn't just to work
around pip install being unable to install a pyd with no package.
This commit is contained in:
Daniel Nunes
2019-10-21 18:07:55 +01:00
committed by Oliver Hamlet
parent 937a36a5ae
commit ffd62f9e0c
6 changed files with 112 additions and 17 deletions
+16 -9
View File
@@ -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 $<TARGET_PDB_FILE:loot_api>
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")
+2 -2
View File
@@ -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-<short revision ID>-python<python version>-win<architecture>.7z
loot_api_python-<short revision ID>-python<python version>-win<architecture>.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
+1 -3
View File
@@ -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:
+1
View File
@@ -0,0 +1 @@
from .loot_api import *
+89
View File
@@ -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',
)
+3 -3
View File
@@ -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() {