Skip to content

Commit

Permalink
remove redundant version export
Browse files Browse the repository at this point in the history
  • Loading branch information
arahlin committed Sep 26, 2024
1 parent cf65122 commit 49c17b9
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 39 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
VERSION filter=exportversion
.gitattributes export-ignore
.gitignore export-ignore
.git_archival.txt export-subst
5 changes: 1 addition & 4 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ jobs:
fetch-tags: true

- name: Build sdist
run: |
cmake/config_export.sh
git archive HEAD .git_archival.txt VERSION | tar -xv
pipx run build --sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
Expand Down
22 changes: 8 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Minimum versions:

- GCC >= 5.0 or clang >= 3.4
- Boost >= 1.48
- cmake >= 3.5
- cmake >= 3.12
- Python >= 2.7 (although pre-Python-3 support is best-effort)

On Ubuntu/Debian, you can install the non-Python dependencies, including the optional ones, by doing:
Expand Down Expand Up @@ -105,9 +105,9 @@ Installation

For various reasons it may be useful to install the software after building, instead of continuing to use it out of the build directory. Several CMake variables control how the software is installed:

* ``WITH_BZIP2``, which defaults to ``TRUE``, is used to control whether the core library is built with support for bzip2 compression of G3 files. Use ``-DWITH_BZIP2=FALSE`` when calling ``cmake`` to disable.
* ``CMAKE_INSTALL_PREFIX``, which defaults to ``/usr/local`` is used as the root directory for installing all non-python components (header files, cmake export scripts, etc.). This variable is frequently useful when installing into a python virtual environment.
* ``CMAKE_BUILD_PARALLEL_LEVEL`` is an environment variable (*not* a cmake option) used to control how many parallel processes are used to compile the shared libraries. This option provides the same behavior as running ``make`` with the ``-j`` flag (e.g. ``make -j4``).
* ``WITH_BZIP2``, which defaults to ``TRUE``, is used to control whether the core library is built with support for bzip2 compression of G3 files. Use ``-DWITH_BZIP2=FALSE`` when calling ``cmake`` to disable.
* ``CMAKE_INSTALL_PREFIX``, which defaults to ``/usr/local`` is used as the root directory for installing all non-python components (header files, cmake export scripts, etc.). This variable is frequently useful when installing into a python virtual environment.
* ``CMAKE_BUILD_PARALLEL_LEVEL`` is an environment variable (*not* a cmake option) used to control how many parallel processes are used to compile the shared libraries. This option provides the same behavior as running ``make`` with the ``-j`` flag (e.g. ``make -j4``).

Installation with Pip
---------------------
Expand Down Expand Up @@ -159,17 +159,11 @@ Release Version Tracking
Use git tags to keep track of release versions. Tags should be of the form "v0.1.2" for release with major version 0, minor version 1 and patch version 2.
If such a tag is defined, cmake will populate the following outputs:

* A `cmake/Spt3gConfigVersion.cmake` file that contains the version number to be checked when including the Spt3g libraries in another cmake project
* A `spt3g/version.py` file containing VCS parameters for access in python and stored in PipelineInfo frames
* Add a `SPT3G_VERSION` compiler definition for accessing the version string in C++ code
* A ``cmake/Spt3gConfigVersion.cmake`` file that contains the version number to be checked when including the Spt3g libraries in another cmake project
* A ``spt3g/version.py`` file containing VCS parameters for access in python and stored in PipelineInfo frames
* Add a ``SPT3G_VERSION`` compiler definition for accessing the version string in C++ code

When exporting the source tree to a standalone archive, run the following command in the source directory to ensure that the source version is correctly exported:

.. code-block:: shell
cmake/config_export.sh
Then archive the source tree using `git archive` as usual.
Use the ``git archive`` command or the Python ``build`` package to export the source tree to a standalone archive.

Version Control Hygiene
-----------------------
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

6 changes: 3 additions & 3 deletions cmake/Spt3gVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ file(REMOVE ${CMAKE_BINARY_DIR}/cmake/Spt3gConfigVersion.cmake)

if (NOT SPT3G_VERSION)
# Check VERSION file (sensible in exported source tree)
file(READ ${CMAKE_SOURCE_DIR}/VERSION GIT_VERSION)
string(REGEX REPLACE "\\$Version: (.*)\\$" "\\1" GIT_VERSION "${GIT_VERSION}")
string(REPLACE "$Version$" "" GIT_VERSION "${GIT_VERSION}")
file(READ ${CMAKE_SOURCE_DIR}/.git_archival.txt GIT_VERSION)
string(REGEX REPLACE ".*describe-name: (.*)$" "\\1" GIT_VERSION "${GIT_VERSION}")
string(REGEX REPLACE "\\$Format:.*" "" GIT_VERSION "${GIT_VERSION}")
string(STRIP "${GIT_VERSION}" GIT_VERSION)

if (NOT GIT_VERSION)
Expand Down
4 changes: 0 additions & 4 deletions cmake/config_export.sh

This file was deleted.

16 changes: 4 additions & 12 deletions cmake/getvers.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#!/bin/sh

# Usage: getvers.sh <tree to get version info from> <build directory>
# Usage: getvers.sh <tree to get version info from> <output version file>

set -e
cd $1

# PEP440-compliant version number for pyproject.toml
if [ -e .git ]; then
# replaces first - with .dev and second - with +, so e.g. 0.3-154-gd36baf4a becomes 0.3.dev154+gd36baf4a
fullversion_pep440=$(echo $(git describe --always --tags 2>/dev/null) | sed 's/-/.dev/' | sed 's/-/+/')
fi
fullversion_pep440="${fullversion_pep440:-0.1.0+unknown}" # fallback for SVN or error above


# version.py version info
rm -f $2
exec 1>"$2"
Expand Down Expand Up @@ -129,18 +121,18 @@ elif [ -e .git ]; then
echo localdiffs=False
fi
echo versionname=\"$(git tag -l --points-at HEAD 2>/dev/null)\"
echo fullversion=\"$fullversion_pep440\"
echo fullversion=\"$(git describe --always --tags 2>/dev/null)\"
else
echo upstream_url=\"UNKNOWN VCS\"
echo upstream_branch=\"UNKNOWN VCS\"
echo revision=\"UNKNOWN VCS\"
echo gitrevision=\"UNKNOWN\"
echo versionname=\"UNKNOWN\"
if [ "$(cat VERSION)" = '$Version$' ]; then
if (grep -q '$Format:' .git_archival.txt); then
echo localdiffs=True
echo fullversion=\"UNKNOWN\"
else
echo localdiffs=False
echo fullversion=\"$(cat VERSION | sed -E 's/\$Version: (.*)\$/\1/g')\"
echo fullversion=\"$(grep describe .git_archival.txt | sed -E 's/describe-name: (.*)/\1/g')\"
fi
fi
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install
from setuptools.command.install_scripts import install_scripts
from setuptools.command.sdist import sdist


# A CMakeExtension does not need a source list
Expand Down Expand Up @@ -123,6 +124,20 @@ def run(self):
subprocess.run(["make", "install"], cwd=build_dir, check=True)


class ArchiveDist(sdist):
def run(self):

if Path(".git").exists():
ar = subprocess.run(
["git", "archive", "HEAD", ".git_archival.txt"],
check=True,
capture_output=True,
)
subprocess.run(["tar", "-x"], input=ar.stdout, check=True)

super().run()


# gather libraries
clibs = []
pdirs = {"spt3g": "cmake/package"}
Expand All @@ -142,6 +157,7 @@ def run(self):
"build_ext": CMakeBuildExt,
"install_scripts": CMakeInstallScripts,
"install": CMakeInstall,
"sdist": ArchiveDist,
},
packages=list(pdirs),
package_dir=pdirs,
Expand Down

0 comments on commit 49c17b9

Please sign in to comment.