Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# link: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
name: publish distributions 📦 to PyPI and TestPyPI

on:
push:
branches:
- main
tags:
- v*

jobs:
build-n-publish:
if: github.repository_owner == 'insarlab'

name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install pypa/build
run: >-
python -m
pip install
build
--user

- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.

- name: Publish developed version 📦 to Test PyPI
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: false
verbose: true

- name: Publish released version 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
15 changes: 12 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
# Author: Zhang Yunjun, Jan 2021
# Copyright 2020, by the California Institute of Technology.
# Note by Yunjun, Oct 2022: "pip install pysolid" does not work,
# because a Fortran compiler is required but not available via pip


# always prefer setuptools over distutils
import setuptools
from numpy.distutils.core import setup, Extension

# Grab from version.py file: version
# Note by Yunjun, Oct 2022: do not use sys.path.append() to import pysolid because
# pysolid.__init__ requires the pysolid.solid sub-module, which is not compiled yet.
with open("src/pysolid/version.py", "r") as f:
lines = f.readlines()
line = [line for line in lines if line.strip().startswith("Tag(")][0].strip()
version = line.replace("'",'"').split('"')[1]

# specify fortran extensions to build with numpy.f2py
solid_ext = Extension(name='pysolid.solid', sources=['src/pysolid/solid.for'])
# Grab from README file: long_description
with open("README.md", "r") as f:
long_description = f.read()

setup(
name='pysolid',
version=version,
description="A Python wrapper for solid to compute solid Earth tides",
url="https://github.com/insarlab/PySolid",
download_url=("https://github.com/insarlab/PySolid/archive/v{}.tar.gz".format(version)),
long_description=long_description,
long_description_content_type="text/markdown",
author="Zhang Yunjun, Dennis Milbert",
author_email="yunjunzgeo@gmail.com",
license="GPL-3.0-or-later",
Expand All @@ -46,7 +53,9 @@
package_dir={"": "src"}, # tell distutils packages are under src

# build fortran deps with numpy.f2py
ext_modules=[solid_ext],
ext_modules=[
Extension(name='pysolid.solid', sources=['src/pysolid/solid.for']),
],

# dependencies
python_requires=">=3.6",
Expand Down
2 changes: 1 addition & 1 deletion src/pysolid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# get version info
from pysolid.version import release_version as __version__
from pysolid.version import version as __version__

# top-level functions
from pysolid.grid import (
Expand Down
42 changes: 41 additions & 1 deletion src/pysolid/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@


import collections
import os
import subprocess


###########################################################################
# release history
Tag = collections.namedtuple('Tag', 'version date')
release_history = (
Expand All @@ -17,5 +21,41 @@
)

# latest release
release_version = 'v{}'.format(release_history[0].version)
release_version = release_history[0].version
release_date = release_history[0].date

# get development version info
def get_version_info():
"""Grab version and date of the latest commit from a git repository"""
# go to the repository directory
dir_orig = os.getcwd()
os.chdir(os.path.dirname(os.path.dirname(__file__)))

try:
# grab from git cmd
cmd = "git describe --tags"
version = subprocess.check_output(cmd.split(), stderr=subprocess.DEVNULL)
version = version.decode('utf-8').strip()[1:]

# if there are new commits after the latest release
if '-' in version:
version, num_commit = version.split('-')[:2]
version += f'-{num_commit}'

cmd = "git log -1 --date=short --format=%cd"
date = subprocess.check_output(cmd.split(), stderr=subprocess.DEVNULL)
date = date.decode('utf-8').strip()

except:
# use the latest release version/date
version = release_version
date = release_date

# go back to the original directory
os.chdir(dir_orig)
return version, date


###########################################################################
version, version_date = get_version_info()