Skip to content

Commit

Permalink
Adapt setup.py to add entry-points in dist-info.data/scripts/rez
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Sep 17, 2023
1 parent 3178230 commit 984b310
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 41 deletions.
54 changes: 53 additions & 1 deletion .github/workflows/wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,56 @@ jobs:
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
VERBOSE=1 cmake --build .
ls -la
mv simple_launcher_cli.exe t64.exe
mv simple_launcher_gui.exe w64.exe
- uses: actions/upload-artifact@v3
with:
name: launchers
path: 'launcher/build/*.exe'

wheel:
name: Build wheel
needs: ["launchers"]
runs-on: "windows-latest"

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
with:
name: launchers
path: launcher

- uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Build wheel
shell: bash
run: |
set -ex
python -m pip install build
python -m build -w .
- name: Install wheel
shell: bash
run: |
set -ex
python -m venv .venv
.venv/Scripts/python.exe -m pip install dist/*
ls -la .venv/Scripts/
ls -la .venv/Scripts/rez
- name: Test commands
shell: bash
run: |
export PATH=$(pwd)/.venv/Scripts/rez:$PATH
set -ex
cat .venv/Scripts/rez/rez-script.py
cat .venv/Scripts/rez/jctest-script.py
jctest
rez --help
rez --version
rez-env --help
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
68 changes: 64 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
import os
import os.path
import sys
import logging
import tempfile
import platform
import shutil


try:
from setuptools import setup, find_packages
import distutils.command.build_scripts
except ImportError:
print("install failed - requires setuptools", file=sys.stderr)
sys.exit(1)
Expand Down Expand Up @@ -51,6 +56,62 @@ def find_files(pattern, path=None, root="rez"):
long_description = f.read()


SCRIPT_TEMPLATE = """#!/usr/bin/python -E
# -*- coding: utf-8 -*-
import re
import sys
from rez.cli._entry_points import {0}
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])
sys.exit({0}())
"""

class build_scripts(distutils.command.build_scripts.build_scripts):
def finalize_options(self):
super().finalize_options()
self.build_dir = os.path.join(self.build_dir, "rez")

def run(self):
logging.getLogger().info("running rez's customized build_scripts command")

scripts = []
tmpdir = tempfile.mkdtemp("rez-scripts")

os.makedirs(self.build_dir)

for command in self.scripts:
spec = get_specifications()[command]

filename = "{0}.py".format(command)
if platform.system() == "Windows":
filename = "{0}-script.py".format(command)

path = os.path.join(tmpdir, filename)
with open(path, "w") as fd:
fd.write(SCRIPT_TEMPLATE.format(spec["func"]))

scripts.append(path)

if platform.system() == "Windows":
launcher = "t64.exe"
if spec["type"] == "window":
launcher = "w64.exe"

self.copy_file(
os.path.join("launcher", launcher),
os.path.join(self.build_dir, "{0}.exe".format(command))
)

prod_install_path = os.path.join(tmpdir, ".rez_production_install")
with open(prod_install_path, "w") as fd:
fd.write("# Production install installed with pip")

scripts.append(prod_install_path)

self.scripts = scripts
return super().run()


setup(
name="rez",
version=_rez_version,
Expand All @@ -65,9 +126,7 @@ def find_files(pattern, path=None, root="rez"):
author_email="[email protected]",
license="Apache-2.0",
license_files=["LICENSE"],
entry_points={
"console_scripts": get_specifications().values()
},
scripts=list(get_specifications().keys()),
include_package_data=True,
zip_safe=False,
package_dir={'': 'src'},
Expand Down Expand Up @@ -99,5 +158,6 @@ def find_files(pattern, path=None, root="rez"):
"Programming Language :: Python :: 3",
"Topic :: Software Development",
"Topic :: System :: Software Distribution"
]
],
cmdclass={"build_scripts": build_scripts},
)
Loading

0 comments on commit 984b310

Please sign in to comment.