Skip to content

Commit

Permalink
trying to add sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
ljrobins committed Jan 28, 2024
1 parent 7eab94d commit c5788f9
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 124 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ script
*.egg-info
build
*.cfg
*.pytest*
*.pytest*
.vscode
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"files.associations": {
"pthread.h": "c",
"arrayobject.h": "c",
"__locale": "c"
}
"liveServer.settings.port": 5501
}
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
.PHONY: build
.PHONY: clean test all install docs

build:
install:
source bin/activate && pip install -e .

clean:
rm -rf build
rm -rf setup.py
poetry version patch
poetry build
rm -rf *.so

test:
pytest tests/*.py

sphinx:
cd docs && make html

start-runner:
actions-runner/run.sh

publish:
poetry publish
all: clean install test
2 changes: 0 additions & 2 deletions config.toml

This file was deleted.

20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
33 changes: 33 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'gravitas'
copyright = '2024, Liam Robinson'
author = 'Liam Robinson'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
]
autosummary_generate = True

templates_path = ['_templates']
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
4 changes: 4 additions & 0 deletions docs/source/gravitas.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gravitas
========

.. automodule:: gravitas
12 changes: 12 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. gravitas documentation master file, created by
sphinx-quickstart on Sun Jan 28 00:58:46 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to gravitas's documentation!
====================================

.. toctree::
:maxdepth: 2

gravitas
22 changes: 0 additions & 22 deletions gravitas/setup.py

This file was deleted.

34 changes: 16 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# [tool.cibuildwheel]
skip = "pp* *-manylinux_i686 *_ppc64le *_s390x *-musllinux_aarch64"
# This is actually used, lol

[tool.cibuildwheel.linux]
manylinux-x86_64-image = "manylinux2014"
manylinux-aarch64-image = "manylinux2014"
musllinux-x86_64-image = "musllinux_1_1"
environment = {RUNNER_OS="Linux"}
[project]
name = "gravitas"
version = "0.0.1"
authors = [{name = "Liam Robinson", email = "liamers127@gmail.com"}]
description = "Gravity field modeling for astrodynamics"
requires-python = ">=3.9"

[tool.cibuildwheel.macos]
archs = "x86_64 arm64"
test-skip = "*_universal2:arm64"
# MACOS linker doesn't support stripping symbols
environment = {RUNNER_OS="macOS"}

[tool.cibuildwheel.windows]
environment = { CFLAGS="Wall", LDFLAGS="" }
[project.urls]
Homepage = "https://example.com"
Repository = "https://github.com/liamrobinson1/gravitas"
Documentation = "https://yourprojectdocs.com"

[build-system]
requires = ["setuptools>=42", "wheel", "numpy"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=42", "wheel", "numpy>=1.19.2", "pybind11>=2.11.0", "eigency>=1.6.0", "setuptools-scm>=8.0"]
build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
build = ["cp312-*", "cp311-*"]
skip = ["*win32*"]
65 changes: 19 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

from distutils.core import setup
from pybind11.setup_helpers import Pybind11Extension
import eigency
import platform
import os
import numpy as np

_SOURCES = [os.path.join('gravitas', x) for x in os.listdir('gravitas') if x.endswith('.c')]
_INCDIR = ['gravitas', np.get_include()]
std_arg = '-std=c++17'
opt_arg = '-O3'
if platform.system() == 'Windows':
std_arg = '/std:c++17'
opt_arg = '/O2'

class CustomBuildExt(build_ext):
def build_extensions(self):
super().build_extensions()
ext_modules = [
Pybind11Extension(
name="gravitas",
sources=[os.path.join("src", "python_bindings.cpp")],
include_dirs=['src', *tuple(eigency.get_includes())],
extra_compile_args=[std_arg, opt_arg],
),
]

# _LIB_DIR
setup(
name='gravitas',
version='0.1.25',
packages=find_packages(),
license='GPL-2',
long_description="""High-fidelity gravity fields for satellite propagation""",
long_description_content_type='text/markdown',
author="Liam Robinson",
author_email="robin502@purdue.edu",
install_requires=['numpy'],
package_data={'gravitas': ['libgrav.h']},
classifiers=[
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
],
ext_modules=[
Extension(
# the qualified name of the extension module to build
'gravitas._grav',
# the files to compile into our module relative to ``setup.py``
sources=_SOURCES,
include_dirs=_INCDIR,
extra_compile_args=['-O3', '-march=native', '-ffast-math', '-fopenmp'],
),
],
cmdclass={
'build_ext': CustomBuildExt,
},
zip_safe=False, # Allow the package to be unzipped without modification
)
setup(name = 'gravitas',
ext_modules=ext_modules)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 12 additions & 1 deletion gravitas/python_bindings.cpp → src/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ using namespace std;
#include "libgrav.hpp"

PYBIND11_MODULE(gravitas, m) {
m.doc() = "gravitas module"; // Optional module docstring
m.doc() = R"pbdoc(
Pybind11 example plugin
-----------------------
.. currentmodule:: gravitas
.. autosummary::
:toctree: _generate
add
subtract
)pbdoc";
m.def("earth_acceleration", &earth_acceleration, "A function that returns the acceleration of a body due to a gravity model");
m.def("moon_acceleration", &moon_acceleration, "A function that returns the acceleration of a body due to a gravity model");
}
15 changes: 0 additions & 15 deletions test_ext.py

This file was deleted.

7 changes: 0 additions & 7 deletions gravitas/test.py → tests/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import os
os.system('python setup.py clean --all && python setup.py build_ext --inplace')
import time
import gravitas
import numpy as np

import pytest

def test_over_nmax():
with pytest.raises(SystemError):
gravitas.earth_acceleration(np.array([[0, 0, 0]]), 361)

def test_bad_name():
with pytest.raises(SystemError):
gravitas.earth_acceleration(np.array([[0, 0, 0]]), 16)

def test_negative_nmax():
with pytest.raises(SystemError):
gravitas.earth_acceleration(np.array([[0, 0, 0]]), -1)
Expand Down

0 comments on commit c5788f9

Please sign in to comment.