Skip to content

Commit

Permalink
[SymForce] Rework packaging
Browse files Browse the repository at this point in the history
symforce-sym and skymarshal are pure pyproject.toml.  Hatchling is
apparently the current sota but I wasn't going that far

Also add py.typed to our packages to mark them as typed

Have checked skymarshal and symforce-sym wheels, will check symforce
before merging

Topic: sf-packaging
GitOrigin-RevId: 75b7e92d6b9ace5ba481c9960d06b7b9b1bb7825
  • Loading branch information
aaron-skydio committed May 8, 2024
1 parent 4cc4add commit bd60d57
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 104 deletions.
24 changes: 24 additions & 0 deletions gen/python/pyproject.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions gen/python/setup.py

This file was deleted.

Empty file added gen/python/sym/py.typed
Empty file.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def fixed_readme() -> str:
"symengine": "third_party/symenginepy/symengine",
"lcmtypes": "lcmtypes_build/lcmtypes",
},
package_data={"": ["*.jinja", "*.mtx", "README*", ".clang-format"]},
package_data={"": ["*.jinja", "*.mtx", "README*", ".clang-format", "py.typed"]},
# pyproject.toml doesn't allow specifying url or homepage separately, and if it's not
# specified separately PyPI sorts all the links alphabetically
# https://github.com/pypi/warehouse/issues/3097
Expand Down
22 changes: 22 additions & 0 deletions symforce/codegen/backends/python/templates/pyproject.toml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{# ----------------------------------------------------------------------------
# SymForce - Copyright 2022, Skydio, Inc.
# This source code is under the Apache 2.0 license found in the LICENSE file.
# ---------------------------------------------------------------------------- #}

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "{{ package_name }}"
description = "{{ description }} (installed by SymForce)"
authors = [{ name = "Skydio, Inc.", email = "[email protected]" }]
license = { text = "Apache 2.0" }
version = "{{ version }}"
dependencies = ["numpy"]
requires-python = ">=2.7"

[project.urls]
SymForce = "https://symforce.org"
"Bug Tracker" = "https://github.com/symforce-org/symforce/issues"
Source = "https://github.com/symforce-org/symforce/tree/main/gen/python"
26 changes: 0 additions & 26 deletions symforce/codegen/backends/python/templates/setup.py.jinja

This file was deleted.

5 changes: 4 additions & 1 deletion symforce/codegen/template_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FileType(enum.Enum):
LCM = enum.auto()
MAKEFILE = enum.auto()
TYPESCRIPT = enum.auto()
TOML = enum.auto()

@staticmethod
def from_extension(extension: str) -> FileType:
Expand All @@ -50,6 +51,8 @@ def from_extension(extension: str) -> FileType:
return FileType.MAKEFILE
elif extension == "ts":
return FileType.TYPESCRIPT
elif extension == "toml":
return FileType.TOML
else:
raise ValueError(f"Could not get FileType from extension {extension}")

Expand All @@ -68,7 +71,7 @@ def comment_prefix(self) -> str:
"""
if self in (FileType.CPP, FileType.CUDA, FileType.LCM):
return "//"
elif self in (FileType.PYTHON, FileType.PYTHON_INTERFACE):
elif self in (FileType.PYTHON, FileType.PYTHON_INTERFACE, FileType.TOML):
return "#"
else:
raise NotImplementedError(f"Unknown comment prefix for {self}")
Expand Down
Empty file added symforce/py.typed
Empty file.
13 changes: 8 additions & 5 deletions test/symforce_gen_codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ----------------------------------------------------------------------------

import asyncio
import dataclasses
import math
import sys
from pathlib import Path
Expand Down Expand Up @@ -93,24 +94,26 @@ def test_gen_package_codegen_python(self) -> None:
cam_package_codegen.generate(config=config, output_dir=output_dir)
template_util.render_template(
template_dir=config.template_dir(),
template_path="setup.py.jinja",
output_path=output_dir / "setup.py",
template_path="pyproject.toml.jinja",
output_path=output_dir / "pyproject.toml",
data=dict(
package_name="symforce-sym",
version=symforce.__version__,
description="generated numerical python package",
long_description="generated numerical python package",
),
config=config.render_template_config,
config=dataclasses.replace(config.render_template_config, autoformat=False),
)

(output_dir / "sym" / "py.typed").touch()

# Test against checked-in geo package (only on SymEngine)
if symforce.get_symbolic_api() == "symengine":
self.compare_or_update_directory(
actual_dir=output_dir / "sym", expected_dir=SYMFORCE_DIR / "gen" / "python" / "sym"
)
self.compare_or_update_file(
new_file=output_dir / "setup.py", path=SYMFORCE_DIR / "gen" / "python" / "setup.py"
new_file=output_dir / "pyproject.toml",
path=SYMFORCE_DIR / "gen" / "python" / "pyproject.toml",
)

# Compare against the checked-in tests
Expand Down
29 changes: 29 additions & 0 deletions third_party/skymarshal/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "skymarshal"
description = "Python implementation of marshalling for LCM messages"
version = "0.9.0"
authors = [{ name = "Skydio, Inc." }]
license = { text = "LGPL-2.1-or-later" }
readme = "README.md"
classifiers = [
"Intended Audience :: Developers",
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
]
requires-python = ">=3.8"
dependencies = ["argh", "jinja2", "numpy", "ply"]

[project.urls]
"Bug Tracker" = "https://github.com/symforce-org/symforce/issues"
Source = "https://github.com/symforce-org/symforce/tree/main/third_party/skymarshal"

[tool.setuptools.packages.find]
include = ["skymarshal", "skymarshal.*"]
35 changes: 0 additions & 35 deletions third_party/skymarshal/setup.cfg

This file was deleted.

8 changes: 0 additions & 8 deletions third_party/skymarshal/setup.py

This file was deleted.

Empty file.

0 comments on commit bd60d57

Please sign in to comment.