From 0ec57a3a3e3d89095d8715309a1f74e1b7277006 Mon Sep 17 00:00:00 2001
From: Dmytro Yaroshenko <73843436+o-murphy@users.noreply.github.com>
Date: Wed, 18 Oct 2023 15:49:52 +0300
Subject: [PATCH] Cython optional (#29)
* optional Cython dependency
* fixes for a workflows
* small import fixes
---
.github/workflows/python-package.yml | 25 ++-
.github/workflows/python-publish-test.yml | 17 +-
.github/workflows/python-publish.yml | 6 +
Manifest.in | 5 +-
py_ballisticcalc/__init__.py | 12 +-
py_ballisticcalc/backend.py | 15 ++
.../{pure/py_drag_model.py => drag_model.py} | 10 +-
py_ballisticcalc/example.py | 7 +-
py_ballisticcalc/interface.py | 5 +-
py_ballisticcalc/logger.py | 13 ++
py_ballisticcalc/multiple_bc.py | 5 +-
py_ballisticcalc/munition.py | 8 +-
py_ballisticcalc/pure/__init__.py | 4 -
..._trajectory_calc.py => trajectory_calc.py} | 15 +-
py_ballisticcalc/unit.py | 4 +-
py_ballisticcalc_exts/LICENSE | 165 ++++++++++++++++
py_ballisticcalc_exts/Manifest.in | 3 +
py_ballisticcalc_exts/README.md | 185 ++++++++++++++++++
py_ballisticcalc_exts/__init__.py | 1 +
py_ballisticcalc_exts/py.typed | 0
.../py_ballisticcalc_exts/__init__.py | 8 +
.../py_ballisticcalc_exts}/drag_model.pyi | 0
.../py_ballisticcalc_exts}/drag_model.pyx | 8 +-
.../trajectory_calc.pyx | 10 +-
py_ballisticcalc_exts/pyproject.toml | 51 +++++
py_ballisticcalc_exts/setup.py | 69 +++++++
pyproject.toml | 12 +-
requirements.txt | 1 -
setup.py | 66 +------
tests/test_binary_import.py | 14 ++
tests/test_danger_space.py | 4 -
tests/test_interface.py | 4 -
tests/test_mbc.py | 4 -
tests/test_performance.py | 4 -
tests/test_trajectory.py | 4 -
tests/test_units.py | 5 -
36 files changed, 601 insertions(+), 168 deletions(-)
create mode 100644 py_ballisticcalc/backend.py
rename py_ballisticcalc/{pure/py_drag_model.py => drag_model.py} (90%)
create mode 100644 py_ballisticcalc/logger.py
delete mode 100644 py_ballisticcalc/pure/__init__.py
rename py_ballisticcalc/{pure/py_trajectory_calc.py => trajectory_calc.py} (97%)
create mode 100644 py_ballisticcalc_exts/LICENSE
create mode 100644 py_ballisticcalc_exts/Manifest.in
create mode 100644 py_ballisticcalc_exts/README.md
create mode 100644 py_ballisticcalc_exts/__init__.py
create mode 100644 py_ballisticcalc_exts/py.typed
create mode 100644 py_ballisticcalc_exts/py_ballisticcalc_exts/__init__.py
rename {py_ballisticcalc => py_ballisticcalc_exts/py_ballisticcalc_exts}/drag_model.pyi (100%)
rename {py_ballisticcalc => py_ballisticcalc_exts/py_ballisticcalc_exts}/drag_model.pyx (92%)
rename {py_ballisticcalc => py_ballisticcalc_exts/py_ballisticcalc_exts}/trajectory_calc.pyx (98%)
create mode 100644 py_ballisticcalc_exts/pyproject.toml
create mode 100644 py_ballisticcalc_exts/setup.py
delete mode 100644 requirements.txt
create mode 100644 tests/test_binary_import.py
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
index 8db2c76..dd48712 100644
--- a/.github/workflows/python-package.yml
+++ b/.github/workflows/python-package.yml
@@ -20,19 +20,32 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
+
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential -y
python -m pip install --upgrade pip
- # python -m pip install flake8
- python -m pip install cython
- python -m pip install pytest
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+ python -m pip install setuptools pytest cython
+
+ - name: Run unittest tests in pure python mode
+ run: |
+ if pytest tests --no-header --no-summary -v; then
+ echo "Pytest succeeded."
+ else
+ echo "Pytest failed, running without capture"
+ # Add your additional commands here
+ pytest tests --no-header --no-summary -v -s
+ fi
+
+ - name: Build cython modules
+ run: |
+ cd py_ballisticcalc_exts
+ python setup.py build_ext --inplace
+ cd ..
- # python setup.py build_ext --inplace
- - name: Run unittest tests
+ - name: Run unittest tests in binary mode
run: |
if pytest tests --no-header --no-summary -v; then
echo "Pytest succeeded."
diff --git a/.github/workflows/python-publish-test.yml b/.github/workflows/python-publish-test.yml
index 972fbb6..05b40a8 100644
--- a/.github/workflows/python-publish-test.yml
+++ b/.github/workflows/python-publish-test.yml
@@ -1,8 +1,6 @@
name: Upload Python Package to Test PyPI
on:
-# release:
-# types: [created, draft, edited]
workflow_dispatch:
permissions:
@@ -30,6 +28,12 @@ jobs:
- name: Build package
run: python -m build
+ - name: Build extensions package
+ run: |
+ cd py_ballisticcalc_exts
+ python -m build --outdir ../dist
+ cd ..
+
- name: Publish package to Test PyPI
run: |
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/* --skip-existing --verbose --non-interactive
@@ -37,15 +41,6 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
-# - name: Publish package to Test PyPI
-# uses: pypa/gh-action-pypi-publish@release/v1
-# with:
-# repository-url: https://test.pypi.org/legacy/
-# user: __token__
-# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
-# skip-existing: true
-# verbose: true
-
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml
index 42c1b82..7844115 100644
--- a/.github/workflows/python-publish.yml
+++ b/.github/workflows/python-publish.yml
@@ -39,6 +39,12 @@ jobs:
- name: Build package
run: python -m build
+ - name: Build extensions package
+ run: |
+ cd py_ballisticcalc_exts
+ python -m build --outdir ../dist
+ cd ..
+
- name: Publish package to PyPI
run: |
python -m twine upload dist/* --skip-existing --verbose --non-interactive
diff --git a/Manifest.in b/Manifest.in
index 4afd20c..a01f4e7 100644
--- a/Manifest.in
+++ b/Manifest.in
@@ -1,4 +1,3 @@
-recursive-include py_ballisticcalc *.pyx
-recursive-include py_ballisticcalc *.pyi
-include requirements*.txt
+prune py_ballisticcalc_exts
+prune tests
include py.typed
diff --git a/py_ballisticcalc/__init__.py b/py_ballisticcalc/__init__.py
index d97a18a..4f48f9f 100644
--- a/py_ballisticcalc/__init__.py
+++ b/py_ballisticcalc/__init__.py
@@ -4,16 +4,10 @@
__copyright__ = ("",)
__credits__ = ["o-murphy"]
-__version__ = "1.1.0b9"
+__version__ = "1.1.0"
-import logging
-try:
- from .drag_model import * # pylint: disable=import-error
- from .trajectory_calc import * # pylint: disable=import-error
-except ImportError:
- logging.warning("Package installed in --no-binary (pure python) mode, "
- "use .whl packages to get better performance")
- from .pure import *
+
+from .backend import *
from .drag_tables import *
from .settings import *
from .multiple_bc import *
diff --git a/py_ballisticcalc/backend.py b/py_ballisticcalc/backend.py
new file mode 100644
index 0000000..a94c74a
--- /dev/null
+++ b/py_ballisticcalc/backend.py
@@ -0,0 +1,15 @@
+"""Searching for an available backends"""
+
+from .logger import logger
+
+# trying to use cython based backend
+try:
+ from py_ballisticcalc_exts import * # pylint: disable=wildcard-import
+
+ logger.info("Binary modules found, running in binary mode")
+except ImportError as error:
+ from .drag_model import *
+ from .trajectory_calc import *
+
+ logger.warning("Library running in pure python mode. "
+ "For better performance install 'py_ballisticcalc.exts' package")
diff --git a/py_ballisticcalc/pure/py_drag_model.py b/py_ballisticcalc/drag_model.py
similarity index 90%
rename from py_ballisticcalc/pure/py_drag_model.py
rename to py_ballisticcalc/drag_model.py
index b8acc26..591d2a0 100644
--- a/py_ballisticcalc/pure/py_drag_model.py
+++ b/py_ballisticcalc/drag_model.py
@@ -1,13 +1,15 @@
+"""definitions for a bullet's drag model calculation"""
+
import typing
from dataclasses import dataclass
import math
-from ..settings import Settings as Set
-from ..unit import Weight, Distance
-from ..drag_tables import DragTablesSet
+from .settings import Settings as Set
+from .unit import Weight, Distance
+from .drag_tables import DragTablesSet
-__all__ = ('DragModel', )
+__all__ = ('DragModel', 'make_data_points')
@dataclass
diff --git a/py_ballisticcalc/example.py b/py_ballisticcalc/example.py
index fe38141..6055e5a 100644
--- a/py_ballisticcalc/example.py
+++ b/py_ballisticcalc/example.py
@@ -1,10 +1,7 @@
"""Example of library usage"""
-from py_ballisticcalc import Velocity, Temperature, Distance
-from py_ballisticcalc import DragModel, TableG7
-from py_ballisticcalc import Ammo, Atmo, Wind
-from py_ballisticcalc import Weapon, Shot, Calculator
+from py_ballisticcalc import *
from py_ballisticcalc import Settings as Set
@@ -14,7 +11,7 @@
# Set.Units.distance = Distance.Meter
Set.Units.sight_height = Distance.Centimeter
-Set.set_max_calc_step_size(Distance.Foot(1))
+# Set.set_max_calc_step_size(Distance.Foot(1))
Set.USE_POWDER_SENSITIVITY = True # enable muzzle velocity correction my powder temperature
# define params with default units
diff --git a/py_ballisticcalc/interface.py b/py_ballisticcalc/interface.py
index 0a2f308..dad7124 100644
--- a/py_ballisticcalc/interface.py
+++ b/py_ballisticcalc/interface.py
@@ -4,10 +4,7 @@
from .conditions import Atmo, Shot
from .munition import Weapon, Ammo
# pylint: disable=import-error,no-name-in-module
-try:
- from .trajectory_calc import * # pylint: disable=import-error
-except ImportError:
- from .pure.py_trajectory_calc import *
+from .backend import *
from .trajectory_data import HitResult
from .unit import Angular, Distance
from .settings import Settings
diff --git a/py_ballisticcalc/logger.py b/py_ballisticcalc/logger.py
new file mode 100644
index 0000000..c3c21fd
--- /dev/null
+++ b/py_ballisticcalc/logger.py
@@ -0,0 +1,13 @@
+"""Default logger for py_ballisticcalc library"""
+
+import logging
+
+__all__ = ('logger',)
+
+formatter = logging.Formatter("%(levelname)s:%(name)s:%(message)s")
+console_handler = logging.StreamHandler()
+console_handler.setFormatter(formatter)
+
+logger = logging.getLogger('py_balcalc')
+logger.addHandler(console_handler)
+logger.setLevel(logging.INFO)
diff --git a/py_ballisticcalc/multiple_bc.py b/py_ballisticcalc/multiple_bc.py
index 5536a16..80fd36b 100644
--- a/py_ballisticcalc/multiple_bc.py
+++ b/py_ballisticcalc/multiple_bc.py
@@ -5,10 +5,7 @@
from .conditions import Atmo
# pylint: disable=import-error,no-name-in-module
-try:
- from .drag_model import make_data_points
-except ImportError:
- from .pure.py_drag_model import make_data_points
+from .backend import make_data_points
from .settings import Settings as Set
from .unit import Distance, Weight, Velocity
diff --git a/py_ballisticcalc/munition.py b/py_ballisticcalc/munition.py
index 54fd57c..2e4b06f 100644
--- a/py_ballisticcalc/munition.py
+++ b/py_ballisticcalc/munition.py
@@ -1,13 +1,7 @@
"""Module for Weapon and Ammo properties definitions"""
-
import math
from dataclasses import dataclass, field
-# pylint: disable=import-error,no-name-in-module
-try:
- from .drag_model import DragModel
-except ImportError:
- from .pure.py_drag_model import DragModel
from .settings import Settings as Set
from .unit import TypedUnits, Velocity, Temperature, Distance, Angular
@@ -44,7 +38,7 @@ def __post_init__(self):
class Ammo(TypedUnits):
"""Creates Ammo and Projectile properties"""
- dm: DragModel
+ dm: 'DragModel'
length: [float, Distance] = field(default_factory=lambda: Set.Units.length)
mv: [float, Velocity] = field(default_factory=lambda: Set.Units.velocity)
temp_modifier: float = field(default=0)
diff --git a/py_ballisticcalc/pure/__init__.py b/py_ballisticcalc/pure/__init__.py
deleted file mode 100644
index 7398043..0000000
--- a/py_ballisticcalc/pure/__init__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-"""Pure python implementation of the cython based modules"""
-
-from .py_drag_model import *
-from .py_trajectory_calc import *
diff --git a/py_ballisticcalc/pure/py_trajectory_calc.py b/py_ballisticcalc/trajectory_calc.py
similarity index 97%
rename from py_ballisticcalc/pure/py_trajectory_calc.py
rename to py_ballisticcalc/trajectory_calc.py
index ab0a574..21e21e8 100644
--- a/py_ballisticcalc/pure/py_trajectory_calc.py
+++ b/py_ballisticcalc/trajectory_calc.py
@@ -1,12 +1,14 @@
+"""pure python trajectory calculation backend"""
+
from dataclasses import dataclass
import math
from typing import NamedTuple
-from ..conditions import Atmo, Shot, Wind
-from ..munition import Ammo, Weapon
-from ..settings import Settings
-from ..trajectory_data import TrajectoryData, TrajFlag
-from ..unit import Distance, Angular, Velocity, Weight, Energy, Pressure, Temperature
+from .conditions import Atmo, Shot, Wind
+from .munition import Ammo, Weapon
+from .settings import Settings
+from .trajectory_data import TrajectoryData, TrajFlag
+from .unit import Distance, Angular, Velocity, Weight, Energy, Pressure, Temperature
__all__ = ('TrajectoryCalc', )
@@ -441,7 +443,10 @@ def calculate_curve(data_points):
curve.append(curve_point)
return curve
+
def calculate_by_curve(data: list, curve: list, mach: float):
+ """returning the calculated drag for a
+ specified mach based on previously calculated data"""
# num_points, mlo, mhi, mid
# cdef CurvePoint curve_m
diff --git a/py_ballisticcalc/unit.py b/py_ballisticcalc/unit.py
index 61e5e74..5e11cb1 100644
--- a/py_ballisticcalc/unit.py
+++ b/py_ballisticcalc/unit.py
@@ -10,9 +10,7 @@
__all__ = ('Unit', 'AbstractUnit', 'UnitPropsDict', 'Distance',
'Velocity', 'Angular', 'Temperature', 'Pressure',
- 'Energy', 'Weight',
- # 'is_unit',
- 'TypedUnits')
+ 'Energy', 'Weight', 'TypedUnits')
class Unit(IntEnum):
diff --git a/py_ballisticcalc_exts/LICENSE b/py_ballisticcalc_exts/LICENSE
new file mode 100644
index 0000000..0a04128
--- /dev/null
+++ b/py_ballisticcalc_exts/LICENSE
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/py_ballisticcalc_exts/Manifest.in b/py_ballisticcalc_exts/Manifest.in
new file mode 100644
index 0000000..925062c
--- /dev/null
+++ b/py_ballisticcalc_exts/Manifest.in
@@ -0,0 +1,3 @@
+recursive-include py_ballisticcalc_exts *.pyx
+recursive-include py_ballisticcalc_exts *.pyi
+include py.typed
diff --git a/py_ballisticcalc_exts/README.md b/py_ballisticcalc_exts/README.md
new file mode 100644
index 0000000..a6290fd
--- /dev/null
+++ b/py_ballisticcalc_exts/README.md
@@ -0,0 +1,185 @@
+# BallisticCalculator
+LGPL library for small arms ballistic calculations (Python 3.9+)
+
+### Table of contents
+* **[Installation](#installation)**
+ * [Latest stable](#latest-stable-release-from-pypi)
+ * [From sources](#installing-from-sources)
+ * [Clone and build](#clone-and-build)
+* **[Usage](#usage)**
+ * [Units of measure](#unit-manipulation-syntax)
+ * [An example of calculations](#an-example-of-calculations)
+ * [Output example](#example-of-the-formatted-output)
+* **[Older versions]()**
+ * [v1.0.x](https://github.com/o-murphy/py_ballisticcalc/tree/v1.0.12)
+* **[Contributors](#contributors)**
+* **[About project](#about-project)**
+
+### Installation
+#### Latest stable release from pypi**
+```shell
+pip install py-ballisticcalc
+```
+#### Installing from sources
+**MSVC** or **GCC** required
+* Download and install **MSVC** or **GCC** depending on target platform
+* Use one of the references you need:
+```shell
+# no binary from PyPi
+pip install py-ballisticcalc== --no-binary py-ballisticcalc
+
+# master brunch
+pip install git+https://github.com/o-murphy/py_ballisticcalc
+
+# specific branch
+pip install git+https://github.com/o-murphy/py_ballisticcalc.git@
+```
+
+#### Clone and build
+**MSVC** or **GCC** required
+```shell
+git clone https://github.com/o-murphy/py_ballisticcalc
+cd py_ballisticcalc
+python -m venv venv
+. venv/bin/activate
+pip install cython
+python setup.py build_ext --inplace
+```
+
+## Usage
+
+The library supports all the popular units of measurement, and adds different built-in methods to define and manipulate it
+#### Unit manipulation syntax:
+
+```python
+from py_ballisticcalc.unit import *
+
+# ways to define value in units
+# 1. old syntax
+unit_in_meter = Distance(100, Distance.Meter)
+# 2. short syntax by Unit type class
+unit_in_meter = Distance.Meter(100)
+# 3. by Unit enum class
+unit_in_meter = Unit.METER(100)
+
+# >>> : 100.0 m (3937.0078740157483)
+
+# convert unit
+# 1. by method
+unit_in_yard = unit_in_meter.convert(Distance.Yard)
+# 2. using shift syntax
+unit_in_yards = unit_in_meter << Distance.Yard # '<<=' operator also supports
+# >>> : 109.36132983377078 yd (3937.0078740157483)
+
+# get value in specified units
+# 1. by method
+value_in_km = unit_in_yards.get_in(Distance.Kilometer)
+# 2. by shift syntax
+value_in_km = unit_in_yards >> Distance.Kilometer # '>>=' operator also supports
+# >>> 0.1
+
+# getting unit raw value:
+rvalue = Distance.Meter(10).raw_value
+rvalue = float(Distance.Meter(10))
+
+# units comparison:
+# supports operators like < > <= >= == !=
+Distance.Meter(100) == Distance.Centimeter(100) # >>> False, compare two units by raw value
+Distance.Meter(100) > 10 # >>> True, compare unit with float by raw value
+```
+
+#### An example of calculations
+
+```python
+from py_ballisticcalc import Velocity, Temperature, Distance
+from py_ballisticcalc import DragModel, TableG7
+from py_ballisticcalc import Ammo, Atmo, Wind
+from py_ballisticcalc import Weapon, Shot, Calculator
+from py_ballisticcalc import Settings as Set
+
+
+# set global library settings
+Set.Units.velocity = Velocity.FPS
+Set.Units.temperature = Temperature.Celsius
+# Set.Units.distance = Distance.Meter
+Set.Units.sight_height = Distance.Centimeter
+
+Set.set_max_calc_step_size(Distance.Foot(1))
+Set.USE_POWDER_SENSITIVITY = True # enable muzzle velocity correction my powder temperature
+
+# define params with default units
+weight, diameter = 168, 0.308
+# or define with specified units
+length = Distance.Inch(1.282) # length = Distance(1.282, Distance.Inch)
+
+weapon = Weapon(9, 100, 2)
+dm = DragModel(0.223, TableG7, weight, diameter)
+
+ammo = Ammo(dm, length, 2750, 15)
+ammo.calc_powder_sens(2723, 0)
+
+zero_atmo = Atmo.icao(100)
+
+# defining calculator instance
+calc = Calculator(weapon, ammo, zero_atmo)
+
+current_atmo = Atmo(110, 1000, 15, 72)
+current_winds = [Wind(2, 90)]
+shot = Shot(1500, atmo=current_atmo, winds=current_winds)
+
+shot_result = calc.fire(shot, trajectory_step=Distance.Yard(100))
+
+for p in shot_result:
+ print(p.formatted())
+```
+#### Example of the formatted output:
+```shell
+python -m py_ballisticcalc.example
+```
+
+```
+['0.00 s', '0.000 m', '2750.0 ft/s', '2.46 mach', '-9.000 cm', '0.00 mil', '0.000 cm', '0.00 mil', '3825 J']
+['0.12 s', '100.000 m', '2528.6 ft/s', '2.26 mach', '0.005 cm', '0.00 mil', '-3.556 cm', '-0.36 mil', '3233 J']
+['0.26 s', '200.050 m', '2317.2 ft/s', '2.08 mach', '-7.558 cm', '-0.38 mil', '-13.602 cm', '-0.69 mil', '2715 J']
+['0.41 s', '300.050 m', '2116.6 ft/s', '1.90 mach', '-34.843 cm', '-1.18 mil', '-30.956 cm', '-1.05 mil', '2266 J']
+['0.57 s', '400.000 m', '1926.5 ft/s', '1.73 mach', '-85.739 cm', '-2.18 mil', '-57.098 cm', '-1.45 mil', '1877 J']
+['0.75 s', '500.000 m', '1745.0 ft/s', '1.56 mach', '-165.209 cm', '-3.37 mil', '-94.112 cm', '-1.92 mil', '1540 J']
+['0.95 s', '600.000 m', '1571.4 ft/s', '1.41 mach', '-279.503 cm', '-4.74 mil', '-144.759 cm', '-2.46 mil', '1249 J']
+```
+
+## Contributors
+### This project exists thanks to all the people who contribute.
+#### Special thanks to:
+- **[David Bookstaber](https://github.com/dbookstaber)** - Ballistics Expert, Financial Engineer \
+*For the help in understanding and improvement of some calculation methods*
+- **[Nikolay Gekht](https://github.com/nikolaygekht)** \
+*For the sources code on C# and GO-lang from which this project firstly was forked from*
+
+## About project
+
+The library provides trajectory calculation for projectiles including for various
+applications, including air rifles, bows, firearms, artillery and so on.
+
+3DF model that is used in this calculator is rooted in old C sources of version 2 of the public version of JBM
+calculator, ported to C#, optimized, fixed and extended with elements described in
+Litz's "Applied Ballistics" book and from the friendly project of Alexandre Trofimov
+and then ported to Go.
+
+Now it's also ported to python3 and expanded to support calculation trajectory by
+multiple ballistics coefficients and using custom drag data (such as Doppler radar data ©Lapua, etc.)
+
+The online version of Go documentation is located here: https://godoc.org/github.com/gehtsoft-usa/go_ballisticcalc
+
+C# version of the package is located here: https://github.com/gehtsoft-usa/BallisticCalculator1
+
+The online version of C# API documentation is located here: https://gehtsoft-usa.github.io/BallisticCalculator/web-content.html
+
+Go documentation can be obtained using godoc tool.
+
+The current status of the project is ALPHA version.
+
+#### RISK NOTICE
+
+The library performs very limited simulation of a complex physical process and so it performs a lot of approximations. Therefore, the calculation results MUST NOT be considered as completely and reliably reflecting actual behavior or characteristics of projectiles. While these results may be used for educational purpose, they must NOT be considered as reliable for the areas where incorrect calculation may cause making a wrong decision, financial harm, or can put a human life at risk.
+
+THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
diff --git a/py_ballisticcalc_exts/__init__.py b/py_ballisticcalc_exts/__init__.py
new file mode 100644
index 0000000..6b4cf8a
--- /dev/null
+++ b/py_ballisticcalc_exts/__init__.py
@@ -0,0 +1 @@
+from .py_ballisticcalc_exts import *
diff --git a/py_ballisticcalc_exts/py.typed b/py_ballisticcalc_exts/py.typed
new file mode 100644
index 0000000..e69de29
diff --git a/py_ballisticcalc_exts/py_ballisticcalc_exts/__init__.py b/py_ballisticcalc_exts/py_ballisticcalc_exts/__init__.py
new file mode 100644
index 0000000..fc39078
--- /dev/null
+++ b/py_ballisticcalc_exts/py_ballisticcalc_exts/__init__.py
@@ -0,0 +1,8 @@
+__author__ = "o-murphy"
+__copyright__ = ("",)
+
+__credits__ = ["o-murphy"]
+__version__ = "1.1.0"
+
+from .drag_model import *
+from .trajectory_calc import *
diff --git a/py_ballisticcalc/drag_model.pyi b/py_ballisticcalc_exts/py_ballisticcalc_exts/drag_model.pyi
similarity index 100%
rename from py_ballisticcalc/drag_model.pyi
rename to py_ballisticcalc_exts/py_ballisticcalc_exts/drag_model.pyi
diff --git a/py_ballisticcalc/drag_model.pyx b/py_ballisticcalc_exts/py_ballisticcalc_exts/drag_model.pyx
similarity index 92%
rename from py_ballisticcalc/drag_model.pyx
rename to py_ballisticcalc_exts/py_ballisticcalc_exts/drag_model.pyx
index 60a6e98..fa2f8dc 100644
--- a/py_ballisticcalc/drag_model.pyx
+++ b/py_ballisticcalc_exts/py_ballisticcalc_exts/drag_model.pyx
@@ -2,11 +2,11 @@ import typing
from libc.math cimport pow
-from .settings import Settings as Set
-from .unit import Weight, Distance
-from .drag_tables import DragTablesSet
+from py_ballisticcalc.settings import Settings as Set
+from py_ballisticcalc.unit import Weight, Distance
+from py_ballisticcalc.drag_tables import DragTablesSet
-__all__ = ('DragModel', )
+__all__ = ('DragModel', 'make_data_points')
cdef class DragDataPoint:
cdef readonly double CD # BC or CD
diff --git a/py_ballisticcalc/trajectory_calc.pyx b/py_ballisticcalc_exts/py_ballisticcalc_exts/trajectory_calc.pyx
similarity index 98%
rename from py_ballisticcalc/trajectory_calc.pyx
rename to py_ballisticcalc_exts/py_ballisticcalc_exts/trajectory_calc.pyx
index b0391a3..ff36b69 100644
--- a/py_ballisticcalc/trajectory_calc.pyx
+++ b/py_ballisticcalc_exts/py_ballisticcalc_exts/trajectory_calc.pyx
@@ -1,11 +1,11 @@
from libc.math cimport sqrt, fabs, pow, sin, cos, log10, floor, atan
cimport cython
-from .conditions import *
-from .munition import *
-from .settings import Settings
-from .trajectory_data import TrajectoryData, TrajFlag
-from .unit import *
+from py_ballisticcalc.conditions import Atmo, Shot
+from py_ballisticcalc.munition import Ammo, Weapon
+from py_ballisticcalc.settings import Settings
+from py_ballisticcalc.trajectory_data import TrajectoryData
+from py_ballisticcalc.unit import *
__all__ = ('TrajectoryCalc',)
diff --git a/py_ballisticcalc_exts/pyproject.toml b/py_ballisticcalc_exts/pyproject.toml
new file mode 100644
index 0000000..1d60f6d
--- /dev/null
+++ b/py_ballisticcalc_exts/pyproject.toml
@@ -0,0 +1,51 @@
+[build-system]
+requires = ["setuptools", "wheel", 'cython']
+build-backend = "setuptools.build_meta"
+
+
+[project]
+name = "py_ballisticcalc.exts"
+
+authors = [
+ { name="o-murphy", email="thehelixpg@gmail.com" },
+]
+description = "LGPL library for small arms ballistic calculations (Python 3)"
+readme = "README.md"
+requires-python = ">=3.9"
+keywords = ["py_ballisticcalc", "ballistics", "Cython", "ballistic calculator", "python", "python3"]
+license = {file = "LICENSE"}
+classifiers = [
+ "Intended Audience :: Developers",
+ "Natural Language :: English",
+ "Programming Language :: Python",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3 :: Only",
+ "Programming Language :: Python :: 3.9",
+ "Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
+ "Programming Language :: Python :: 3.12",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python :: Implementation :: CPython",
+]
+dependencies = []
+dynamic = ["version"]
+
+[project.urls]
+"Homepage" = "https://github.com/o-murphy/py_ballisticcalc"
+"Bug Reports" = "https://github.com/o-murphy/py_ballisticcalc/issues"
+#"Funding" = "https://donate.pypi.org"
+#"Say Thanks!" = ""
+"Source" = "https://github.com/o-murphy/py_ballisticcalc"
+
+[tool.setuptools]
+py-modules = ["py_ballisticcalc_exts"]
+
+
+[tool.setuptools.packages.find]
+where = ["."]
+include = ["py_ballisticcalc_exts*"] # alternatively: `exclude = ["additional*"]`
+
+
+[tool.setuptools.dynamic]
+version = {attr = "py_ballisticcalc_exts.__version__"}
diff --git a/py_ballisticcalc_exts/setup.py b/py_ballisticcalc_exts/setup.py
new file mode 100644
index 0000000..4ccd92e
--- /dev/null
+++ b/py_ballisticcalc_exts/setup.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+"""setup.py script for py_ballisticcalc library"""
+
+import os
+from pathlib import Path
+
+from setuptools import setup, Extension
+
+try:
+ from Cython.Build import cythonize
+
+ # USE_CYTHON = True
+except ImportError:
+ # USE_CYTHON = False
+ cythonize = False
+
+
+def iter_extensions(path) -> list:
+ """
+ iterate extensions in project directory
+ :rtype: list
+ :return: list of extensions paths
+ """
+ founded_extensions = []
+ extensions_dir = Path(path).parent
+ for ext_path in Path.iterdir(extensions_dir):
+ if ext_path.suffix == '.pyx':
+ ext_name = f"{'.'.join(extensions_dir.parts)}.{ext_path.stem}"
+ ext = Extension(ext_name, [ext_path.as_posix()])
+ founded_extensions.append(ext)
+ return founded_extensions
+
+
+def no_cythonize(exts, **_ignore):
+ """grep extensions sources without cythonization"""
+ for extension in exts:
+ sources = []
+ for src_file in extension.sources:
+ path, ext = os.path.splitext(src_file)
+
+ if ext in (".pyx", ".py"):
+ if extension.language == "c++":
+ ext = ".cpp"
+ else:
+ ext = ".c"
+ src_file = path + ext
+ sources.append(src_file)
+ extension.sources[:] = sources
+ return exts
+
+
+extensions_paths = [
+ 'py_ballisticcalc_exts/*.pyx',
+]
+
+extensions = []
+for path_ in extensions_paths:
+ extensions += iter_extensions(path_)
+
+if cythonize:
+ compiler_directives = {"language_level": 3, "embedsignature": True}
+ extensions = cythonize(extensions, compiler_directives=compiler_directives)
+else:
+ extensions = no_cythonize(extensions)
+
+setup(
+ ext_modules=extensions,
+)
diff --git a/pyproject.toml b/pyproject.toml
index 191439d..49e84b5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,5 +1,5 @@
[build-system]
-requires = ["setuptools", "wheel", "cython"]
+requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
@@ -24,7 +24,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
-# "Programming Language :: Python :: 3.12",
+ "Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
"Programming Language :: Python :: Implementation :: CPython",
]
@@ -39,9 +39,13 @@ dynamic = ["version"]
"Source" = "https://github.com/o-murphy/py_ballisticcalc"
+[tool.setuptools]
+py-modules = ["py_ballisticcalc"]
+
[tool.setuptools.packages.find]
where = ["."]
include = ["py_ballisticcalc*"] # alternatively: `exclude = ["additional*"]`
+exclude = ["py_ballisticcalc_exts*"]
[tool.setuptools.dynamic]
@@ -49,6 +53,6 @@ version = {attr = "py_ballisticcalc.__version__"}
[project.optional-dependencies]
-dev = ['Cython', 'setuptools']
+exts = ['py_ballisticcalc.exts']
lint = ['pylint', 'flake8']
-plot = ['matplotlib', 'pandas']
+graph = ['matplotlib', 'pandas']
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 8b13789..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/setup.py b/setup.py
index 59d2ea4..9b80486 100644
--- a/setup.py
+++ b/setup.py
@@ -2,68 +2,6 @@
"""setup.py script for py_ballisticcalc library"""
-import os
-from pathlib import Path
+from setuptools import setup
-from setuptools import setup, Extension
-
-try:
- from Cython.Build import cythonize
-
- # USE_CYTHON = True
-except ImportError:
- # USE_CYTHON = False
- cythonize = False
-
-
-def iter_extensions(path) -> list:
- """
- iterate extensions in project directory
- :rtype: list
- :return: list of extensions paths
- """
- founded_extensions = []
- extensions_dir = Path(path).parent
- for ext_path in Path.iterdir(extensions_dir):
- if ext_path.suffix == '.pyx':
- ext_name = f"{'.'.join(extensions_dir.parts)}.{ext_path.stem}"
- ext = Extension(ext_name, [ext_path.as_posix()])
- founded_extensions.append(ext)
- return founded_extensions
-
-
-def no_cythonize(exts, **_ignore):
- """grep extensions sources without cythonization"""
- for extension in exts:
- sources = []
- for src_file in extension.sources:
- path, ext = os.path.splitext(src_file)
-
- if ext in (".pyx", ".py"):
- if extension.language == "c++":
- ext = ".cpp"
- else:
- ext = ".c"
- src_file = path + ext
- sources.append(src_file)
- extension.sources[:] = sources
- return exts
-
-
-extensions_paths = [
- 'py_ballisticcalc/*.pyx',
-]
-
-extensions = []
-for path_ in extensions_paths:
- extensions += iter_extensions(path_)
-
-if cythonize:
- compiler_directives = {"language_level": 3, "embedsignature": True}
- extensions = cythonize(extensions, compiler_directives=compiler_directives)
-else:
- extensions = no_cythonize(extensions)
-
-setup(
- ext_modules=extensions,
-)
+setup()
diff --git a/tests/test_binary_import.py b/tests/test_binary_import.py
new file mode 100644
index 0000000..d4ad9fb
--- /dev/null
+++ b/tests/test_binary_import.py
@@ -0,0 +1,14 @@
+import unittest
+
+
+class TestImports(unittest.TestCase):
+
+ def test_bin_import(self):
+ try:
+ import py_ballisticcalc_exts
+ except ImportError as err:
+ print(err)
+ py_ballisticcalc_exts = None
+ if py_ballisticcalc_exts:
+ from py_ballisticcalc.backend import DragModel
+ print(DragModel)
diff --git a/tests/test_danger_space.py b/tests/test_danger_space.py
index bd55d27..d0d6ebd 100644
--- a/tests/test_danger_space.py
+++ b/tests/test_danger_space.py
@@ -1,8 +1,4 @@
import unittest
-
-import pyximport
-
-pyximport.install(language_level=3)
from py_ballisticcalc import *
diff --git a/tests/test_interface.py b/tests/test_interface.py
index d362b60..7ad99e1 100644
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -1,8 +1,4 @@
import unittest
-
-import pyximport
-
-pyximport.install(language_level=3)
from py_ballisticcalc import *
diff --git a/tests/test_mbc.py b/tests/test_mbc.py
index b8d88d1..d67b60b 100644
--- a/tests/test_mbc.py
+++ b/tests/test_mbc.py
@@ -1,8 +1,4 @@
import unittest
-
-import pyximport
-
-pyximport.install(language_level=3)
from py_ballisticcalc import *
diff --git a/tests/test_performance.py b/tests/test_performance.py
index d96d2aa..70902e7 100644
--- a/tests/test_performance.py
+++ b/tests/test_performance.py
@@ -1,8 +1,4 @@
import unittest
-
-import pyximport
-
-pyximport.install(language_level=3)
from py_ballisticcalc import *
diff --git a/tests/test_trajectory.py b/tests/test_trajectory.py
index 17f0ea8..c0215ea 100644
--- a/tests/test_trajectory.py
+++ b/tests/test_trajectory.py
@@ -2,10 +2,6 @@
import unittest
from math import fabs
-
-import pyximport
-
-pyximport.install(language_level=3)
from py_ballisticcalc import *
diff --git a/tests/test_units.py b/tests/test_units.py
index 45bbe85..ad0c904 100644
--- a/tests/test_units.py
+++ b/tests/test_units.py
@@ -1,9 +1,4 @@
import unittest
-
-import pyximport
-
-pyximport.install(language_level=3)
-
from py_ballisticcalc.unit import *