Skip to content

Commit

Permalink
🐛🚸: improved cross-platform compatibility of scripts and tasks.py tasks
Browse files Browse the repository at this point in the history
Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Nov 12, 2024
1 parent 3620f24 commit d4eb0f3
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 59 deletions.
19 changes: 12 additions & 7 deletions ozi/scripts/core_metadata_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.10"
# dependencies = ['tomli>=2;python_version<="3.11"'] # noqa: E800
# dependencies = ['tomli>=2;python_version<="3.11"']
# ///
""":pep:`723` script template: check OZI core dependency metadata
Expand Down Expand Up @@ -41,12 +41,17 @@

if __name__ == '__main__':
# pylint: disable=consider-using-with
source = pathlib.Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_SOURCE_ROOT', os.path.relpath('..'))),
'/',
),
)
if sys.platform == 'win32':
source = pathlib.Path(os.environ.get('MESON_SOURCE_ROOT'))
else:
source = pathlib.Path(
os.path.relpath(
os.path.join(
'/', os.environ.get('MESON_SOURCE_ROOT', os.path.relpath('..'))
),
'/',
),
)
project_file = open(source / 'pyproject.toml', 'rb')
pyproject_toml = toml.load(project_file)
project_file.close()
Expand Down
36 changes: 20 additions & 16 deletions ozi/scripts/meson_dist_setuptools_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.10"
# dependencies = ['tomli>=2;python_version<="3.11"'] # noqa: E800
# [tool.setuptools_scm] # noqa: E800
# version_file = "PKG-INFO" # noqa: E800
# dependencies = ['tomli>=2;python_version<="3.11"']
# [tool.setuptools_scm]
# version_file = "PKG-INFO"
# ///
""":pep:`723` script: deploy python PKG-INFO template for meson based on pyproject file.
Expand Down Expand Up @@ -41,19 +41,23 @@
elif sys.version_info < (3, 11): # pragma: no cover
import tomli as toml

if __name__ == '__main__':
source = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_BUILD_ROOT', os.path.relpath('..'))),
'/',
),
)
dist = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_DIST_ROOT', os.path.relpath('..'))),
'/',
),
)
if __name__ == '__main__': # noqa: C901
if sys.platform == 'win32':
source = Path(os.environ.get('MESON_BUILD_ROOT'))
dist = Path(os.environ.get('MESON_DIST_ROOT'))
else:
source = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_BUILD_ROOT', os.path.relpath('..'))),
'/',
),
)
dist = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_DIST_ROOT', os.path.relpath('..'))),
'/',
),
)
with (source / 'pyproject.toml').open('rb') as project_file:
pyproject_toml = toml.load(project_file)
setuptools_scm = pyproject_toml.get('tool', {}).get('setuptools_scm', {})
Expand Down
55 changes: 43 additions & 12 deletions ozi/scripts/meson_postconf_install_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# noqa: INP001
# ozi/scripts/meson_postconf_install_dependencies.py
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.10"
# dependencies = ['tomli>=2;python_version<="3.11"']
# ///
""":pep:`723` script: deploy python package build dependencies based on pyproject file.
Side-effects
^^^^^^^^^^^^
* None
Environment Variables
^^^^^^^^^^^^^^^^^^^^^
* :envvar:`MESON_BUILD_ROOT`
* :envvar:`MESON_DIST_ROOT`
``pyproject.toml`` Tool Table Variables
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* ``project.dependencies``
"""
import os
import sys
from pathlib import Path
Expand All @@ -10,18 +37,22 @@


if __name__ == '__main__':
source = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_BUILD_ROOT', os.path.relpath('..'))),
'/',
),
)
dist = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_DIST_ROOT', os.path.relpath('..'))),
'/',
),
)
if sys.platform == 'win32':
source = Path(os.environ.get('MESON_BUILD_ROOT'))
dist = Path(os.environ.get('MESON_DIST_ROOT'))
else:
source = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_BUILD_ROOT', os.path.relpath('..'))),
'/',
),
)
dist = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_DIST_ROOT', os.path.relpath('..'))),
'/',
),
)
with (source / 'pyproject.toml').open('rb') as project_file:
pyproject_toml = toml.load(project_file)
dependencies = pyproject_toml.get('project', {}).get('dependencies', [])
Expand Down
21 changes: 12 additions & 9 deletions ozi/scripts/meson_setuptools_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.10"
# dependencies = ['tomli>=2;python_version<="3.11"'] # noqa: E800
# [tool.setuptools_scm] # noqa: E800
# version_file = "PKG-INFO" # noqa: E800
# dependencies = ['tomli>=2;python_version<="3.11"']
# [tool.setuptools_scm]
# version_file = "PKG-INFO"
# ///
""":pep:`723` script: deploy python PKG-INFO template for meson based on pyproject file.
Expand Down Expand Up @@ -41,12 +41,15 @@
import tomli as toml

if __name__ == '__main__':
source = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_BUILD_ROOT', os.path.relpath('..'))),
'/',
),
)
if sys.platform == 'win32':
source = Path(os.environ.get('MESON_BUILD_ROOT'))
else:
source = '/' / Path(
os.path.relpath(
os.path.join('/', os.environ.get('MESON_BUILD_ROOT', os.path.relpath('..'))),
'/',
),
)
with (source / 'pyproject.toml').open('rb') as project_file:
pyproject_toml = toml.load(project_file)
setuptools_scm = pyproject_toml.get('tool', {}).get('setuptools_scm', {})
Expand Down
16 changes: 10 additions & 6 deletions ozi/scripts/replace_ruff_target_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
"""
import os
import sys
from pathlib import Path

if __name__ == '__main__':
build = '/' / Path(
os.path.relpath(
Path('/', os.environ.get('MESON_BUILD_ROOT', Path('..').relative_to('.'))),
'/',
),
)
if sys.platform == 'win32':
build = Path(os.environ.get('MESON_BUILD_ROOT'))
else:
build = '/' / Path(
os.path.relpath(
Path('/', os.environ.get('MESON_BUILD_ROOT', Path('..').relative_to('.'))),
'/',
),
)
file = build / 'pyproject.toml'
file.write_text(file.read_text().replace('# target-version', 'target-version'))
2 changes: 1 addition & 1 deletion ozi/scripts/scm_version_snip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.10"
# dependencies = ["setuptools_scm"] # noqa: E800
# dependencies = ["setuptools_scm"]
# ///
"""python snippet: grab version info
Expand Down
17 changes: 9 additions & 8 deletions ozi/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ def setup(
@task(setup)
def sign_checkpoint(c: Context, suite: str | None = None) -> None:
"""Sign checkpoint suites with sigstore."""
banned = './'
banned = '.' + os.sep
host = f'py{sys.version_info.major}{sys.version_info.minor}'
if not suite:
return print('No suite target provided', file=sys.stderr)
if any(i in suite for i in banned):
return print(f'Invalid sign target suite: {suite}', file=sys.stderr)
testlog = Path(f'.tox/{suite}/tmp/meson-logs/testlog-{suite}.txt') # noqa: S108
meson_log = Path(f'.tox/{suite}/tmp/meson-logs/meson-log.txt') # noqa: S108
sigdir = Path(f'sig/{host}/{suite}')
if testlog.exists():
c.run(f'sigstore sign --output-dir=sig/{host}/{suite} {testlog}')
c.run(f'sigstore sign --output-dir={sigdir} {testlog}')
else:
print(f'Test log not found for suite: {suite}.', file=sys.stderr)
meson_log = Path(f'.tox/{suite}/tmp/meson-logs/meson-log.txt') # noqa: S108
if meson_log.exists():
c.run(f'sigstore sign --output-dir=sig/{host}/{suite} {meson_log}')
c.run(f'sigstore sign --output-dir={sigdir} {meson_log}')
else:
print(f'Meson log not found for suite: {suite}.', file=sys.stderr)

Expand Down Expand Up @@ -103,7 +104,7 @@ def release( # noqa: C901
if sdist:
c.run('python -m build --sdist')
if sign:
c.run('sigstore sign --output-dir=sig dist/*.tar.gz')
c.run(f'sigstore sign --output-dir=sig dist{os.sep}*.tar.gz')

if cibuildwheel:
res = c.run('cibuildwheel --prerelease-pythons --output-dir dist .', warn=True)
Expand All @@ -113,7 +114,7 @@ def release( # noqa: C901
c.run('python -m build --wheel')

if sign:
c.run('sigstore sign --output-dir=sig dist/*.whl')
c.run(f'sigstore sign --output-dir=sig dist{os.sep}*.whl')


@task
Expand All @@ -127,8 +128,8 @@ def publish(c: Context, ozi: bool = False) -> None:
"""Publishes a release tag"""
setup(c, suite='dist', ozi=ozi)
c.run('psr publish')
c.run('twine check dist/*')
c.run('twine upload dist/*')
c.run(f'twine check dist{os.sep}*')
c.run(f'twine upload dist{os.sep}*')


@task
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ max-line-length = 93
extend-exclude = ["meson-private", "build-env-*", "vendor", "venv", "build*", "*.pyi"]
extend-ignore = "E203,E501,TC007,TC008"
extend-select = "B950"
per-file-ignores = ['ozi/scripts/*:E800']

[tool.isort]
line_length = 93
Expand Down

0 comments on commit d4eb0f3

Please sign in to comment.