Skip to content

Commit

Permalink
Merge 05320d0 into 78196cf
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Jan 8, 2020
2 parents 78196cf + 05320d0 commit c25f1fa
Show file tree
Hide file tree
Showing 19 changed files with 1,812 additions and 3,549 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ spiceypy/utils/__pycache__/
.eggs/
*.whl
.pytest_cache/
*.sqlite3
4 changes: 3 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ sphinx:
# fail_on_warning: true # < enable later...

# Optionally build your docs in additional formats such as PDF and ePub
formats: all
formats:
- epub
- pdf

# use a conda environment
conda:
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ language: python
sudo: false
matrix:
include:
- os: linux
python: 2.7
- os: linux
python: 3.6
- os: linux
python: 3.7
- os: linux
python: 3.8
- os: osx
language: generic
env: PYVERSION='2.7.13'
- os: osx
language: generic
env: PYVERSION='3.6.0'
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ include LICENSE
include requirements.txt
include README.rst

# cspice files
include spiceypy/utils/*

# Docs
include docs/conf.py
include docs/*.rst
Expand Down
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
SpiceyPy
========

SpiceyPy is a Python wrapper for the NAIF C SPICE Toolkit (N66),
compatible with Python 2 and 3, written using ctypes.
SpiceyPy is a Python wrapper for the NAIF C SPICE Toolkit (N66), written using ctypes.

+------------------------------------------------+---------------------+--------------------------+-------------------+------------+
| Continuous Integration | Code Coverage | Docs | Chat | Citation |
Expand Down Expand Up @@ -100,7 +99,9 @@ as newer versions are released.

- OS: OS X, Linux, Windows
- CPU: 64bit only!
- Python 2.7, 3.5, 3.6, 3.7
- Python 3.6, 3.7, 3.8

* Support for Python 2.7 ended with version 2.3.2 January 2020 *

Acknowledgements
----------------
Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ environment:
secure: ojP0ftEgmrZcijN49vQEPz39rkcPyOxtjwNp5hUYkdKxQq47DwkiaWOnVA11nog637VUmRnHb07uXwvrhK4bbg==

matrix:
- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x"
ARCH: "64"
PLAT_NAME: "win-amd64"
PY_TAG: "cp27"

- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.x"
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"sphinx.ext.viewcode",
]

Expand All @@ -57,9 +58,9 @@
# built documents.
#
# The short X.Y version.
version = "2.3.2"
version = "3.0.0"
# The full version, including alpha/beta/rc tags.
release = "2.3.2"
release = "3.0.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
4 changes: 2 additions & 2 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: SPICEYPY_DOCS

channels:
- defaults
- conda-forge

dependencies:
- python=3
- numpy
- six
- pip:
- sphinx_autodoc_typehints
11 changes: 3 additions & 8 deletions docs/exampleone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,22 @@ meta kernels in spice, please consult the `Kernel Required Reading <https://naif
Help on function spkpos in module spiceypy.spiceypy:
spkpos(targ, et, ref, abcorr, obs)
spkpos(targ: str, et: Union[float, numpy.ndarray], ref: str, abcorr: str, obs: str) -> Union[Tuple[numpy.ndarray, float], Tuple[numpy.ndarray, numpy.ndarray]]
Return the position of a target body relative to an observing
body, optionally corrected for light time (planetary aberration)
and stellar aberration.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkpos_c.html
:param targ: Target body name.
:type targ: str
:param et: Observer epoch.
:type et: float or List of Floats
:param ref: Reference frame of output position vector.
:type ref: str
:param abcorr: Aberration correction flag.
:type abcorr: str
:param obs: Observing body name.
:type obs: str
:return:
Position of target,
One way light time between observer and target.
:rtype: tuple
Expand Down Expand Up @@ -174,7 +169,7 @@ positions list to a 2D numpy array for easier indexing in the plot.

.. code:: python
positions = np.asarray(positions).T # positions is a list, make it an ndarray for easier indexing
positions = positions.T # positions is shaped (4000, 3), let's transpose to (3, 4000) for easier indexing
fig = plt.figure(figsize=(9, 9))
ax = fig.add_subplot(111, projection='3d')
ax.plot(positions[0], positions[1], positions[2])
Expand Down
10 changes: 10 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ Common Issues

SSL Alert Handshake Issue
-------------------------

.. attention::

As of 2020, users are not likely to experience this issue with python
version 3.7 and above, and for newer 3.6.X releases. Users running
older operating systems are encouraged to update to newer versions
of python if they are attempting to install version 3.0.0 or above.
See other sections of this document for more information.


In early 2017, JPL updated to a TLS1.2 certificate and enforced https connections causing installation
issues for users, in particular for macOS users, with OpenSSL versions older
than 1.0.1g. This is because older versions of OpenSSL still distributed in some
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
sphinx_autodoc_typehints
172 changes: 172 additions & 0 deletions getspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import io
import platform
import os
import shutil
import subprocess
import ssl
import sys
Expand All @@ -80,6 +81,16 @@

import six.moves.urllib as urllib

host_OS = platform.system()
# Get platform is Unix-like OS or not
is_unix = host_OS in ("Linux", "Darwin", "FreeBSD")
# Get current working directory
root_dir = os.path.dirname(os.path.realpath(__file__))
# Make the directory path for cspice
cspice_dir = os.path.join(root_dir, "cspice")
# Make the directory path for cspice/lib
lib_dir = os.path.join(cspice_dir, "lib")


class GetCSPICE(object):
"""
Expand Down Expand Up @@ -272,3 +283,164 @@ def _unpack(self):
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE)
proc.stdin.write(self._local.read())
self._local.close()


class InstallCSpice(object):
@staticmethod
def get_cspice():
if InstallCSpice.check_for_spice():
print("Host OS: {0}".format(host_OS))
if is_unix:
InstallCSpice.unix_method()
elif host_OS == "Windows":
InstallCSpice.windows_method()
else:
sys.exit("Unsupported OS: {0}".format(host_OS))

@staticmethod
def check_for_spice():
print("Checking the path", cspice_dir)
if not os.path.exists(cspice_dir):

message = "Unable to find CSPICE at {0}. Attempting to Download CSPICE For you:".format(
cspice_dir
)
print(message)
# Download cspice using getspice.py
GetCSPICE(version="N0066")
if not os.path.exists(cspice_dir):
message = "Unable to find CSPICE at {0}. Exiting".format(cspice_dir)
sys.exit(message)
return True
return False

@staticmethod
def unpack_cspice():
if is_unix:
cspice_lib = os.path.join(
lib_dir, ("cspice.lib" if host_OS == "Windows" else "cspice.a")
)
csupport_lib = os.path.join(
lib_dir, ("csupport.lib" if host_OS == "Windows" else "csupport.a")
)

if os.path.exists(cspice_lib) and os.path.exists(csupport_lib):
cwd = os.getcwd()
try:
os.chdir(lib_dir)
if host_OS == "Windows":
raise BaseException(
"Windows is not supported in this build method"
)
elif is_unix:
for lib in ["ar -x cspice.a", "ar -x csupport.a"]:
unpack_lib_process = subprocess.Popen(lib, shell=True)
process_status = os.waitpid(unpack_lib_process.pid, 0)[1]
if process_status != 0:
raise BaseException("{0}".format(process_status))
else:
raise BaseException("Unsupported OS: {0}".format(host_OS))
except BaseException as error:
status = error.args
sys.exit(
"Error: cspice object file extraction failed with exit status: {0}".format(
status
)
)
finally:
os.chdir(cwd)
else:
error_message = (
"Error, cannot find CSPICE "
"static libraries at {0}".format(lib_dir)
)
sys.exit(error_message)

@staticmethod
def build_library():
# Get the current working directory
cwd = os.getcwd()

if is_unix:
try:
os.chdir(lib_dir)
# find a way to make this work via Extension and setuptools, not using popen.
build_lib = subprocess.Popen(
"gcc -shared -fPIC -lm *.o -o spice.so", shell=True
)
status = os.waitpid(build_lib.pid, 0)[1]
if status != 0:
raise BaseException("{0}".format(status))
success = os.path.exists(os.path.join(os.getcwd(), "spice.so"))
if not success:
raise BaseException("Did not find spice.so, build went badly.")
except BaseException as errorInst:
status = errorInst.args
sys.exit(
"Error: compilation of shared spice.so build exit status: {0}".format(
status
)
)

elif host_OS == "Windows":
try:
destination = os.path.join(cspice_dir, "src", "cspice")
def_file = os.path.join(root_dir, "appveyor", "cspice.def")
make_bat = os.path.join(root_dir, "appveyor", "makeDynamicSpice.bat")
shutil.copy(def_file, destination)
shutil.copy(make_bat, destination)
# run the script
os.chdir(destination)
windows_build = subprocess.Popen("makeDynamicSpice.bat", shell=True)
status = windows_build.wait()
if status != 0:
raise BaseException("{0}".format(status))
except BaseException as error:
sys.exit("Build failed with: {0}".format(error.args))
# Change back to the stored 'current working directory
os.chdir(cwd)

@staticmethod
def move_to_root_directory():
sharedlib = "spice.so" if is_unix else "cspice.dll"
destination = os.path.join(root_dir, "spiceypy", "utils", sharedlib)
if not os.path.isfile(destination):
if is_unix:
target = os.path.join(cspice_dir, "lib", sharedlib)
else:
target = os.path.join(cspice_dir, "src", "cspice", sharedlib)
print("Attempting to move: {0} to: {1}".format(target, destination))
try:
os.rename(target, destination)
except BaseException as e:
sys.exit("{0} file not found, what happend?: {1}".format(sharedlib, e))

@staticmethod
def cleanup():
# Remove CSPICE folder
try:
shutil.rmtree(os.path.join(os.getcwd(), "cspice"))
except OSError as e:
print("Error Cleaning up cspice folder")
raise e

@staticmethod
def unix_method():
# Unpack cspice.a and csupport.a
InstallCSpice.unpack_cspice()
# Build the shared Library
InstallCSpice.build_library()
# Move to correct location (root of the distribution)
InstallCSpice.move_to_root_directory()

@staticmethod
def windows_method():
if os.path.exists(os.path.join(cspice_dir, "lib", "cspice.dll")):
print("Found pre-made cspice.dll, not building")
elif os.path.exists(os.path.join(root_dir, "spiceypy", "utils", "cspice.dll")):
print("Found pre-made cspice.dll in spiceypy, not building")
else:
# Build the DLL
InstallCSpice.build_library()
# Move to correct location (root of the distribution)
InstallCSpice.move_to_root_directory()
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
numpy>=1.17.0; python_version >= "3.5"
numpy<=1.16.4; python_version < "3.5"
numpy>=1.17.0
coverage<5.0 # fix for coveralls 1.9.2 and coverage <5 issue https://github.com/coveralls-clients/coveralls-python/issues/203
six>=1.9.0
pytest>=2.9.0
coveralls>=1.1
setuptools>=38.0.0
Expand Down
Loading

0 comments on commit c25f1fa

Please sign in to comment.