Skip to content

Commit

Permalink
Merge pull request #14 from jaqx0r/pyproject
Browse files Browse the repository at this point in the history
build: Single-source the release version from git.
  • Loading branch information
jaqx0r committed Aug 23, 2023
2 parents 02b5029 + cc5aff6 commit cbf1b31
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 32 deletions.
37 changes: 30 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
name: CI
on: [push, pull_request]
on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
# none-all, which doesn't exist, but
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow
# implies that the token still gets created, and
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
# shows what the default permissions are, which are more than `none`.
# Elsewhere we learn that any permission not mentioned here gets turned to
# `none`. So setting a single permission to none causes all to be `none`.
actions: none

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
fetch-depth: 0 # get all tags
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: install dependencies
run: sudo apt-get install -y libmad0-dev
- name: build
run: |
python config_unix.py
python setup.py build
python -m compileall -f .
sudo apt-get install -y libmad0-dev
python -m pip install --upgrade pip
python -m pip install --upgrade pytest
- name: install
run: |
python -m pip install .
- name: test
run: |
pytest
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]

[project]
name = "pymad"
dynamic = ["version"]
description = "A wrapper for the MAD (mpeg audio decoder) library."
authors = [
{name="Jamie Wilkinson",email="jaq@spacepants.org"},
]
readme = "README.md"
license = {text = "GPL-2.0"}

[project.urls]
Homepage = "https://spacepants.org/src/pymad"
Repository = "https://github.com/jaqx0r/pymad"

[tool.setuptools_scm]
tag_regex = '^version/(?P<version>[^\+]+)(?P<suffix>.*)?$'
44 changes: 19 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,28 @@

"""Setup script for the MAD module distribution."""

import os
import re
import sys

from distutils.core import setup
from distutils.extension import Extension
from setuptools_scm import get_version

VERSION_MAJOR = 0
VERSION_MINOR = 10
PYMAD_VERSION = str(VERSION_MAJOR) + '.' + str(VERSION_MINOR)

scm_kwargs = {
# Must be in sync with pyproject.toml.
"tag_regex": r"^version/(?P<version>[^\+]+)(?P<suffix>.*)?$",
}

DEFINES = [('VERSION_MAJOR', VERSION_MAJOR),
('VERSION_MINOR', VERSION_MINOR),
('VERSION', '"%s"' % PYMAD_VERSION)]
version = get_version(**scm_kwargs)

MADMODULE = Extension(
name='mad',
sources=['src/madmodule.c', 'src/pymadfile.c', 'src/xing.c'],
define_macros=DEFINES,
libraries=['mad'])

setup( # Distribution metadata
name='pymad',
version=PYMAD_VERSION,
description='A wrapper for the MAD libraries.',
author='Jamie Wilkinson',
author_email='jaq@spacepants.org',
url='http://spacepants.org/src/pymad/',
license='GPL',
ext_modules=[MADMODULE])
name="mad",
sources=["src/madmodule.c", "src/pymadfile.c", "src/xing.c"],
define_macros=[
("VERSION", '"{}"'.format(version)),
],
libraries=["mad"],
)

setup(
version=version,
ext_modules=[MADMODULE],
use_scm_version=scm_kwargs,
)
16 changes: 16 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import sys

sys.path.insert(0, os.path.abspath(".."))
print(sys.path)

from importlib.metadata import version


def test_import():
import mad

print("Package version:", mad.__version__)
print("Expected metadata version:", version("pymad"))

assert mad.__version__ == version("pymad")

0 comments on commit cbf1b31

Please sign in to comment.