Skip to content

Commit 42e73a3

Browse files
committed
test new flow
1 parent bd99a34 commit 42e73a3

5 files changed

Lines changed: 299 additions & 72 deletions

File tree

.github/workflows/publish.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build and upload to PyPI
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
jobs:
7+
build_wheels:
8+
name: Build wheels for ${{ matrix.os }}
9+
runs-on: ${{ matrix.runs-on }}
10+
strategy:
11+
matrix:
12+
include:
13+
- os: linux-intel
14+
runs-on: ubuntu-latest
15+
- os: linux-arm
16+
runs-on: ubuntu-24.04-arm
17+
- os: windows-intel
18+
runs-on: windows-latest
19+
- os: windows-arm
20+
runs-on: windows-11-arm
21+
- os: macos-intel
22+
# macos-15-intel is the last x86_64 runner
23+
runs-on: macos-15-intel
24+
- os: macos-arm
25+
# macos-14+ (including latest) are ARM64 runners
26+
runs-on: macos-latest
27+
28+
steps:
29+
- uses: actions/checkout@v5
30+
31+
- name: Build wheels
32+
uses: pypa/cibuildwheel@v3.3.0
33+
env:
34+
CIBW_PLATFORM: ${{ matrix.platform || 'auto' }}
35+
CIBW_ARCHS: ${{ matrix.archs || 'auto' }}
36+
# Can also be configured directly, using `with:`
37+
# with:
38+
# package-dir: .
39+
# output-dir: wheelhouse
40+
# config-file: "{package}/pyproject.toml"
41+
42+
- uses: actions/upload-artifact@v4
43+
with:
44+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
45+
path: ./wheelhouse/*.whl
46+
47+
build_sdist:
48+
name: Build source distribution
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v5
52+
53+
- name: Build sdist
54+
run: pipx run build --sdist
55+
56+
- uses: actions/upload-artifact@v4
57+
with:
58+
name: cibw-sdist
59+
path: dist/*.tar.gz
60+
61+
# upload_pypi:
62+
# needs: [build_wheels, build_sdist]
63+
# runs-on: ubuntu-latest
64+
# environment: pypi
65+
# permissions:
66+
# id-token: write
67+
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
68+
# steps:
69+
# - uses: actions/download-artifact@v5
70+
# with:
71+
# # unpacks all CIBW artifacts into dist/
72+
# pattern: cibw-*
73+
# path: dist
74+
# merge-multiple: true
75+
76+
# - uses: pypa/gh-action-pypi-publish@release/v1
77+
# # To test uploads to TestPyPI, uncomment the following:
78+
# with:
79+
# repository-url: https://test.pypi.org/legacy/
80+
81+
82+
github-release:
83+
needs: [build_wheels, build_sdist]
84+
name: >-
85+
Sign the distribution📦 with Sigstore
86+
and upload them to GitHub Release
87+
runs-on: ubuntu-latest
88+
89+
permissions:
90+
contents: write # IMPORTANT: mandatory for making GitHub Releases
91+
id-token: write # IMPORTANT: mandatory for sigstore
92+
93+
steps:
94+
- name: Download all the dists
95+
uses: actions/download-artifact@v6
96+
with:
97+
name: cibw-sdist
98+
path: dist/
99+
merge-multiple: true
100+
- name: Sign the dists with Sigstore🔏
101+
uses: sigstore/gh-action-sigstore-python@v3.1.0
102+
with:
103+
inputs: >-
104+
./dist/*.tar.gz
105+
./dist/*.whl
106+
- name: Create GitHub Release
107+
env:
108+
GITHUB_TOKEN: ${{ github.token }}
109+
run: >-
110+
gh release create
111+
"$GITHUB_REF_NAME"
112+
--repo "$GITHUB_REPOSITORY"
113+
--generate-notes --draft
114+
- name: Upload artifact signatures to GitHub Release
115+
env:
116+
GITHUB_TOKEN: ${{ github.token }}
117+
run: >-
118+
gh release upload
119+
"$GITHUB_REF_NAME" dist/**
120+
--repo "$GITHUB_REPOSITORY"
121+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/*
2+
*.egg-info/
3+
CGRtools/containers/_unpack.c

MANIFEST.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Include documentation and license files
2+
include README.rst
3+
include LICENSE
4+
include readthedocs.yml
5+
6+
# Include INCHI library files
7+
include INCHI/libinchi.so
8+
include INCHI/libinchi.dll
9+
include INCHI/LICENCE
10+
include INCHI/readme.txt
11+
12+
# Include Cython source files
13+
include CGRtools/containers/_unpack.pyx
14+
15+
# Include package data files
16+
include CGRtools/algorithms/calculate2d/clean2d.js
17+
18+
# Include test files
19+
recursive-include test *.sdf *.rdf *.xyz *.rxn *.mrv *.txt
20+
21+
# Include documentation
22+
recursive-include doc *.rst *.py *.ipynb
23+
24+
# Include clean2d build files
25+
recursive-include clean2d *.json *.js README
26+
27+
# Exclude build artifacts
28+
global-exclude *.pyc
29+
global-exclude *.pyo
30+
global-exclude __pycache__
31+
global-exclude *.so
32+
global-exclude *.c
33+
prune build
34+
prune dist
35+
prune CGRtools.egg-info
36+
prune __pycache__

pyproject.toml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel", "cython>=0.29,<3.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "CGRtools"
7+
version = "4.1.35"
8+
description = "Tools for processing of reactions based on Condensed Graph of Reaction (CGR) approach"
9+
readme = "README.rst"
10+
requires-python = ">=3.8"
11+
license = "LGPL-3.0-or-later"
12+
authors = [
13+
{name = "Dr. Ramil Nugmanov", email = "nougmanoff@protonmail.com"},
14+
{name = "Dr. Timur Madzhidov", email = "tmadzhidov@gmail.com"},
15+
{name = "Valentina Afonina"}
16+
]
17+
maintainers = [
18+
{name = "Dr. Timur Madzhidov", email = "tmadzhidov@gmail.com"}
19+
]
20+
keywords = ["chemistry", "chemoinformatics", "CGR", "reaction", "molecule"]
21+
classifiers = [
22+
"Environment :: Plugins",
23+
"Intended Audience :: Science/Research",
24+
"Operating System :: OS Independent",
25+
"Programming Language :: Python",
26+
"Programming Language :: Python :: 3 :: Only",
27+
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10",
31+
"Programming Language :: Python :: 3.11",
32+
"Programming Language :: Python :: 3.12",
33+
"Topic :: Scientific/Engineering",
34+
"Topic :: Scientific/Engineering :: Chemistry",
35+
"Topic :: Scientific/Engineering :: Information Analysis",
36+
"Topic :: Software Development",
37+
"Topic :: Software Development :: Libraries",
38+
"Topic :: Software Development :: Libraries :: Python Modules"
39+
]
40+
dependencies = [
41+
"CachedMethods>=0.1.4,<0.2"
42+
]
43+
44+
[project.optional-dependencies]
45+
mrv = ["lxml>=4.1"]
46+
clean2d = ["py-mini-racer>=0.4.0"]
47+
jit = ["numpy>=1.18", "numba>=0.50"]
48+
dev = [
49+
"wheel",
50+
"cython",
51+
"build",
52+
"pytest",
53+
"ipython"
54+
]
55+
56+
[project.urls]
57+
Homepage = "https://github.com/cimm-kzn/CGRtools"
58+
Documentation = "https://cgrtools.readthedocs.io"
59+
Repository = "https://github.com/cimm-kzn/CGRtools"
60+
Issues = "https://github.com/cimm-kzn/CGRtools/issues"
61+
62+
[tool.setuptools]
63+
zip-safe = false
64+
65+
[tool.setuptools.packages.find]
66+
include = ["CGRtools*"]
67+
68+
[tool.setuptools.package-data]
69+
"CGRtools.algorithms.calculate2d" = ["clean2d.js"]
70+
"CGRtools.containers" = ["_unpack.pyx"]
71+
72+
[tool.cibuildwheel]
73+
build = ["cp310-*", "cp311-*", "cp312-*", "cp313-*", "cp314-*"]
74+
skip = ["*-musllinux_*", "pp*"]
75+
build-frontend = "build"

setup.py

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -18,88 +18,80 @@
1818
# You should have received a copy of the GNU Lesser General Public License
1919
# along with this program; if not, see <https://www.gnu.org/licenses/>.
2020
#
21-
from distutils.command.sdist import sdist
22-
from distutils.command.build import build
23-
from distutils.util import get_platform
24-
from importlib.util import find_spec
21+
import sys
2522
from pathlib import Path
2623
from setuptools import setup, Extension
24+
from setuptools.command.build_ext import build_ext as _build_ext
2725

2826

29-
class _sdist(sdist):
30-
def finalize_options(self):
31-
super().finalize_options()
32-
self.distribution.data_files.append(('lib', ['INCHI/libinchi.so', 'INCHI/libinchi.dll']))
33-
34-
35-
cmd_class = {'sdist': _sdist}
36-
37-
38-
if find_spec('wheel'):
39-
from wheel.bdist_wheel import bdist_wheel
40-
41-
class _bdist_wheel(bdist_wheel):
42-
def finalize_options(self):
43-
super().finalize_options()
44-
self.root_is_pure = False
45-
platform = get_platform()
46-
if platform == 'win-amd64':
47-
self.distribution.data_files.append(('lib', ['INCHI/libinchi.dll']))
48-
elif platform == 'linux-x86_64':
49-
self.distribution.data_files.append(('lib', ['INCHI/libinchi.so']))
27+
class build_ext(_build_ext):
28+
"""Custom build_ext to handle Cython compilation."""
29+
30+
def run(self):
31+
# Import Cython here and compile just before building
32+
try:
33+
from Cython.Build import cythonize
34+
if self.distribution.ext_modules:
35+
self.distribution.ext_modules = cythonize(
36+
self.distribution.ext_modules,
37+
language_level=3,
38+
compiler_directives={'embedsignature': True}
39+
)
40+
except ImportError:
41+
# If Cython is not available during build, look for pre-generated C files
42+
print("Cython not found. Looking for pre-generated C files...", file=sys.stderr)
43+
c_file = Path('CGRtools/containers/_unpack.c')
44+
if c_file.exists() and self.distribution.ext_modules:
45+
# Replace .pyx with .c in sources
46+
for ext in self.distribution.ext_modules:
47+
ext.sources = [src.replace('.pyx', '.c') for src in ext.sources]
48+
else:
49+
print("Warning: Neither Cython nor pre-generated C files found. "
50+
"Extension modules will not be built.", file=sys.stderr)
51+
self.distribution.ext_modules = []
52+
53+
super().run()
5054

51-
cmd_class['bdist_wheel'] = _bdist_wheel
5255

56+
def get_data_files():
57+
"""Get platform-specific INCHI library files for wheel."""
58+
import platform
59+
60+
data_files = []
61+
system = platform.system()
62+
machine = platform.machine()
63+
64+
# Include INCHI libraries based on platform
65+
if system == 'Windows' and machine in ('AMD64', 'x86_64'):
66+
dll_path = Path('INCHI/libinchi.dll')
67+
if dll_path.exists():
68+
data_files.append(('lib', ['INCHI/libinchi.dll']))
69+
elif system == 'Linux' and machine in ('x86_64',):
70+
so_path = Path('INCHI/libinchi.so')
71+
if so_path.exists():
72+
data_files.append(('lib', ['INCHI/libinchi.so']))
73+
74+
return data_files
5375

54-
if find_spec('cython'):
55-
class _build(build):
56-
def finalize_options(self):
57-
super().finalize_options()
58-
from Cython.Build import cythonize
59-
self.distribution.ext_modules = cythonize(self.distribution.ext_modules, language_level=3)
6076

61-
cmd_class['build'] = _build
77+
# Extension modules
78+
ext_modules = [
79+
Extension(
80+
'CGRtools.containers._unpack',
81+
['CGRtools/containers/_unpack.pyx'],
82+
extra_compile_args=['-O3']
83+
)
84+
]
6285

86+
# For source distributions, include both library files
87+
if 'sdist' in sys.argv:
88+
data_files = [('lib', ['INCHI/libinchi.so', 'INCHI/libinchi.dll'])]
89+
else:
90+
data_files = get_data_files()
6391

6492
setup(
65-
name='CGRtools',
66-
version='4.1.35',
67-
packages=['CGRtools', 'CGRtools.algorithms', 'CGRtools.algorithms.calculate2d', 'CGRtools.algorithms.components',
68-
'CGRtools.algorithms.standardize', 'CGRtools.containers', 'CGRtools.files', 'CGRtools.files._mdl',
69-
'CGRtools.periodictable', 'CGRtools.periodictable.element', 'CGRtools.reactor', 'CGRtools.utils',
70-
'CGRtools.attributes'],
71-
url='https://github.com/cimm-kzn/CGRtools',
72-
license='LGPLv3',
73-
author='Dr. Ramil Nugmanov, Dr. Timur Madzhidov, Valentina Afonina',
74-
author_email='tmadzhidov@gmail.com',
75-
python_requires='>=3.6.1',
76-
cmdclass=cmd_class,
77-
ext_modules=[Extension('CGRtools.containers._unpack', ['CGRtools/containers/_unpack.pyx'],
78-
extra_compile_args=['-O3'])],
79-
setup_requires=['wheel', 'cython'],
80-
install_requires=['CachedMethods>=0.1.4,<0.2'],
81-
extras_require={'mrv': ['lxml>=4.1'], 'clean2d': ['py-mini-racer>=0.4.0'], 'jit': ['numpy>=1.18', 'numba>=0.50']},
82-
package_data={'CGRtools.algorithms.calculate2d': ['clean2d.js'], 'CGRtools.containers': ['_unpack.pyx']},
83-
data_files=[],
93+
ext_modules=ext_modules,
94+
data_files=data_files,
95+
cmdclass={'build_ext': build_ext},
8496
zip_safe=False,
85-
long_description=(Path(__file__).parent / 'README.rst').read_text(),
86-
classifiers=['Environment :: Plugins',
87-
'Intended Audience :: Science/Research',
88-
'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)',
89-
'Operating System :: OS Independent',
90-
'Programming Language :: Python',
91-
'Programming Language :: Python :: 3 :: Only',
92-
'Programming Language :: Python :: 3.7',
93-
'Programming Language :: Python :: 3.8',
94-
'Programming Language :: Python :: 3.9',
95-
'Programming Language :: Python :: 3.10',
96-
'Topic :: Scientific/Engineering',
97-
'Topic :: Scientific/Engineering :: Chemistry',
98-
'Topic :: Scientific/Engineering :: Information Analysis',
99-
'Topic :: Software Development',
100-
'Topic :: Software Development :: Libraries',
101-
'Topic :: Software Development :: Libraries :: Python Modules'],
102-
command_options={'build_sphinx': {'source_dir': ('setup.py', 'doc'),
103-
'build_dir': ('setup.py', 'build/doc'),
104-
'all_files': ('setup.py', True)}}
10597
)

0 commit comments

Comments
 (0)