From 4f4c4591fd274c9fe197324f3955cc17a68f92c7 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 07:23:56 -0500 Subject: [PATCH 01/10] return to generating different formats on the fly during wheel building --- pyproject.toml | 2 +- setup.py | 49 +++------ src/PyPop/CommandLineInterface.py | 3 +- src/PyPop/__init__.py | 36 ------- src/PyPop/citation/CITATION.apalike | 1 - src/PyPop/citation/CITATION.bibtex | 7 -- src/PyPop/citation/CITATION.cff | 88 ---------------- src/PyPop/citation/CITATION.codemeta | 149 --------------------------- src/PyPop/citation/CITATION.endnote | 26 ----- src/PyPop/citation/CITATION.ris | 28 ----- src/PyPop/citation/README.md | 1 - 11 files changed, 17 insertions(+), 373 deletions(-) delete mode 100644 src/PyPop/citation/CITATION.apalike delete mode 100644 src/PyPop/citation/CITATION.bibtex delete mode 100644 src/PyPop/citation/CITATION.cff delete mode 100644 src/PyPop/citation/CITATION.codemeta delete mode 100644 src/PyPop/citation/CITATION.endnote delete mode 100644 src/PyPop/citation/CITATION.ris delete mode 100644 src/PyPop/citation/README.md diff --git a/pyproject.toml b/pyproject.toml index 641070d72..982350209 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,7 @@ write_to = "src/PyPop/_version.py" # matches the path where version will be wri build-backend = "setuptools.build_meta:__legacy__" requires = ["setuptools>=42", "setuptools_scm[toml]>=6.2", - # "cffconvert @ git+https://github.com/alexlancaster/cffconvert.git@combine_features#egg=cffconvert", + "cffconvert @ git+https://github.com/alexlancaster/cffconvert.git@combine_features#egg=cffconvert", "importlib-metadata; python_version <= '3.8'" ] diff --git a/setup.py b/setup.py index 56c06d771..1bd801d69 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ # UPDATES, ENHANCEMENTS, OR MODIFICATIONS. import sys, os -import shutil from glob import glob from setuptools import setup from setuptools.extension import Extension @@ -221,7 +220,7 @@ def path_to_src(source_path_list): citation_data_file_paths = [] # citation files are in a subdirectory of PyPop, but not a separate module -from src.PyPop import citation_output_formats +from src.PyPop.citation import citation_output_formats, convert_citation_formats citation_files = [os.path.join("citation", 'CITATION.' + suffix) for suffix in citation_output_formats] citation_data_file_paths.extend(citation_files) @@ -229,42 +228,21 @@ def path_to_src(source_path_list): class CustomBuildPy(_build_py): def run(self): - from cffconvert import Citation - # do standard build process super().run() - # source citation path (single-source of truth) - citation_path = "CITATION.cff" - - # then copy CITATION.cff to temp build directory - # use setuptools' temp build directory - build_lib = self.get_finalized_command('build').build_lib - - # target directory for the CITATION file within the build directory - target_dir = os.path.join(build_lib, "PyPop", "citation") + # if not running from a CIBUILDWHEEL environment variable + # we need to create the citations + if os.environ.get('CIBUILDWHEEL') != '1': + + # source citation path (single-source of truth) + citation_path = "CITATION.cff" - # create the citation directory if it doesn’t exist - os.makedirs(target_dir, exist_ok=True) - shutil.copy(citation_path, target_dir) + # then copy CITATION.cff to temp build directory + # use setuptools' temp build directory + build_lib = self.get_finalized_command('build').build_lib - # load the CITATION.cff content - cff = Citation(cffstr=open(citation_path).read()) - - # remove 'cff' from generated list - since we don't generate that - citation_output_formats.remove('cff') - - for fmt in citation_output_formats: - # use getattr to get the method based on the format string - convert_method = getattr(cff, f"as_{fmt}", None) - if callable(convert_method): - converted_content = convert_method() - else: - print(f"Conversion format '{fmt}' not supported.") - - # save the converted output (e.g., as CITATION.json) - with open(os.path.join(target_dir, "CITATION." + fmt), "w") as f: - f.write(converted_content) + convert_citation_formats(build_lib, citation_path) # read the contents of your README file from pathlib import Path @@ -318,7 +296,8 @@ def run(self): }, ext_modules=extensions, cmdclass={'clean': CleanCommand, - # disable the custom build - # 'build_py': CustomBuildPy, + # enable the custom build + 'build_py': CustomBuildPy, }, + ) diff --git a/src/PyPop/CommandLineInterface.py b/src/PyPop/CommandLineInterface.py index 2d410cff9..4bd6f3c43 100644 --- a/src/PyPop/CommandLineInterface.py +++ b/src/PyPop/CommandLineInterface.py @@ -36,7 +36,8 @@ import os, sys from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter, FileType, Action from pathlib import Path -from PyPop import platform_info, citation_output_formats # global info and citation formats +from PyPop import platform_info # global info +from PyPop.citation import citation_output_formats # and citation formats """Command-line interface for PyPop scripts """ diff --git a/src/PyPop/__init__.py b/src/PyPop/__init__.py index 355a0140e..49313f83d 100644 --- a/src/PyPop/__init__.py +++ b/src/PyPop/__init__.py @@ -1,38 +1,3 @@ -#!/usr/bin/env python - -# This file is part of PyPop - -# Copyright (C) 2017. -# All Rights Reserved. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, -# INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING -# LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -# DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY -# OF SUCH DAMAGE. - -# REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING -# DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS -# IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, -# UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - import platform __pkgname__ = 'pypop-genomics' @@ -56,7 +21,6 @@ platform_info="[Python {python_version} | {system} | {arch}]".format(python_version=platform.python_version(), system=platform.platform(), arch=platform.machine()) -citation_output_formats = ['apalike', 'bibtex', 'endnote', 'ris', 'codemeta', 'cff'] import locale import logging diff --git a/src/PyPop/citation/CITATION.apalike b/src/PyPop/citation/CITATION.apalike deleted file mode 100644 index fed3aa640..000000000 --- a/src/PyPop/citation/CITATION.apalike +++ /dev/null @@ -1 +0,0 @@ -Lancaster A.K., Nelson M.P., Single R., Solberg O., Tsai Y., Meyer D., Webster G., Mariani M.P., Sochat V., Kornel K., Spaaks J.H., Mack S.J., and Thomson G. PyPop: Python for Population Genomics (version v1.1.1). DOI: 10.5281/zenodo.13742984 URL: http://pypop.org/ diff --git a/src/PyPop/citation/CITATION.bibtex b/src/PyPop/citation/CITATION.bibtex deleted file mode 100644 index ee78b779a..000000000 --- a/src/PyPop/citation/CITATION.bibtex +++ /dev/null @@ -1,7 +0,0 @@ -@misc{YourReferenceHere, -author = {Lancaster, Alexander K. and Nelson, Mark P. and Single, Richard and Solberg, Owen and Tsai, Yingsu and Meyer, Diogo and Webster, Gordon and Mariani, Michael P. and Sochat, Vanessa and Kornel, Karl and Spaaks, Jurriaan H. and Mack, Steven J. and Thomson, Glenys}, -doi = {10.5281/zenodo.13742984}, -title = {PyPop: Python for Population Genomics}, -url = {http://pypop.org/}, -note = {If you use this software, please cite both the software itself, as well as the article Lancaster AK et al. (2024) PyPop: A mature open-source software pipeline for population genomics. Front. Immunol. 15:1378512. doi: 10.3389/fimmu.2024.1378512} -} diff --git a/src/PyPop/citation/CITATION.cff b/src/PyPop/citation/CITATION.cff deleted file mode 100644 index d60f9ee2b..000000000 --- a/src/PyPop/citation/CITATION.cff +++ /dev/null @@ -1,88 +0,0 @@ -cff-version: 1.2.0 -message: >- - If you use this software, please cite both the software itself, as well as the - article Lancaster AK et al. (2024) PyPop: A mature - open-source software pipeline for population genomics. Front. - Immunol. 15:1378512. doi: 10.3389/fimmu.2024.1378512 -abstract: >- - PyPop for Population Genomics (PyPop) is a Python program for processing - genotype and allele data and running population genetic analyses, including - conformity to Hardy-Weinberg expectations; tests for balancing or directional - selection; estimates of haplotype frequencies and measures and tests of - significance for linkage disequilibrium (LD). Output of analyses are - stored in XML format for maximum downstream flexibility. PyPop also has an - internal facility for additionally aggregating the output XML and generating - output tab-separated (TSV) files, as well as default plain text files for each - population. Although it can be run on any kind of genotype data, it has - additional support for analyzing population genotype with allelic nomenclature - from the human leukocyte antigen (HLA) region. -authors: - - family-names: Lancaster - given-names: Alexander K. - orcid: https://orcid.org/0000-0002-0002-9263 - affiliation: Amber Biology LLC and Ronin Institute - - family-names: Nelson - given-names: Mark P. - affiliation: University of California, Berkeley - - family-names: Single - given-names: Richard - orcid: https://orcid.org/0000-0001-6054-6505 - affiliation: University of Vermont - - family-names: Solberg - given-names: Owen - orcid: https://orcid.org/0000-0003-3060-9709 - - family-names: Tsai - given-names: Yingsu - affiliation: University of California, Berkeley - orcid: https://orcid.org/0009-0006-0162-6066 - - family-names: Meyer - given-names: Diogo - orcid: https://orcid.org/0000-0002-7155-5674 - affiliation: University of São Paulo - - family-names: Webster - given-names: Gordon - affiliation: Amber Biology LLC - orcid: https://orcid.org/0009-0009-2862-0467 - - family-names: Mariani - given-names: Michael P. - orcid: https://orcid.org/0000-0001-5852-0517 - affiliation: Mariani Systems LLC and University of Vermont - - family-names: Sochat - given-names: Vanessa - orcid: https://orcid.org/0000-0002-4387-3819 - affiliation: Lawrence Livermore National Laboratory - - family-names: Kornel - given-names: Karl - orcid: https://orcid.org/0000-0001-5847-5330 - affiliation: Stanford Research Computing Center - - family-names: Spaaks - given-names: Jurriaan H. - orcid: https://orcid.org/0000-0002-7064-4069 - affiliation: Netherlands eScience Center - - family-names: Mack - given-names: Steven J. - orcid: https://orcid.org/0000-0001-9820-9547 - affiliation: University of California, San Francisco - - family-names: Thomson - given-names: Glenys - orcid: https://orcid.org/0000-0001-5235-4159 - affiliation: University of California, Berkeley -title: 'PyPop: Python for Population Genomics' -url: http://pypop.org/ -repository-artifact: https://pypi.org/project/pypop-genomics/ -repository-code: https://github.com/alexlancaster/pypop -type: software -license: GPL-2.0-or-later -version: v1.1.1 -doi: 10.5281/zenodo.13742984 -keywords: - - population genetics - - population genomics - - bioinformatics - - computational biology - - evolutionary biology - - Human leukocyte antigen - - Major histocompatibility complex - - HLA - - MHC diff --git a/src/PyPop/citation/CITATION.codemeta b/src/PyPop/citation/CITATION.codemeta deleted file mode 100644 index 165ee514b..000000000 --- a/src/PyPop/citation/CITATION.codemeta +++ /dev/null @@ -1,149 +0,0 @@ -{ - "@context": "https://doi.org/10.5063/schema/codemeta-2.0", - "@type": "SoftwareSourceCode", - "author": [ - { - "@id": "https://orcid.org/0000-0002-0002-9263", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "Amber Biology LLC and Ronin Institute" - }, - "familyName": "Lancaster", - "givenName": "Alexander K." - }, - { - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "University of California, Berkeley" - }, - "familyName": "Nelson", - "givenName": "Mark P." - }, - { - "@id": "https://orcid.org/0000-0001-6054-6505", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "University of Vermont" - }, - "familyName": "Single", - "givenName": "Richard" - }, - { - "@id": "https://orcid.org/0000-0003-3060-9709", - "@type": "Person", - "familyName": "Solberg", - "givenName": "Owen" - }, - { - "@id": "https://orcid.org/0009-0006-0162-6066", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "University of California, Berkeley" - }, - "familyName": "Tsai", - "givenName": "Yingsu" - }, - { - "@id": "https://orcid.org/0000-0002-7155-5674", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "University of São Paulo" - }, - "familyName": "Meyer", - "givenName": "Diogo" - }, - { - "@id": "https://orcid.org/0009-0009-2862-0467", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "Amber Biology LLC" - }, - "familyName": "Webster", - "givenName": "Gordon" - }, - { - "@id": "https://orcid.org/0000-0001-5852-0517", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "Mariani Systems LLC and University of Vermont" - }, - "familyName": "Mariani", - "givenName": "Michael P." - }, - { - "@id": "https://orcid.org/0000-0002-4387-3819", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "Lawrence Livermore National Laboratory" - }, - "familyName": "Sochat", - "givenName": "Vanessa" - }, - { - "@id": "https://orcid.org/0000-0001-5847-5330", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "Stanford Research Computing Center" - }, - "familyName": "Kornel", - "givenName": "Karl" - }, - { - "@id": "https://orcid.org/0000-0002-7064-4069", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "Netherlands eScience Center" - }, - "familyName": "Spaaks", - "givenName": "Jurriaan H." - }, - { - "@id": "https://orcid.org/0000-0001-9820-9547", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "University of California, San Francisco" - }, - "familyName": "Mack", - "givenName": "Steven J." - }, - { - "@id": "https://orcid.org/0000-0001-5235-4159", - "@type": "Person", - "affiliation": { - "@type": "Organization", - "name": "University of California, Berkeley" - }, - "familyName": "Thomson", - "givenName": "Glenys" - } - ], - "codeRepository": "https://github.com/alexlancaster/pypop", - "description": "PyPop for Population Genomics (PyPop) is a Python program for processing genotype and allele data and running population genetic analyses, including conformity to Hardy-Weinberg expectations; tests for balancing or directional selection; estimates of haplotype frequencies and measures and tests of significance for linkage disequilibrium (LD). Output of analyses are stored in XML format for maximum downstream flexibility. PyPop also has an internal facility for additionally aggregating the output XML and generating output tab-separated (TSV) files, as well as default plain text files for each population. Although it can be run on any kind of genotype data, it has additional support for analyzing population genotype with allelic nomenclature from the human leukocyte antigen (HLA) region.", - "identifier": "https://doi.org/10.5281/zenodo.13742984", - "keywords": [ - "population genetics", - "population genomics", - "bioinformatics", - "computational biology", - "evolutionary biology", - "Human leukocyte antigen", - "Major histocompatibility complex", - "HLA", - "MHC" - ], - "license": "https://spdx.org/licenses/GPL-2.0-or-later", - "name": "PyPop: Python for Population Genomics", - "url": "http://pypop.org/", - "version": "v1.1.1" -} diff --git a/src/PyPop/citation/CITATION.endnote b/src/PyPop/citation/CITATION.endnote deleted file mode 100644 index 2a2e87d47..000000000 --- a/src/PyPop/citation/CITATION.endnote +++ /dev/null @@ -1,26 +0,0 @@ -%0 Generic -%A Lancaster, Alexander K. -%A Nelson, Mark P. -%A Single, Richard -%A Solberg, Owen -%A Tsai, Yingsu -%A Meyer, Diogo -%A Webster, Gordon -%A Mariani, Michael P. -%A Sochat, Vanessa -%A Kornel, Karl -%A Spaaks, Jurriaan H. -%A Mack, Steven J. -%A Thomson, Glenys -%K population genetics -%K population genomics -%K bioinformatics -%K computational biology -%K evolutionary biology -%K Human leukocyte antigen -%K Major histocompatibility complex -%K HLA -%K MHC -%R 10.5281/zenodo.13742984 -%T PyPop: Python for Population Genomics -%U http://pypop.org/ diff --git a/src/PyPop/citation/CITATION.ris b/src/PyPop/citation/CITATION.ris deleted file mode 100644 index dc035f76e..000000000 --- a/src/PyPop/citation/CITATION.ris +++ /dev/null @@ -1,28 +0,0 @@ -TY - GEN -AB - PyPop for Population Genomics (PyPop) is a Python program for processing genotype and allele data and running population genetic analyses, including conformity to Hardy-Weinberg expectations; tests for balancing or directional selection; estimates of haplotype frequencies and measures and tests of significance for linkage disequilibrium (LD). Output of analyses are stored in XML format for maximum downstream flexibility. PyPop also has an internal facility for additionally aggregating the output XML and generating output tab-separated (TSV) files, as well as default plain text files for each population. Although it can be run on any kind of genotype data, it has additional support for analyzing population genotype with allelic nomenclature from the human leukocyte antigen (HLA) region. -AU - Lancaster, Alexander K. -AU - Nelson, Mark P. -AU - Single, Richard -AU - Solberg, Owen -AU - Tsai, Yingsu -AU - Meyer, Diogo -AU - Webster, Gordon -AU - Mariani, Michael P. -AU - Sochat, Vanessa -AU - Kornel, Karl -AU - Spaaks, Jurriaan H. -AU - Mack, Steven J. -AU - Thomson, Glenys -DO - 10.5281/zenodo.13742984 -KW - population genetics -KW - population genomics -KW - bioinformatics -KW - computational biology -KW - evolutionary biology -KW - Human leukocyte antigen -KW - Major histocompatibility complex -KW - HLA -KW - MHC -TI - PyPop: Python for Population Genomics -UR - http://pypop.org/ -ER diff --git a/src/PyPop/citation/README.md b/src/PyPop/citation/README.md deleted file mode 100644 index ed36905ac..000000000 --- a/src/PyPop/citation/README.md +++ /dev/null @@ -1 +0,0 @@ -# DO NOT MODIFY THESE FILES - they are automatically generated from the top-level [`CITATION.cff`](../../../CITATION.cff) by a GitHub Action. From 072cb355f1387f2e8db35dfd37ae2cd46235eba7 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 13:45:28 -0500 Subject: [PATCH 02/10] missing file --- src/PyPop/citation.py | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/PyPop/citation.py diff --git a/src/PyPop/citation.py b/src/PyPop/citation.py new file mode 100644 index 000000000..ff6a35605 --- /dev/null +++ b/src/PyPop/citation.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +# This file is part of PyPop + +# Copyright (C) 2017. +# All Rights Reserved. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, +# INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +# LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +# DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY +# OF SUCH DAMAGE. + +# REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING +# DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS +# IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, +# UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +import os +import shutil + +citation_output_formats = ['apalike', 'bibtex', 'endnote', 'ris', 'codemeta', 'cff'] + +def convert_citation_formats(build_lib, citation_path): + + from cffconvert import Citation + + # target directory for the CITATION file within the build directory + target_dir = os.path.join(build_lib, "PyPop", "citation") + + # create the citation directory if it doesn’t exist + os.makedirs(target_dir, exist_ok=True) + shutil.copy(citation_path, target_dir) + + # load the CITATION.cff content + cff = Citation(cffstr=open(citation_path).read()) + + # remove 'cff' from generated list - since we don't generate that + citation_output_formats.remove('cff') + + for fmt in citation_output_formats: + # use getattr to get the method based on the format string + convert_method = getattr(cff, f"as_{fmt}", None) + if callable(convert_method): + converted_content = convert_method() + else: + print(f"Conversion format '{fmt}' not supported.") + + # save the converted output (e.g., as CITATION.json) + with open(os.path.join(target_dir, "CITATION." + fmt), "w") as f: + f.write(converted_content) + +if __name__ == "__main__": + + convert_citation_formats("src", "CITATION.cff") + From ff2486d3c0017f09397cb77c7e2e841ae80ef36d Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 18:15:24 -0500 Subject: [PATCH 03/10] Remove cffconvert from build-system requires in pyproject.toml --- .github/workflows/build_wheels.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 3d82d2e6b..a7d30cae4 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -182,7 +182,12 @@ jobs: if: runner.os == 'Linux' uses: docker/setup-qemu-action@v3 with: - platforms: all + platforms: all + - name: Remove cffconvert from build-system requires in pyproject.toml + run: | + sed -i '/^\[build-system\]/,/^\[/ { + /"cffconvert\( @[^"]*\)\?"/d + }' pyproject.toml - name: Build and test wheels uses: pypa/cibuildwheel@v2.21.3 env: From 6084a3ab5da96f2e1f09cebb9d6355dfafe9a93b Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 18:45:00 -0500 Subject: [PATCH 04/10] use a Python script more cross-platform --- .github/workflows/build_wheels.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index a7d30cae4..55b33acdb 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -183,11 +183,21 @@ jobs: uses: docker/setup-qemu-action@v3 with: platforms: all - - name: Remove cffconvert from build-system requires in pyproject.toml + - name: Install toml and remove cffconvert from pyproject.toml run: | - sed -i '/^\[build-system\]/,/^\[/ { - /"cffconvert\( @[^"]*\)\?"/d - }' pyproject.toml + python -m pip install toml + python -c " + import toml + with open('pyproject.toml', 'r') as f: + config = toml.load(f) + if 'build-system' in config and 'requires' in config['build-system']: + config['build-system']['requires'] = [ + dep for dep in config['build-system']['requires'] if 'cffconvert' not in dep.lower() + ] + with open('pyproject.toml', 'w') as f: + toml.dump(config, f) + " + cat pyproject.toml - name: Build and test wheels uses: pypa/cibuildwheel@v2.21.3 env: From 9787069d853c6b490ec26cd3718137eadc5fde37 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 19:21:50 -0500 Subject: [PATCH 05/10] generate citiation formats --- .github/workflows/build_wheels.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 55b33acdb..695c58607 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -198,6 +198,10 @@ jobs: toml.dump(config, f) " cat pyproject.toml + - name: Generate citation formats + run: | + python -m pip install git+https://github.com/alexlancaster/cffconvert.git@combine_features#egg=cffconvert + python src/PyPop/citation.py - name: Build and test wheels uses: pypa/cibuildwheel@v2.21.3 env: From fe6cf41743a05e1a71f47d4c739734024c83d290 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 19:31:14 -0500 Subject: [PATCH 06/10] debugging --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 695c58607..8fca923d4 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -197,9 +197,9 @@ jobs: with open('pyproject.toml', 'w') as f: toml.dump(config, f) " - cat pyproject.toml - name: Generate citation formats run: | + python --version python -m pip install git+https://github.com/alexlancaster/cffconvert.git@combine_features#egg=cffconvert python src/PyPop/citation.py - name: Build and test wheels From 696c990ff2f1eaa02d46ea882df2c4df1b605c9e Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 19:38:04 -0500 Subject: [PATCH 07/10] install recent Python to handle cffconvert --- .github/workflows/build_wheels.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 8fca923d4..53c66c814 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -197,6 +197,8 @@ jobs: with open('pyproject.toml', 'w') as f: toml.dump(config, f) " + - name: Install most Python stable to handle cffconvert + uses: actions/setup-python@v4 - name: Generate citation formats run: | python --version From 1e51cc8f86f4016235d860bde6efcd5c0f295ec6 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 19:40:21 -0500 Subject: [PATCH 08/10] install stable 3.12 --- .github/workflows/build_wheels.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 53c66c814..90237a395 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -197,8 +197,10 @@ jobs: with open('pyproject.toml', 'w') as f: toml.dump(config, f) " - - name: Install most Python stable to handle cffconvert + - name: Install a recent stable Python to handle cffconvert uses: actions/setup-python@v4 + with: + python-version: 3.12 - name: Generate citation formats run: | python --version From 5eb555995c8bad9f258f4fa1472a48de21058189 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 20:16:26 -0500 Subject: [PATCH 09/10] remove unused workflows and actions --- .github/actions/update_citations/action.yml | 47 --------------------- .github/workflows/build_wheels.yml | 4 -- .github/workflows/run_citations.yml | 34 --------------- 3 files changed, 85 deletions(-) delete mode 100644 .github/actions/update_citations/action.yml delete mode 100644 .github/workflows/run_citations.yml diff --git a/.github/actions/update_citations/action.yml b/.github/actions/update_citations/action.yml deleted file mode 100644 index 9bce668d7..000000000 --- a/.github/actions/update_citations/action.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Update citation files -description: "Update citation files" -inputs: - CITATION_DIR: - description: 'Directory for citations' - required: true - default: 'src/PyPop/citation' - INIT_FILE: - description: 'Path to the init file' - required: true - default: 'src/PyPop/__init__.py' - -runs: - using: "composite" - steps: - - name: Extract citation formats - id: extract_formats - run: | - python -c ' - import ast - with open("${{ inputs.INIT_FILE }}") as f: - contents = f.read() - citation_output_formats = next((node.value.elts for node in ast.walk(ast.parse(contents)) if isinstance(node, ast.Assign) and node.targets[0].id == "citation_output_formats"), []) - formats = ",".join([str(elem.value) for elem in citation_output_formats]) - print(f"::set-output name=formats::{formats}") - ' - shell: bash - - - name: Copy CITATION.cff to citation directory - run: | - cp CITATION.cff ${{ inputs.CITATION_DIR }}/CITATION.cff - shell: bash - - - name: Generate citation files - run: | - formats="${{ steps.extract_formats.outputs.formats }}" - IFS=',' read -r -a formats_array <<< "$formats" - for format in "${formats_array[@]}"; do - cffconvert --infile CITATION.cff --outfile "${{ inputs.CITATION_DIR }}/CITATION.${format}" --format "$format" - done - shell: bash - - - name: Commit and push changes - uses: EndBug/add-and-commit@v9 - with: - message: "Auto-update citation files based on CITATION.cff" - add: "${{ inputs.CITATION_DIR }}/*" diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 90237a395..52f8a24d9 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -20,8 +20,6 @@ on: - '.github/workflows/buildjet_arm64.yml' - '.github/workflows/release-drafter.yml' - '.github/workflows/codeql.yml' - - '.github/workflows/run_citations.yml' - - '.github/actions/update_citations/action.yml' - '.gitattributes' push: paths-ignore: @@ -37,8 +35,6 @@ on: - '.github/workflows/buildjet_arm64.yml' - '.github/workflows/release-drafter.yml' - '.github/workflows/codeql.yml' - - '.github/workflows/run_citations.yml' - - '.github/actions/update_citations/action.yml' - '.gitattributes' release: types: diff --git a/.github/workflows/run_citations.yml b/.github/workflows/run_citations.yml deleted file mode 100644 index 0a06830f6..000000000 --- a/.github/workflows/run_citations.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Update citations upon CITATION.cff changes - -on: - push: - paths: - - CITATION.cff - - '.github/workflows/run_citations.yml' - - '.github/actions/update_citations/action.yml' - -jobs: - update-citations: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - # use customized version of cffconvert - pip install git+https://github.com/alexlancaster/cffconvert.git@combine_features#egg=cffconvert - - - name: Runs composite action - uses: ./.github/actions/update_citations - with: - CITATION_DIR: 'src/PyPop/citation' - INIT_FILE: 'src/PyPop/__init__.py' - From ecec313d401f7a47aef2b855d5f1bb80529739c5 Mon Sep 17 00:00:00 2001 From: Alex Lancaster Date: Wed, 13 Nov 2024 20:28:44 -0500 Subject: [PATCH 10/10] fallback to top-level CITATION.cff --- src/PyPop/CommandLineInterface.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PyPop/CommandLineInterface.py b/src/PyPop/CommandLineInterface.py index 4bd6f3c43..41a253a4e 100644 --- a/src/PyPop/CommandLineInterface.py +++ b/src/PyPop/CommandLineInterface.py @@ -62,16 +62,18 @@ def __call__(self, parser, namespace, values, option_string=None): from importlib_resources import files citation_file = files('PyPop').joinpath(citation_file_name) citation_text = citation_file.read_text() - except (ModuleNotFoundError, ImportError, FileNotFoundError): # fallback to looking in current directory if running from repo - pypop_dir = Path(__file__).resolve().parent - citation_file = pypop_dir / citation_file_name + except (ModuleNotFoundError, ImportError, FileNotFoundError): # fallback to looking in top-level directory if running from repo + top_level_dir = Path(__file__).resolve().parent.parent.parent + citation_file = top_level_dir / 'CITATION.cff' # only output CFF if citation_file.exists(): + print("only CITATION.cff is available") + print() citation_text = citation_file.read_text() else: print("could not locate the specified citation format.") parser.exit() - + print(citation_text) parser.exit() # exit after printing the file