Skip to content

Commit

Permalink
OZI.build 1.4.0 add packaging requirement and flexible Requires-Pytho…
Browse files Browse the repository at this point in the history
…n setting

Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Aug 28, 2024
1 parent ee004f3 commit 6200763
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('OZI.build', version : '1.3.4', license : 'apache-2.0')
project('OZI.build', version : '1.4.0', license : 'apache-2.0')
fs = import('fs')
python = import('python').find_installation()
subdir('ozi_build')
Expand Down
43 changes: 36 additions & 7 deletions ozi_build/buildapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pathlib import Path

from wheel.wheelfile import WheelFile
from packaging.version import Version

if sys.version_info >= (3, 11):
import tomllib as toml
Expand Down Expand Up @@ -66,11 +67,16 @@ def meson_configure(*args, config_settings=None):

PKG_INFO = """\
Metadata-Version: 2.1
Requires-Python: >=3.10, <3.13
Requires-Python: >={min_python}, <{max_python}
Name: {name}
Version: {version}
"""

PKG_INFO_NO_REQUIRES_PYTHON = """\
Metadata-Version: 2.1
Name: {name}
Version: {version}
"""

readme_ext_to_content_type = {
'.rst': 'text/x-rst',
Expand All @@ -79,7 +85,7 @@ def meson_configure(*args, config_settings=None):
'': 'text/plain',
}


GET_PYTHON_VERSION = 'import sys;print("{}.{}".format(*sys.version_info[:2]))'
class Config:
def __init__(self, builddir=None):
config = self.__get_config()
Expand All @@ -93,6 +99,8 @@ def __init__(self, builddir=None):
else:
self.__extras = config.get('project', {}).get('optional-dependencies', {})
self.__requires = config.get('project', {}).get('dependencies', None)
self.__min_python = '3.10'
self.__max_python = '3.13'
self.installed = []
self.options = []
self.builddir = None
Expand Down Expand Up @@ -198,7 +206,6 @@ def get_metadata(self):
'name': self['module'],
'version': self['version'],
}

if 'pkg-info-file' in self:
if not Path(self['pkg-info-file']).exists():
builddir = tempfile.TemporaryDirectory().name
Expand All @@ -207,7 +214,7 @@ def get_metadata(self):
pkg_info_file = Path(builddir) / 'PKG-INFO'
else:
pkg_info_file = self['pkg-info-file']
res = '\n'.join(PKG_INFO.split('\n')[:3]).format(**meta) + '\n'
res = '\n'.join(PKG_INFO_NO_REQUIRES_PYTHON.split('\n')[:3]).format(**meta) + '\n'
with open(pkg_info_file, 'r') as f:
orig_lines = f.readlines()
for line in orig_lines:
Expand All @@ -222,6 +229,29 @@ def get_metadata(self):
continue
res += line
return res
option_build = self.get('meson-python-option-name')
python = 'python3'
if not option_build:
log.warning(
"meson-python-option-name not specified in the "
+ "[tool.ozi-build.metadata] section, assuming `python3`"
)
else:
for opt in self.options:
if opt['name'] == option_build:
python = opt['value']
break
python_version = Version(subprocess.check_output([python, '-c', GET_PYTHON_VERSION]).decode('utf-8').strip('\n'))
if python_version < Version(self.__min_python):
meta.update({
'min_python': python_version,
'max_python': self.__max_python,
})
elif python_version >= Version(self.__max_python):
meta.update({
'min_python': self.__min_python,
'max_python': python_version,
})

res = PKG_INFO.format(**meta)
res += self._parse_project()
Expand Down Expand Up @@ -447,8 +477,7 @@ def build(self, wheel_directory, config_settings, metadata_dir):
if not is_pure:
abi = get_abi(python)
else:
abi = config.get('requires-python', get_abi(python))

abi = config.get('pure-python-abi', get_abi(python))
target_fp = wheel_directory / '{}-{}-{}-{}.whl'.format(
config['module'].replace('-','_'),
config['version'],
Expand All @@ -468,7 +497,7 @@ def build(self, wheel_directory, config_settings, metadata_dir):
meson('install', '-C', self.builddir.name)
self.pack_files(config)
self.wheel_zip.close()
if not config.get('requires-python'):
if not config.get('pure-python-abi'):
convert_wheel(Path(target_fp))
return str(target_fp)

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
requires = [
"wheel>0.33",
"meson[ninja]>1.1.0",
'packaging',
'tomli>=2.0.0;python_version<"3.11"',
"setuptools>=64",
]
Expand Down Expand Up @@ -50,7 +51,7 @@ project-urls= [
"Source, https://github.com/OZI-Project/OZI.build",
"Documentation, https://docs.oziproject.dev/en/stable/ozi_build.html",
]
requires-python="py3-none"
pure-python-abi="py3-none"
summary="Create pep517 compliant packages from the meson build system, OZI-maintained fork."

[tool.deptry.per_rule_ignores]
Expand Down

0 comments on commit 6200763

Please sign in to comment.