Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dial it up to 11 #246

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
61c2219
Move CI to tox
pllim Oct 12, 2023
8e50cce
Move setup.cfg to pyproject.toml
pllim Oct 12, 2023
dce4f77
Move benchmark module out of unit tests area.
pllim Oct 12, 2023
56e903f
Use OpenAstronomy to build wheels
pllim Oct 12, 2023
9cf7b4e
Use absolute imports
pllim Oct 12, 2023
6d0e85d
Add installation instruction
pllim Oct 12, 2023
2510222
Fix typo in pyproject.toml
pllim Oct 12, 2023
6c80627
Fix image not showing in RTD
pllim Oct 12, 2023
97333d8
Pass move env into tox
pllim Oct 12, 2023
2223fcd
Fix manifest and tox.ini
pllim Oct 12, 2023
b16d6bf
GitHub README cannot follow symlink
pllim Oct 12, 2023
e2aeeeb
Fix version import
pllim Oct 12, 2023
84649d8
Remove one more relative import
pllim Oct 12, 2023
2916e6c
Also include header in manifest
pllim Oct 12, 2023
a66de94
tox to install verbosely
pllim Oct 12, 2023
4b226a7
Put back changedir in tox
pllim Oct 12, 2023
77812c1
It is getting late
pllim Oct 12, 2023
6e0a070
Skip some tests if math_util is missing
pllim Oct 12, 2023
a1a626a
Match package_data closer to old definition
pllim Oct 12, 2023
da978c8
Cannot be empty string on LHS
pllim Oct 12, 2023
4819e45
Fix setuptols discovery
pllim Oct 12, 2023
33c63c2
What if we do not changedir in tox
pllim Oct 12, 2023
23f460b
Do not include docs in test paths.
pllim Oct 12, 2023
a10b4c1
xfail tests that fail with numpy alt func
pllim Oct 12, 2023
5670251
I should let this go but I cannot
pllim Oct 12, 2023
3ba1fa2
Build a wheel even without label
pllim Oct 12, 2023
3e84384
Localize test_almost_identical_polygons_multi_union failure handling
pllim Oct 12, 2023
7dde5df
label did not trigger wheels
pllim Oct 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 100
extend-ignore = E201,E202,E203,E221,E231,E741
105 changes: 68 additions & 37 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
name: Publish to PyPI
name: Wheel building

on:
release:
types: [released]
pull_request:
# We also want this workflow triggered if the 'Build all wheels'
# label is added or present when PR is updated
types:
- opened
- synchronize
- labeled
push:
branches:
- master
tags:
- '*'

permissions:
contents: read

jobs:
validate:
name: Validate metadata
runs-on: ubuntu-latest
steps:
- uses: spacetelescope/action-publish_to_pypi/validate@master

build_wheels:
name: Build wheels on ${{ matrix.os }}
needs: [validate]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15]

steps:
- uses: spacetelescope/action-publish_to_pypi/build-wheel@master

build_sdist:
name: Build source distribution
needs: [validate]
runs-on: ubuntu-latest
steps:
- uses: spacetelescope/action-publish_to_pypi/build-sdist@master

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: spacetelescope/action-publish_to_pypi/publish@master
with:
test: ${{ secrets.PYPI_TEST }}
user: ${{ secrets.PYPI_USERNAME_STSCI_MAINTAINER }}
password: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }} # WARNING: Do not hardcode secret values here! If you want to use a different user or password, you can override this secret by creating one with the same name in your Github repository settings.
test_password: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER_TEST }}
test_wheel_building:
# This ensures that a couple of targets work fine in pull requests and pushes
permissions:
contents: none
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@v1
if: (github.event_name == 'push' || github.event_name == 'pull_request')
with:
upload_to_pypi: false
upload_to_anaconda: false
test_extras: test
test_command: pytest -p no:warnings --pyargs spherical_geometry.tests -v
targets: |
- cp39-manylinux_x86_64


build_and_publish:
# This job builds the wheels and publishes them to PyPI for all
# tags. For PRs with the "Build wheels" label, wheels are built,
# but are not uploaded to PyPI.

permissions:
contents: none

uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@v1

if: (github.repository == 'spacetelescope/spherical_geometry' && (github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'Build wheels')))
with:
# We upload to PyPI for all tag pushes
upload_to_pypi: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' }}

# BUG: https://github.com/spacetelescope/spherical_geometry/issues/244
# BUG: https://github.com/spacetelescope/spherical_geometry/issues/245
test_extras: test
test_command: pytest -p no:warnings --pyargs spherical_geometry.tests -v
targets: |
# Linux wheels
- cp3*-manylinux_x86_64
- cp3*-musllinux_x86_64
# FIXME: https://github.com/spacetelescope/spherical_geometry/issues/247
#- cp3*-manylinux_aarch64

# MacOS X wheels - we deliberately do not build universal2 wheels.
# Note that the arm64 wheels are not actually tested so we
# rely on local manual testing of these to make sure they are ok.
- cp3*macosx_x86_64
- cp3*macosx_arm64

# Windows wheels
- cp3*win32
- cp3*win_amd64
secrets:
pypi_token: ${{ secrets.PYPI_TOKEN }}
117 changes: 32 additions & 85 deletions .github/workflows/spherical_geometry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,88 +19,35 @@ permissions:
contents: read

jobs:
build:
name: Python Testing ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install numpy
python -m pip install -e .[test]
- name: Test with pytest
run: |
pip freeze
pytest

devdeps:
name: Python Testing with dev versions of dependencies
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --pre --upgrade --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
python -m pip install --pre --upgrade --extra-index-url https://pypi.anaconda.org/astropy/simple astropy
python -m pip install -e .[test]
- name: Test with pytest
run: |
pip freeze
pytest

code_coverage:
name: Code Coverage Report
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[test]
- name: Test with pytest and code coverage
run: |
pip freeze
pytest --cov-report=xml --cov=. --cov-config=setup.cfg
- name: Upload coverage to codecoverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml

bandit:
name: Bandit
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install bandit
- name: Security checks with bandit
run: |
bandit spherical_geometry -r -x spherical_geometry/tests
tests:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
submodules: false
coverage: ''
envs: |
# Make sure that packaging will work
- name: pep517 build
linux: twine

- name: Security audit
linux: bandit

- name: PEP 8
linux: codestyle

- name: Python 3.9 (OSX)
macos: py39-test
posargs: -v

- name: Python 3.10 (Windows)
windows: py310-test
posargs: -v

- name: Python 3.11 with coverage
linux: py311-test-cov
posargs: -v
coverage: codecov

- name: Python 3.12 with dev version of dependencies
linux: py312-test-devdeps
posargs: -v
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
__pycache__

# Other generated files
*/version.py
*/_version.py
*/cython_version.py
htmlcov
MANIFEST
.coverage
coverage.xml
docs/api/
MANIFEST

Expand Down
7 changes: 4 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
include README.rst
include CHANGES.rst

include setup.cfg
include pyproject.toml

recursive-include *.c
exclude benchmarks.py
exclude inside.png

recursive-include src *.c *.h
recursive-include docs *
recursive-include licenses *

Expand Down
13 changes: 12 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ User documentation
The ``spherical_geometry`` library is a Python package for handling spherical
polygons that represent arbitrary regions of the sky.

Installation
------------

On PyPI::

pip install spherical-geometry

On conda::

conda install -c conda-forge spherical-geometry

Requirements
------------

Expand Down Expand Up @@ -111,7 +122,7 @@ In the following image, the inside point (marked with the red dot)
declares that the area of the polygon is the green region, and not the
white region.

.. image:: docs/spherical_geometry/inside.png
.. image:: inside.png

The inside point of the the polygon can be obtained from the
``~polygon.SphericalPolygon.inside`` property.
Expand Down
18 changes: 8 additions & 10 deletions spherical_geometry/tests/benchmarks.py → benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
import sys
import time

import numpy as np
from sphere import *
from test_util import *
from test_shared import resolve_imagename
from spherical_geometry.polygon import SphericalPolygon
from spherical_geometry.tests.helpers import ROOT_DIR, get_point_set, resolve_imagename


def point_in_poly_lots():
image_name = resolve_imagename(ROOT_DIR,'1904-66_TAN.fits')
image_name = resolve_imagename(ROOT_DIR, '1904-66_TAN.fits')

poly1 = SphericalPolygon.from_wcs(image_name, 64, crval=[0, 87])
poly2 = SphericalPolygon.from_wcs(image_name, 64, crval=[20, 89])
poly3 = SphericalPolygon.from_wcs(image_name, 64, crval=[180, 89])
Expand All @@ -18,15 +16,16 @@ def point_in_poly_lots():

count = 0
for point in points:
if poly1.contains_point(point) or poly2.contains_point(point) or \
poly3.contains_point(point):
if (poly1.contains_point(point) or poly2.contains_point(point) or
poly3.contains_point(point)):
count += 1

assert count == 5
assert poly1.intersects_poly(poly2)
assert not poly1.intersects_poly(poly3)
assert not poly2.intersects_poly(poly3)


if __name__ == '__main__':
for benchmark in [point_in_poly_lots]:
t = time.time()
Expand All @@ -36,4 +35,3 @@ def point_in_poly_lots():
benchmark()
sys.stdout.write(' %.03fs\n' % (time.time() - t))
sys.stdout.flush()

22 changes: 22 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
try:
from pytest_astropy_header.display import (PYTEST_HEADER_MODULES,
TESTED_VERSIONS)
except ImportError:
PYTEST_HEADER_MODULES = {}
TESTED_VERSIONS = {}

try:
from spherical_geometry import __version__ as version
except ImportError:
version = 'unknown'

# Uncomment and customize the following lines to add/remove entries
# from the list of packages for which version numbers are displayed
# when running the tests.
PYTEST_HEADER_MODULES['astropy'] = 'astropy'
PYTEST_HEADER_MODULES.pop('Scipy', None)
PYTEST_HEADER_MODULES.pop('Matplotlib', None)
PYTEST_HEADER_MODULES.pop('Pandas', None)
PYTEST_HEADER_MODULES.pop('h5py', None)

TESTED_VERSIONS['spherical-geometry'] = version
21 changes: 0 additions & 21 deletions coveragerc

This file was deleted.

Loading
Loading