Skip to content

Commit

Permalink
Entry point support
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Apr 30, 2022
1 parent 03ee59c commit 123ce92
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ example projects.

## Planned features

- Entry point support
- Namespace package support ([PEP 420](https://www.python.org/dev/peps/pep-0420/))
- Doxygen and Sphinx support
- OSX support
- [x] ~~Entry point support~~
- [ ] Namespace package support ([PEP 420](https://www.python.org/dev/peps/pep-0420/))
- [ ] Doxygen and Sphinx support
- [ ] OSX support
2 changes: 1 addition & 1 deletion examples/minimal/src-python/minimal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
A simple, minimal example of building a Python C module using CMake.
"""
__version__ = '0.0.5'
__version__ = '0.0.6'
2 changes: 1 addition & 1 deletion examples/pybind11-project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
project(py-build-cmake VERSION 0.0.5)
project(py-build-cmake VERSION 0.0.6)
set(PY_VERSION_SUFFIX "")
set(PY_FULL_VERSION ${PROJECT_VERSION}${PY_VERSION_SUFFIX})

Expand Down
3 changes: 3 additions & 0 deletions examples/pybind11-project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ urls = { "Documentation" = "https://tttapa.github.io/" }
dependencies = []
dynamic = ["version", "description"]

[project.scripts]
add = "pybind11_project.add:main"

[build-system]
requires = ["py-build-cmake", "pybind11", "pybind11-stubgen", "mypy"]
build-backend = "py_build_cmake.build"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Example project using the py-build-cmake build backend and pybind11."""
__version__ = '0.0.5'
__version__ = '0.0.6'
10 changes: 10 additions & 0 deletions examples/pybind11-project/python-src/pybind11_project/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .add_module import add
import sys

def main():
"""Script that adds all command line arguments as integers."""
sum = 0
for el in sys.argv[1:]:
sum = add(sum, int(el))
print(sum)
return 0
2 changes: 1 addition & 1 deletion src/py_build_cmake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Modern, PEP 517 compliant build backend for building Python packages with
extensions built using CMake.
"""
__version__ = '0.0.5'
__version__ = '0.0.6'
22 changes: 10 additions & 12 deletions src/py_build_cmake/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class _BuildBackend(object):
def __init__(self) -> None:
self.verbose = False

fileopt = {'encoding': 'utf-8'}

def get_requires_for_build_wheel(self, config_settings=None):
"""https://www.python.org/dev/peps/pep-0517/#get-requires-for-build-wheel"""
return []
Expand Down Expand Up @@ -167,14 +165,14 @@ def build_wheel_in_dir(self,

# Write metadata
metadata_path = distinfo / 'METADATA'
with open(metadata_path, 'w', **self.fileopt) as f:
with open(metadata_path, 'w', encoding='utf-8') as f:
metadata.write_metadata_file(f)

# Write or copy license
self.write_license_files(cfg.license, src_dir, distinfo)

# TODO: write entrypoints
self.write_entrypoints(cfg)
# Write entrypoints
self.write_entrypoints(distinfo, cfg)

# Generate .pyi stubs
if cfg.stubgen is not None and not editable:
Expand Down Expand Up @@ -243,14 +241,14 @@ def normalize_version(self, version):

def write_license_files(self, license, srcdir: Path, distinfo_dir: Path):
if 'text' in license:
with open(distinfo_dir / 'LICENSE', 'w', encoding='utf-8') as f:
with (distinfo_dir / 'LICENSE').open('w', encoding='utf-8') as f:
f.write(license['text'])
elif 'file' in license:
shutil.copy2(srcdir / license['file'], distinfo_dir)

def write_editable_wrapper(self, tmp_build_dir: Path, src_dir: Path, pkg):
# Write a fake __init__.py file that points to the development folder
tmp_pkg = tmp_build_dir / pkg.name
tmp_pkg: Path = tmp_build_dir / pkg.name
os.makedirs(tmp_pkg, exist_ok=True)
special_dunders = [
'__builtins__', '__cached__', '__file__', '__loader__', '__name__',
Expand All @@ -276,7 +274,7 @@ def write_editable_wrapper(self, tmp_build_dir: Path, src_dir: Path, pkg):
del _util
"""
(tmp_pkg / '__init__.py').write_text(textwrap.dedent(content),
**self.fileopt)
encoding='utf-8')
# Add the py.typed file if it exists, so mypy picks up the stubs for
# the C++ extensions
py_typed: Path = pkg.path / 'py.typed'
Expand Down Expand Up @@ -427,10 +425,10 @@ def get_build_config_name(cross_cfg):
_BuildBackend.get_cross_tags(cross_cfg).values()))
return buildconfig

def write_entrypoints(self, cfg: Config):
if cfg.entrypoints:
print(cfg.entrypoints)
raise RuntimeWarning("Entrypoints are not currently supported")
def write_entrypoints(self, distinfo: Path, cfg: Config):
from flit_core.common import write_entry_points
with (distinfo / 'entry_points.txt').open('w', encoding='utf-8') as f:
write_entry_points(cfg.entrypoints, f)

def create_wheel(self, wheel_directory, tmp_build_dir, cfg, norm_name,
norm_version):
Expand Down

0 comments on commit 123ce92

Please sign in to comment.