Skip to content

Commit b8c9250

Browse files
committed
modernize pip package creation
1 parent 4482cdd commit b8c9250

File tree

2 files changed

+54
-76
lines changed

2 files changed

+54
-76
lines changed

pyproject.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel", "pybind11", "cmake"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "fsmod"
7+
version = "0.4.0"
8+
description = "A simulated file system module for SimGrid"
9+
authors = [
10+
{ name = "FSMod Team", email = "simgrid-community@inria.fr" }
11+
]
12+
readme = "README.md"
13+
license = { text = "LGPL-2.1-only" }
14+
requires-python = ">=3.7"
15+
dependencies = [
16+
"pybind11>=2.4",
17+
"simgrid>=4.1"
18+
]
19+
20+
classifiers = [
21+
"Development Status :: 4 - Beta",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: C++",
24+
"License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)",
25+
"Operating System :: POSIX",
26+
"Operating System :: MacOS",
27+
"Topic :: System :: Distributed Computing"
28+
]
29+
30+
[project.urls]
31+
Source = "https://github.com/simgrid/file-system-module"

setup.py

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,51 @@
55

66
# python3 setup.py sdist # Build a source distrib (building binary distribs is complex on linux)
77

8-
# twine upload --repository-url https://test.pypi.org/legacy/ dist/fsmod-*.tar.gz # Upload to test
9-
# pip3 install --user --index-url https://test.pypi.org/simple fsmod
8+
# python3 -m build --sdist # Build a source distrib (building binary distribs is complex on linux)
9+
10+
# twine upload --repository-url https://test.pypi.org/legacy/ dist/dtlmod-*.tar.gz # Upload to test
11+
# pip3 install --extra-index-url https://test.pypi.org/simple dtlmod
1012

1113
# Once it works, upload to the real infra. /!\ you cannot modify a file once uploaded
12-
# twine upload dist/fsmod-*.tar.gz
14+
# twine upload dist/dtlmod-*.tar.gz
1315

1416
import os
15-
import platform
16-
import re
17-
import subprocess
1817
import sys
19-
from distutils.version import LooseVersion
20-
21-
from setuptools import Extension, setup
18+
import subprocess
19+
from setuptools import setup, Extension
2220
from setuptools.command.build_ext import build_ext
2321

2422
class CMakeExtension(Extension):
25-
def __init__(self, name, sourcedir=''):
26-
Extension.__init__(self, name, sources=[])
23+
def __init__(self, name, sourcedir=""):
24+
super().__init__(name, sources=[])
2725
self.sourcedir = os.path.abspath(sourcedir)
2826

2927
class CMakeBuild(build_ext):
3028
def run(self):
3129
try:
32-
out = subprocess.check_output(['cmake', '--version'])
30+
subprocess.check_output(["cmake", "--version"])
3331
except OSError:
34-
raise RuntimeError(
35-
"CMake must be installed to build python bindings of FSMod")
36-
37-
if not os.path.exists("MANIFEST.in"):
38-
raise RuntimeError(
39-
"Please generate a MANIFEST.in file at the root of the source directory")
32+
raise RuntimeError("CMake must be installed to build the file-system-module")
4033

4134
for ext in self.extensions:
4235
self.build_extension(ext)
4336

4437
def build_extension(self, ext):
4538
from pybind11 import get_cmake_dir
46-
extdir = os.path.abspath(os.path.dirname(
47-
self.get_ext_fullpath(ext.name)))
48-
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
49-
'-DPYTHON_EXECUTABLE=' + sys.executable,
50-
'-Denable_python=ON',
51-
'-Dpybind11_DIR=' + get_cmake_dir()
52-
]
53-
54-
build_args = []
55-
56-
env = os.environ.copy()
57-
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
58-
self.distribution.get_version())
59-
env['LDFLAGS'] = '{} -L{}'.format(env.get('LDFLAGS', ''), extdir)
60-
env['MAKEFLAGS'] = '-j'+str(os.cpu_count())
61-
# env['VERBOSE'] = "1" # Please, make, be verbose about the commands you run
6239

63-
if not os.path.exists(self.build_temp):
64-
os.makedirs(self.build_temp)
65-
subprocess.check_call(['cmake', ext.sourcedir] +
66-
cmake_args, cwd=self.build_temp, env=env)
67-
subprocess.check_call(['cmake', '--build', '.'] +
68-
build_args, cwd=self.build_temp, env=env)
40+
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
41+
cmake_args = [
42+
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
43+
f"-DPYTHON_EXECUTABLE={sys.executable}",
44+
"-Denable_python=ON",
45+
f"-Dpybind11_DIR={get_cmake_dir()}",
46+
]
6947

48+
os.makedirs(self.build_temp, exist_ok=True)
49+
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp)
50+
subprocess.check_call(["cmake", "--build", "."], cwd=self.build_temp)
7051

7152
setup(
72-
name='fsmod',
73-
version='0.4.0',
74-
author='The FSMod Team',
75-
author_email='simgrid-community@inria.fr',
76-
description='File System Module for SimGrid',
77-
long_description=("This project implements a simulated file system "module" on top of SimGrid, to be "
78-
"used in any SimGrid-based simulator. It supports the notion of partitions that store "
79-
"directories that store files, with the expected operations (e.g., create files, move "
80-
"files, unlink files, unlink directories, check for existence), and the notion of a file "
81-
"descriptor with POSIX-like operations (open, seek, read, write, close).\n\n"
82-
"This package contains a native library. Please install cmake, boost, pybind11 and a "
83-
"C++ compiler before using pip3. On Debian/Ubuntu, this is as easy as\n"
84-
"sudo apt install cmake libboost-dev pybind11-dev g++ gcc"),
85-
ext_modules=[CMakeExtension('fsmod')],
86-
cmdclass=dict(build_ext=CMakeBuild),
87-
install_requires=['pybind11>=2.4'],
88-
setup_requires=['pybind11>=2.4'],
89-
zip_safe=False,
90-
classifiers=[
91-
"Development Status :: 4 - Beta",
92-
"Environment :: Console",
93-
"Intended Audience :: Education",
94-
"Intended Audience :: Developers",
95-
"Intended Audience :: Science/Research",
96-
"Intended Audience :: System Administrators",
97-
"License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)",
98-
"Operating System :: POSIX",
99-
"Operating System :: MacOS",
100-
"Programming Language :: Python :: 3",
101-
"Programming Language :: C++",
102-
"Topic :: System :: Distributed Computing",
103-
"Topic :: System :: Systems Administration",
104-
],
105-
project_urls={
106-
'Source': 'https://github.com/simgrid/file-system-module',
107-
},
53+
ext_modules=[CMakeExtension("fsmod")],
54+
cmdclass={"build_ext": CMakeBuild},
10855
)

0 commit comments

Comments
 (0)