Skip to content

Commit ba20e6e

Browse files
Adapt setup.py to add entry-points in dist-info.data/scripts/rez
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent 2fc275d commit ba20e6e

File tree

4 files changed

+163
-41
lines changed

4 files changed

+163
-41
lines changed

.github/workflows/wheel.yaml

+53-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,56 @@ jobs:
3636
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
3737
VERBOSE=1 cmake --build .
3838
39-
ls -la
39+
mv simple_launcher_cli.exe t64.exe
40+
mv simple_launcher_gui.exe w64.exe
41+
42+
- uses: actions/upload-artifact@v3
43+
with:
44+
name: launchers
45+
path: 'launcher/build/*.exe'
46+
47+
wheel:
48+
name: Build wheel
49+
needs: ["launchers"]
50+
runs-on: "windows-latest"
51+
52+
steps:
53+
- uses: actions/checkout@v4
54+
55+
- uses: actions/download-artifact@v3
56+
with:
57+
name: launchers
58+
path: launcher
59+
60+
- uses: actions/setup-python@v4
61+
with:
62+
python-version: 3.11
63+
64+
- name: Build wheel
65+
shell: bash
66+
run: |
67+
set -ex
68+
python -m pip install build
69+
python -m build -w .
70+
71+
- name: Install wheel
72+
shell: bash
73+
run: |
74+
set -ex
75+
python -m venv .venv
76+
.venv/Scripts/python.exe -m pip install dist/*
77+
ls -la .venv/Scripts/
78+
ls -la .venv/Scripts/rez
79+
80+
- name: Test commands
81+
shell: bash
82+
run: |
83+
export PATH=$(pwd)/.venv/Scripts/rez:$PATH
84+
set -ex
85+
cat .venv/Scripts/rez/rez-script.py
86+
cat .venv/Scripts/rez/jctest-script.py
87+
jctest
88+
89+
rez --help
90+
rez --version
91+
rez-env --help

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"

setup.py

+64-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
import os
99
import os.path
1010
import sys
11+
import logging
12+
import tempfile
13+
import platform
14+
import shutil
1115

1216

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

5358

59+
SCRIPT_TEMPLATE = """#!/usr/bin/python -E
60+
# -*- coding: utf-8 -*-
61+
import re
62+
import sys
63+
from rez.cli._entry_points import {0}
64+
if __name__ == '__main__':
65+
sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])
66+
sys.exit({0}())
67+
"""
68+
69+
class build_scripts(distutils.command.build_scripts.build_scripts):
70+
def finalize_options(self):
71+
super().finalize_options()
72+
self.build_dir = os.path.join(self.build_dir, "rez")
73+
74+
def run(self):
75+
logging.getLogger().info("running rez's customized build_scripts command")
76+
77+
scripts = []
78+
tmpdir = tempfile.mkdtemp("rez-scripts")
79+
80+
os.makedirs(self.build_dir)
81+
82+
for command in self.scripts:
83+
spec = get_specifications()[command]
84+
85+
filename = "{0}.py".format(command)
86+
if platform.system() == "Windows":
87+
filename = "{0}-script.py".format(command)
88+
89+
path = os.path.join(tmpdir, filename)
90+
with open(path, "w") as fd:
91+
fd.write(SCRIPT_TEMPLATE.format(spec["func"]))
92+
93+
scripts.append(path)
94+
95+
if platform.system() == "Windows":
96+
launcher = "t64.exe"
97+
if spec["type"] == "window":
98+
launcher = "w64.exe"
99+
100+
self.copy_file(
101+
os.path.join("launcher", launcher),
102+
os.path.join(self.build_dir, "{0}.exe".format(command))
103+
)
104+
105+
prod_install_path = os.path.join(tmpdir, ".rez_production_install")
106+
with open(prod_install_path, "w") as fd:
107+
fd.write("# Production install installed with pip")
108+
109+
scripts.append(prod_install_path)
110+
111+
self.scripts = scripts
112+
return super().run()
113+
114+
54115
setup(
55116
name="rez",
56117
version=_rez_version,
@@ -65,9 +126,7 @@ def find_files(pattern, path=None, root="rez"):
65126
author_email="[email protected]",
66127
license="Apache-2.0",
67128
license_files=["LICENSE"],
68-
entry_points={
69-
"console_scripts": get_specifications().values()
70-
},
129+
scripts=list(get_specifications().keys()),
71130
include_package_data=True,
72131
zip_safe=False,
73132
package_dir={'': 'src'},
@@ -99,5 +158,6 @@ def find_files(pattern, path=None, root="rez"):
99158
"Programming Language :: Python :: 3",
100159
"Topic :: Software Development",
101160
"Topic :: System :: Software Distribution"
102-
]
161+
],
162+
cmdclass={"build_scripts": build_scripts},
103163
)

0 commit comments

Comments
 (0)