mirror of
https://github.com/biojppm/rapidyaml.git
synced 2026-01-18 21:41:18 +01:00
[tidy] python packaging
This commit is contained in:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -45,7 +45,7 @@ env:
|
||||
# # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
|
||||
# vs2019
|
||||
# windows-2016:
|
||||
# # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
|
||||
# # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2016-Readme.md
|
||||
# vs2017
|
||||
jobs:
|
||||
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -37,6 +37,10 @@ compile_commands.json
|
||||
# test files
|
||||
/Testing/
|
||||
|
||||
# python packaging
|
||||
.eggs/
|
||||
dist/
|
||||
rapidyaml.egg-info/
|
||||
|
||||
# continuous integration files
|
||||
.ci/.vagrant
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=42", "setuptools_scm[toml]>=3.4", "wheel", "ninja", "cmake_build_extension"]
|
||||
requires = [
|
||||
"setuptools>=42",
|
||||
"setuptools_scm[toml]>=3.4",
|
||||
"setuptools-git",
|
||||
"wheel",
|
||||
"ninja",
|
||||
"cmake_build_extension"]
|
||||
|
||||
@@ -3,3 +3,5 @@ wheel
|
||||
cmake-build-extension
|
||||
build
|
||||
twine
|
||||
setuptools_scm
|
||||
setuptools-git
|
||||
|
||||
76
setup.py
76
setup.py
@@ -8,18 +8,24 @@ import sys
|
||||
|
||||
from pathlib import Path
|
||||
from distutils import log
|
||||
from setuptools import setup
|
||||
from setuptools.command.sdist import sdist as SdistCommand
|
||||
from setuptools import setup, find_packages
|
||||
from cmake_build_extension import BuildExtension, CMakeExtension
|
||||
|
||||
TOP_DIR = (Path(__file__).parent).resolve()
|
||||
|
||||
# Where the Python library is actually found.
|
||||
# where the Python library is actually found
|
||||
PYTHON_DIR = "api/python"
|
||||
|
||||
setup_kw = {}
|
||||
|
||||
# Read in the package version when not in a git repository.
|
||||
|
||||
# read the module description from the README.md file
|
||||
with open(TOP_DIR / "README.md", "r") as fh:
|
||||
setup_kw['long_description'] = fh.read()
|
||||
setup_kw['long_description_content_type'] = "text/markdown"
|
||||
|
||||
|
||||
# read the package version when not in a git repository
|
||||
VERSION_FILE = os.path.join(PYTHON_DIR, 'ryml', 'version.py')
|
||||
if not (TOP_DIR / '.git').exists() and os.path.exists(VERSION_FILE):
|
||||
exec(open(VERSION_FILE).read())
|
||||
@@ -31,12 +37,6 @@ else:
|
||||
"write_to": VERSION_FILE,
|
||||
}
|
||||
|
||||
# Read in the module description from the README.md file.
|
||||
README_FILE = TOP_DIR / "README.md"
|
||||
if README_FILE.exists():
|
||||
with open(TOP_DIR / "README.md", "r") as fh:
|
||||
setup_kw['long_description'] = fh.read()
|
||||
setup_kw['long_description_content_type'] = "text/markdown"
|
||||
|
||||
# define a CMake package
|
||||
cmake_args = dict(
|
||||
@@ -48,19 +48,27 @@ cmake_args = dict(
|
||||
"-DRYML_BUILD_API:BOOL=ON",
|
||||
# Force cmake to use the Python interpreter we are currently
|
||||
# using to run setup.py
|
||||
"-DPython3_EXECUTABLE:FILEPATH="+sys.executable,
|
||||
"-DPython3_EXECUTABLE:FILEPATH=" + sys.executable,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
ext = CMakeExtension(**cmake_args)
|
||||
log.info("Using standard CMakeExtension")
|
||||
except TypeError:
|
||||
del cmake_args['cmake_component']
|
||||
ext = CMakeExtension(**cmake_args)
|
||||
log.info("Using custom CMakeExtension")
|
||||
# If the CMakeExtension doesn't support `cmake_component` then we
|
||||
# have to do some manual cleanup.
|
||||
del cmake_args['cmake_component']
|
||||
ext = CMakeExtension(**cmake_args)
|
||||
def _cleanup(path, mandatory):
|
||||
if mandatory:
|
||||
assert path.exists(), path
|
||||
elif not path.exists():
|
||||
return
|
||||
log.info("Removing everything under: %s", path)
|
||||
shutil.rmtree(path)
|
||||
_BuildExtension = BuildExtension
|
||||
class BuildExtension(_BuildExtension):
|
||||
def build_extension(self, ext):
|
||||
@@ -69,46 +77,50 @@ except TypeError:
|
||||
cmake_install_prefix = ext_dir / ext.install_prefix
|
||||
assert cmake_install_prefix.exists(), cmake_install_prefix
|
||||
try:
|
||||
lib_path = cmake_install_prefix / "lib"
|
||||
assert lib_path.exists(), lib_path
|
||||
log.info("Removing everything under: %s", lib_path)
|
||||
shutil.rmtree(lib_path)
|
||||
|
||||
inc_path = cmake_install_prefix / "include"
|
||||
assert inc_path.exists(), inc_path
|
||||
log.info("Removing everything under: %s", inc_path)
|
||||
shutil.rmtree(inc_path)
|
||||
|
||||
_cleanup(cmake_install_prefix / "lib", mandatory=True)
|
||||
_cleanup(cmake_install_prefix / "include", mandatory=True)
|
||||
# Windows only
|
||||
cm_path = cmake_install_prefix / "cmake"
|
||||
if cm_path.exists():
|
||||
log.info("Removing everything under: %s", cm_path)
|
||||
shutil.rmtree(cm_path)
|
||||
_cleanup(cmake_install_prefix / "cmake", mandatory=False)
|
||||
except:
|
||||
log.info('Found following installed files:')
|
||||
for f in cmake_install_prefix.rglob("*"):
|
||||
log.info(' - %s', f)
|
||||
raise
|
||||
|
||||
|
||||
setup(
|
||||
# Package human readable information
|
||||
name='rapidyaml',
|
||||
#author='Joao Paulo Magalhaes',
|
||||
description='Rapid YAML - a library to parse and emit YAML, and do it fast.',
|
||||
description='Rapid YAML - a library to parse and emit YAML, and do it fast',
|
||||
url='https://github.com/biojppm/rapidyaml',
|
||||
license='MIT',
|
||||
license_files=['LICENSE.txt'],
|
||||
author="Joao Paulo Magalhaes",
|
||||
author_email="dev@jpmag.me",
|
||||
# Package contents control
|
||||
cmdclass={
|
||||
"build_ext": BuildExtension,
|
||||
},
|
||||
package_dir={"": PYTHON_DIR},
|
||||
packages=['ryml'],
|
||||
packages=find_packages( # not working...
|
||||
'ryml',
|
||||
exclude=[
|
||||
"test",
|
||||
"build",
|
||||
"install",
|
||||
"ext/c4core/build",
|
||||
"ext/c4core/install"
|
||||
]
|
||||
),
|
||||
ext_modules=[ext],
|
||||
include_package_data=True,
|
||||
# Requirements
|
||||
python_requires=">=3.7",
|
||||
setup_requires=['setuptools_scm'],
|
||||
python_requires=">=3.6",
|
||||
setup_requires=[
|
||||
'setuptools_scm',
|
||||
'setuptools-git',
|
||||
'setuptools',
|
||||
],
|
||||
# Extra arguments
|
||||
**setup_kw,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user