Skip to content

Commit

Permalink
Switch to pure Python code in setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Nov 18, 2024
1 parent 8bf5baf commit fc68e14
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1,462 deletions.
5 changes: 3 additions & 2 deletions py/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ endif

SETUP=setup.py pyproject.toml

all: python3.9 python3.10 python3.11 python3.12 python3.13
#all: python3.9 python3.10 python3.11 python3.12 python3.13
all: python3.13

python3.13: $(SETUP)
@echo "########### PYTHON 3.13 ##########"
$(PY)3.13 setup.py build_ext --inplace
$(PY)3.13 -m build --no-isolation --sdist
$(PY)3.13 -m build --no-isolation --wheel
$(PY)3.13 -m unittest -v
$(PY)3.13 -m pytest -v
$(AW)
@echo "#################################"

Expand Down
113 changes: 59 additions & 54 deletions py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,67 +44,71 @@


# Headers
root_src = pathlib.Path(f"./src/py{name:s}/include/")
root_dest = pathlib.Path(f"./src/py{name:s}/")
files = [f"{name:s}.h"]
for file in files:
src = root_src / file
dest = root_dest / file
if not src.exists():
raise ValueError(f"The library {name:s} was not installed. Run in the root folder: make install prefix=./py/src/py{name:s}")
try:
print(f"copying {str(src):s} -> {str(dest.parent):s}.")
shutil.copy(src, dest)
except:
print(f"{file:s} was not copied.")
# root_src = pathlib.Path(f"./src/py{name:s}/include/")
# root_dest = pathlib.Path(f"./src/py{name:s}/")
# files = [f"{name:s}.h"]
# for file in files:
# src = root_src / file
# dest = root_dest / file
# if not src.exists():
# raise ValueError(f"The library {name:s} was not installed. Run in the root folder: make install prefix=./py/src/py{name:s}")
# try:
# print(f"copying {str(src):s} -> {str(dest.parent):s}.")
# shutil.copy(src, dest)
# except:
# print(f"{file:s} was not copied.")

# Libs
root_src = pathlib.Path(f"./src/py{name:s}/lib/")
root_dest = pathlib.Path(f"./src/py{name:s}/")
files = list(map(lambda s: f"lib{name:s}"+s, ext))
for file in files:
src = root_src / file
dest = root_dest / file
if not src.exists():
raise ValueError(f"The library {name:s} was not installed. Run in the root folder: make install prefix=./py/src/py{name:s}")
try:
print(f"copying {str(src):s} -> {str(dest.parent):s}.")
shutil.copy(src, dest)
except:
print(f"{file:s} was not copied.")
# # Libs
# root_src = pathlib.Path(f"./src/py{name:s}/lib/")
# root_dest = pathlib.Path(f"./src/py{name:s}/")
# files = list(map(lambda s: f"lib{name:s}"+s, ext))
# for file in files:
# src = root_src / file
# dest = root_dest / file
# if not src.exists():
# raise ValueError(f"The library {name:s} was not installed. Run in the root folder: make install prefix=./py/src/py{name:s}")
# try:
# print(f"copying {str(src):s} -> {str(dest.parent):s}.")
# shutil.copy(src, dest)
# except:
# print(f"{file:s} was not copied.")

# gfortran libs
root_src = pathlib.Path(ROOT)
root_dest = pathlib.Path(f"./src/py{name:s}/")
files = LIBS
for file in files:
src = root_src / (file + ext[0])
dest = root_dest / (file + ext[0])
cmd = ["install_name_tool", "-change", f"{str(src):s}", f"@loader_path/{src.name}", f"./src/py{name:s}/lib{name:s}{ext[0]:s}"]
try:
print(f"copying {str(src):s} -> {str(dest.parent):s}.")
shutil.copy(src, dest)
if platform.system() == "Darwin":
print(f"changing rpath for {str(file):s}")
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
print(" ".join(cmd) + " was not successful.")
except:
print(f"{file:s} was not copied.")
# # gfortran libs
# root_src = pathlib.Path(ROOT)
# root_dest = pathlib.Path(f"./src/py{name:s}/")
# files = LIBS
# for file in files:
# src = root_src / (file + ext[0])
# dest = root_dest / (file + ext[0])
# cmd = ["install_name_tool", "-change", f"{str(src):s}", f"@loader_path/{src.name}", f"./src/py{name:s}/lib{name:s}{ext[0]:s}"]
# try:
# print(f"copying {str(src):s} -> {str(dest.parent):s}.")
# shutil.copy(src, dest)
# if platform.system() == "Darwin":
# print(f"changing rpath for {str(file):s}")
# subprocess.check_call(cmd)
# except subprocess.CalledProcessError:
# print(" ".join(cmd) + " was not successful.")
# except:
# print(f"{file:s} was not copied.")

# check rpaths for Darwin
if platform.system() == "Darwin":
cmd = ["otool", "-L", f"./src/py{name:s}/lib{name:s}{ext[0]:s}"]
try:
print(f"checking rpaths")
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
print(" ".join(cmd) + " was not successful.")
# # check rpaths for Darwin
# if platform.system() == "Darwin":
# cmd = ["otool", "-L", f"./src/py{name:s}/lib{name:s}{ext[0]:s}"]
# try:
# print(f"checking rpaths")
# subprocess.check_call(cmd)
# except subprocess.CalledProcessError:
# print(" ".join(cmd) + " was not successful.")

version = None
with open("./VERSION", "r") as f:
version = f.read().strip()

fobj = open('./src/pycodata/version.py', "w")
fobj.write(f"__version__ = \"{version:s}\"")
fobj.close


if __name__ == "__main__":

Expand Down Expand Up @@ -139,5 +143,6 @@
runtime_library_dirs=runtime_library_dirs,
extra_objects=extra_objects)
setup(version=version,
ext_modules=[mod_constants_latest, mod_constants_2018, mod_constants_2014, mod_constants_2010, mod_version])
# ext_modules=[mod_constants_latest, mod_constants_2018, mod_constants_2014, mod_constants_2010, mod_version]
)

17 changes: 16 additions & 1 deletion py/src/pycodata/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
PY=python
GEN=../../../scripts/gen_cpython.py
GENPY=../../../scripts/gen_python.py

AST_DIR=../../../nist

AST_SRC=$(wildcard $(AST_DIR)/*.toml)
CPYTHON = cpy_codata_constants_2010.c cpy_codata_constants_2014.c cpy_codata_constants_2018.c cpy_codata_constants_2022.c
PYTHON = constants_2010.py constants_2014.py constants_2018.py constants_2022.py

.PHONY: clean

all: $(CPYTHON)
all: $(CPYTHON) $(PYTHON)

cpy_codata_constants_2010.c: $(AST_DIR)/codata_2010.toml
$(PY) $(GEN) $< $@
Expand All @@ -22,6 +24,19 @@ cpy_codata_constants_2018.c: $(AST_DIR)/codata_2018.toml
cpy_codata_constants_2022.c: $(AST_DIR)/codata_2022.toml
$(PY) $(GEN) $< $@

constants_2010.py: $(AST_DIR)/codata_2010.toml
$(PY) $(GENPY) $< $@

constants_2014.py: $(AST_DIR)/codata_2014.toml
$(PY) $(GENPY) $< $@

constants_2018.py: $(AST_DIR)/codata_2018.toml
$(PY) $(GENPY) $< $@

constants_2022.py: $(AST_DIR)/codata_2022.toml
$(PY) $(GENPY) $< $@

clean:
rm -rf $(CPYTHON)
rm -rf $(PYTHON)

Loading

0 comments on commit fc68e14

Please sign in to comment.