diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 0000000..e4a560d --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,94 @@ +name: Build Wheels + +on: + workflow_dispatch: + push: + branches: + - fix-* + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] # add windows-latest later + + steps: + - uses: actions/checkout@v4 + + # Dependencies are now handled by cibuildwheel's before-all hooks + # No need to install them on the runner + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install cibuildwheel + + - name: Build wheels + run: cibuildwheel --output-dir dist + env: + # Install system dependencies and build giza from source + # giza-devel is not available in AlmaLinux 8 EPEL, so we build from source + # Install build dependencies for RHEL/CentOS/AlmaLinux + # Fallback for Debian/Ubuntu systems + # Download and build giza from source + CIBW_BEFORE_ALL_LINUX: | + (which apt || which yum || which dnf) && + ((yum install -y gcc make cairo-devel libX11-devel pkgconfig wget tar gzip) || + (apt-get update && apt-get install -y gcc make libcairo2-dev libx11-dev pkg-config wget tar gzip)) && + cd /tmp && + wget https://github.com/danieljprice/giza/archive/refs/tags/v1.4.2.tar.gz && + tar -xzf v1.4.2.tar.gz && + cd giza-1.4.2 && + export CFLAGS=-fPIC && + ./configure --prefix=/usr/local && + make && + make install && + ldconfig + CIBW_BEFORE_ALL_MACOS: "brew install giza libx11 pkg-config" + CIBW_BEFORE_ALL_WINDOWS: "echo 'Windows support not implemented yet'" + # Ensure pkg-config and runtime linker can find giza + CIBW_ENVIRONMENT_LINUX: "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH" + CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=14.0 PKG_CONFIG_PATH=$(brew --prefix)/lib/pkgconfig DYLD_FALLBACK_LIBRARY_PATH=$(brew --prefix)/lib:$DYLD_FALLBACK_LIBRARY_PATH" + # Avoid universal2 since Homebrew giza isn’t universal + CIBW_ARCHS_MACOS: "native" + # Smoke test to verify import/linking works inside each wheel env + CIBW_TEST_COMMAND: > + python -c 'import ppgplot; print("ok")' + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: python-pgplot-wheels-${{ matrix.os }} + path: dist/ + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build sdist + run: python -m build --sdist + + - name: Upload sdist + uses: actions/upload-artifact@v4 + with: + name: python-pgplot-sdist + path: dist/*.tar.gz diff --git a/.github/workflows/publish_to_pypi.yml b/.github/workflows/publish_to_pypi.yml new file mode 100644 index 0000000..cfdf9ca --- /dev/null +++ b/.github/workflows/publish_to_pypi.yml @@ -0,0 +1,146 @@ +name: Build and Publish Wheels + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: # Manual trigger for testing + inputs: + dry_run: + description: 'Dry run (skip actual PyPI upload)' + required: false + default: 'true' + type: boolean + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] # add windows-latest later + + steps: + - uses: actions/checkout@v4 + + # Dependencies are now handled by cibuildwheel's before-all hooks + # No need to install them on the runner + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install cibuildwheel + + - name: Build wheels + run: cibuildwheel --output-dir dist + env: + # Install system dependencies and build giza from source + # giza-devel is not available in AlmaLinux 8 EPEL, so we build from source + # Install build dependencies for RHEL/CentOS/AlmaLinux + # Fallback for Debian/Ubuntu systems + # Download and build giza from source + CIBW_BEFORE_ALL_LINUX: | + (which apt || which yum || which dnf) && + ((yum install -y gcc make cairo-devel libX11-devel pkgconfig wget tar gzip) || + (apt-get update && apt-get install -y gcc make libcairo2-dev libx11-dev pkg-config wget tar gzip)) && + cd /tmp && + wget https://github.com/danieljprice/giza/archive/refs/tags/v1.4.2.tar.gz && + tar -xzf v1.4.2.tar.gz && + cd giza-1.4.2 && + export CFLAGS=-fPIC && + ./configure --prefix=/usr/local && + make && + make install && + ldconfig + CIBW_BEFORE_ALL_MACOS: "brew install giza libx11 pkg-config" + CIBW_BEFORE_ALL_WINDOWS: "echo 'Windows support not implemented yet'" + # Ensure pkg-config and runtime linker can find giza + CIBW_ENVIRONMENT_LINUX: "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH" + CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=14.0 PKG_CONFIG_PATH=$(brew --prefix)/lib/pkgconfig DYLD_FALLBACK_LIBRARY_PATH=$(brew --prefix)/lib:$DYLD_FALLBACK_LIBRARY_PATH" + # Avoid universal2 since Homebrew giza isn’t universal + CIBW_ARCHS_MACOS: "native" + # Smoke test to verify import/linking works inside each wheel env + CIBW_TEST_COMMAND: > + python -c 'import ppgplot; print("ok")' + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: python-pgplot-wheels-${{ matrix.os }} + path: dist/ + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build sdist + run: python -m build --sdist + + - name: Upload sdist + uses: actions/upload-artifact@v4 + with: + name: python-pgplot-sdist + path: dist/*.tar.gz + + publish_pypi: + name: Publish to PyPI + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: dist/ + + - name: Flatten artifacts + run: | + find dist/ -name "*.whl" -exec mv {} dist/ \; + find dist/ -name "*.tar.gz" -exec mv {} dist/ \; + find dist/ -mindepth 1 -type d -exec rm -rf {} + || true + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Twine + run: pip install twine + + - name: Verify distributions + run: | + ls -la dist/ + twine check dist/* + + - name: Publish to PyPI + if: ${{ !inputs.dry_run }} + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: twine upload dist/* + + - name: Dry run - show what would be uploaded + if: ${{ inputs.dry_run }} + run: | + echo "DRY RUN: Would upload the following files to PyPI:" + ls -la dist/ + echo "Files passed twine check - ready for upload!" diff --git a/.github/workflows/test_publish.yml b/.github/workflows/test_publish.yml new file mode 100644 index 0000000..6fd9913 --- /dev/null +++ b/.github/workflows/test_publish.yml @@ -0,0 +1,120 @@ +name: Test Build and Publish + +on: + workflow_dispatch: # Manual trigger + push: + branches: + - test-pypi* # + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install cibuildwheel + + - name: Build wheels + run: cibuildwheel --output-dir dist + env: + CIBW_BEFORE_ALL_LINUX: | + (which apt || which yum || which dnf) && + ((yum install -y gcc make cairo-devel libX11-devel pkgconfig wget tar gzip) || + (apt-get update && apt-get install -y gcc make libcairo2-dev libx11-dev pkg-config wget tar gzip)) && + cd /tmp && + wget https://github.com/danieljprice/giza/archive/refs/tags/v1.4.2.tar.gz && + tar -xzf v1.4.2.tar.gz && + cd giza-1.4.2 && + export CFLAGS=-fPIC && + ./configure --prefix=/usr/local && + make && + make install && + ldconfig + CIBW_BEFORE_ALL_MACOS: "brew install giza libx11 pkg-config" + CIBW_ENVIRONMENT_LINUX: "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH" + CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=14.0 PKG_CONFIG_PATH=$(brew --prefix)/lib/pkgconfig DYLD_FALLBACK_LIBRARY_PATH=$(brew --prefix)/lib:$DYLD_FALLBACK_LIBRARY_PATH" + CIBW_ARCHS_MACOS: "native" + CIBW_TEST_COMMAND: > + python -c 'import ppgplot; print("ok")' + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: python-pgplot-wheels-${{ matrix.os }} + path: dist/ + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build sdist + run: python -m build --sdist + + - name: Upload sdist + uses: actions/upload-artifact@v4 + with: + name: python-pgplot-sdist + path: dist/*.tar.gz + + test_publish: + name: Test Publish to Test PyPI + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: dist/ + + - name: Flatten artifacts + run: | + find dist/ -name "*.whl" -exec mv {} dist/ \; + find dist/ -name "*.tar.gz" -exec mv {} dist/ \; + find dist/ -mindepth 1 -type d -exec rm -rf {} + || true + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Twine + run: pip install twine + + - name: Verify distributions + run: | + ls -la dist/ + twine check dist/* + + - name: Publish to Test PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} + run: twine upload --repository testpypi dist/* diff --git a/CHANGELOG b/CHANGELOG index ac84878..92f3efb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +version 1.6 + - Python2/3 compatibility, numpy 1.x/2.x compatibility + - github actions to build wheels and publish to (test)PyPI + - setup.py can build source dists +version 1.5* + - Fake version for experimenting w/ PyPI by n00b version 1.4 - Now ppgplot uses the "numpy" module by default, reverting to "numarray" and then "Numeric", respectively, if the preferred module is not found. diff --git a/CONTRIBUTORS b/CONTRIBUTORS index fc74981..71c5901 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,6 +1,11 @@ PPGPLOT CONTRIBUTORS: +Marjolein Verkouter continued supporting a fork of NickP's repo, making it +Py2/Py3, numpy1.x/2.x compatible, and make the extension pip-installable. +Added some functionality and incorporated patches from C. Bassa on his fork +of the original repo. + Steven Bamford adapted ppgplot in 2007 to use numpy, in favour of the depreciated numarray and Numeric modules, and included these minor changes (mostly to setup.py) in the Google Code version (1.4) in April diff --git a/INSTALL b/INSTALL index 946128b..2628509 100644 --- a/INSTALL +++ b/INSTALL @@ -6,6 +6,9 @@ possible to install ppgplot with one command (issued as user "root"): # python setup.py install +New in 2018: + Now also support python3 + If the pgplot libraries are in some other directory, or you don't feel like setting the PGPLOT_DIR, try this (again as user "root"): @@ -15,6 +18,20 @@ like setting the PGPLOT_DIR, try this (again as user "root"): Assuming "/usr/local/pgplot" is the directory where PGPLOT is installed. +New in 2018: + The "-L/.../" trick does not work if > 1 'libcpgplot.{so|dylib}' are + installed on the system. + + If linkage to an alternative, co-existing, PGPLOT library is required + (e.g. 'giza' - http://giza.sourceforge.net/): + export PGPLOT_DIR=/path/to/giza-root + + The linker will be instructed to choose the library(ies) from + /path/to/giza-root/lib/ over those found in the system paths + in such a way the user will not have to tinker with their + LD_LIBRARY_PATH variable to make ld.so find and load + he correct shared libraries. + Depending on how you compiled PGPLOT, you may need to link ppgplot with additional runtime libraries. If compilation (linking) of the extension fails due to unresolved symbols, then this is probably the @@ -34,4 +51,9 @@ Since 1.4 ppgplot is configured to prefer "numpy" over "numarray" over "Numeric", then uncomment the appropriate "raise ImportError" lines in setup.py +New in 2018: + In stead of having to edit the setup.py script it is now possible to + pass '--no-Numeric', '--no-numpy' and/or '--no-numarray' on the + commandline to prevent checking for a specific num* implementation + Have fun ! :) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4362b49 --- /dev/null +++ b/LICENSE @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/README b/README deleted file mode 100644 index 96f6b93..0000000 --- a/README +++ /dev/null @@ -1,17 +0,0 @@ -ppgplot - The Pythonic interface to PGPLOT - -ppgplot is a python module (extension) providing bindings to the -PGPLOT graphics library. PGPLOT is a scientific visualization -(graphics) library written in Fortran by T. J. Pearson. C bindings -for PGPLOT are also available. ppgplot makes the library usable by -Python programs. It uses the numeric / numarray modules (nowadays -replaced by Numpy), to efficiently represent and manipulate vectors -and matrices. - -You can download the latest ppgplot release from - - https://github.com/npat-efault/ppgplot/releases - -see file "INSTALL" for installation instructions and directory -"examples" for usage examples - diff --git a/README.md b/README.md new file mode 100644 index 0000000..2dcddd6 --- /dev/null +++ b/README.md @@ -0,0 +1,109 @@ +# ppgplot + +ppgplot - The Pythonic interface to PGPLOT, with support for both PGPLOT and Giza backends. + +`ppgplot` is a python module (extension) providing bindings to the PGPLOT +graphics library. PGPLOT is a scientific visualization (graphics) library +written in Fortran by T. J. Pearson. C bindings for PGPLOT are also available. +`ppgplot` makes the library usable by Python programs. It had support for the Numeric / +numarray modules, but nowadays (>= Feb 2025) replaced by Numpy, to efficiently represent and +manipulate vectors and matrices. + +## Installing + +### Option 1: Conda (Recommended) + +The easiest way to install `python-pgplot` is via conda-forge, which automatically handles all system dependencies: + +```bash + $> conda install -c conda-forge python-pgplot + $> python3 + >>> import ppgplot + >>> +``` + +This method automatically installs and configures: +- Giza graphics library +- Cairo graphics backend +- X11 libraries (Linux) +- All required development headers + +### Option 2: PyPI + +Since `v1.5` (Apr 2025) the package is also available on [PyPI](https://pypi.org/project/python-pgplot/): + +```bash + $> pip install python-pgplot + $> python3 + >>> import ppgplot + >>> +``` +**NOTE: Due to a package name collision, the PyPI project name is `python-pgplot`; the obvious package name was already claimed by something completely different** + +**Important:** PyPI installation requires system dependencies (see Requirements section below) to be manually installed first. + +### Option 3: From Source + +It is also possible to build the package from this `git`-repository. You may need to create a Python [`venv`](https://docs.python.org/3/library/venv.html) first. See below for detailed instructions. + +```bash + $> pip install [-e] . +``` + +**Note:** there is a [separate old-python-3.6 branch](https://github.com/haavee/ppgplot/tree/old-python-3.6) based off master, with a how-to in the commit log(s). Of course nothing works out of the box on that system - only succeeded using an (old) Anaconda3.6 base package. YMMV. + +## Requirements + +- Python 3.9+ +- numpy >= 1.21.0 +- PGPLOT or Giza libraries installed +- X11 development libraries +- pkg-config + +### Installing the dependencies + +On Linux use your favourite package manager, e.g.: +```bash +$> sudo apt-get install giza-dev libx11-dev pkg-config +``` + +Successful installation using [Homebrew](https://brew.sh) on Mac OSX with: +```bash +$> brew install libx11 giza pkgconf +``` + +## Installation + +In principle, this extension should build out-of-the-box in a Python `venv`, or, if you have it, a `conda` virtual environment (untested at the moment). +The [`pyproject.toml`](pyproject.toml) file lists all dependencies and should (...) pull them into the `venv` as required for building/deploying: + +```bash +$> cd /path/to/checkout/of/this/repo +$> pip install [-e] . +``` + +Without `-e` installs the extension in the `venv`, with the `-e` keeps the module in the current directory. + + +## Using a bespoke PGPLOT or Giza backend + +The extension configuration allows compiling + linking to a locally compiled [PGPLOT](https://sites.astro.caltech.edu/~tjp/pgplot/) or [Giza](https://github.com/danieljprice/giza) library. + + +Obviously, first install or build PGPLOT and/or Giza on your system (should you want to compare them). +Then build the extension, pointing the `PGPLOT_DIR` environment variable to the installation directory of the backend of choice: + +```bash +$> PGPLOT_DIR=/path/to/pgplot pip install [-e] . +``` + +## Notes + +FORTRAN? Srsly? Actually, for plotting large numbers of points or simple, yet precise control of the graphics, the FORTRAN based PGPLOT backend is convenient and _fast_ (a _lot_ faster than `matplotlib`, and still noticeably faster than `Giza`). However, the upside of investing those compute cycles is that the (anti-aliased!) fonts and graphics produced by the [`cairo`](https://www.cairographics.org) library (the _actual_ graphics backend used by `Giza`) are of an amazing quality. + +If `ppgplot` is linked against the `Giza` library, it can produce output in `.png` and `.pdf`, also not something to be sneezed at. + +All in all, the `Giza` backend is an amazing job done, but it is [not 100% compatible with the original PGPLOT](https://danieljprice.github.io/giza/documentation/pgplot.html), so it is not guaranteed your plots will come out identical. + +This fork of the Python-extension owes a lot of thanks to the original author, Nick Patavalis, of `ppgplot`: + https://github.com/npat-efault/ppgplot diff --git a/conda-recipe/README.md b/conda-recipe/README.md new file mode 100644 index 0000000..1126761 --- /dev/null +++ b/conda-recipe/README.md @@ -0,0 +1,53 @@ +# Conda-Forge Recipe for python-pgplot + +This directory contains the conda-forge recipe for `python-pgplot`, a Python extension providing bindings for the PGPLOT graphics library via the giza backend. + +## Files + +- `meta.yaml` - Main conda recipe specification +- `build.sh` - Unix build script (Linux/macOS) +- `bld.bat` - Windows build script (currently disabled) + +## Key Features + +- **System dependency handling**: Automatically installs and links against giza from conda-forge +- **Cross-platform**: Supports Linux and macOS (Windows not supported due to giza availability) +- **Binary extension**: Builds C extension module with proper numpy integration +- **Comprehensive testing**: Verifies both Python import and C extension loading + +## Dependencies + +### Build Requirements +- C compiler +- pkg-config +- giza >=1.3.2 (from conda-forge) + +### Runtime Requirements +- Python +- NumPy (version-pinned for ABI compatibility) +- giza >=1.3.2 + +## Submission to conda-forge + +To submit this recipe to conda-forge: + +1. Fork the [conda-forge/staged-recipes](https://github.com/conda-forge/staged-recipes) repository +2. Create a new directory `recipes/python-pgplot/` +3. Copy `meta.yaml`, `build.sh`, and `bld.bat` to that directory +4. Submit a pull request + +## Local Testing + +To test this recipe locally with conda-build: + +```bash +conda install conda-build +conda build conda-recipe/ +``` + +## Notes + +- Windows builds are disabled due to giza not being available on Windows in conda-forge +- The recipe uses the PyPI source distribution as the source +- pkg-config is used to locate giza headers and libraries +- The build includes verification that the C extension loads correctly diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat new file mode 100644 index 0000000..216e11d --- /dev/null +++ b/conda-recipe/bld.bat @@ -0,0 +1,5 @@ +@echo off +REM Windows build script - currently not supported due to giza dependency +echo "Windows builds are not currently supported for python-pgplot" +echo "This is due to the giza dependency not being available on Windows" +exit /b 1 diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh new file mode 100644 index 0000000..e2036e4 --- /dev/null +++ b/conda-recipe/build.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -euxo pipefail + +# Build and install giza from source (like CIBW_BEFORE_ALL) +cd /tmp +wget https://github.com/danieljprice/giza/archive/refs/tags/v1.4.2.tar.gz +tar -xzf v1.4.2.tar.gz +cd giza-1.4.2 + +# Configure and build giza +export CFLAGS="-fPIC" +export CXXFLAGS="-fPIC" +export LDFLAGS="-L${PREFIX}/lib" +export CPPFLAGS="-I${PREFIX}/include" + +# Update config.sub for ARM64 support +if [[ "$OSTYPE" == "darwin"* ]]; then + # Download updated config.sub that recognizes arm64-apple-darwin + wget -O build/config.sub 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' + chmod +x build/config.sub +fi + +./configure --prefix=${PREFIX} --enable-shared +make -j${CPU_COUNT} +make install + +# Ensure pkg-config can find giza +export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" + +# Return to source directory and build python-pgplot +cd ${SRC_DIR} + +# Build and install the package +${PYTHON} -m pip install . -vv --no-deps --no-build-isolation + +# Test that the extension was built correctly +${PYTHON} -c "import ppgplot; print('python-pgplot extension imported successfully')" +${PYTHON} -c "import ppgplot._ppgplot; print('C extension module loaded successfully')" diff --git a/conda-recipe/conda_build_config.yaml b/conda-recipe/conda_build_config.yaml new file mode 100644 index 0000000..2d62619 --- /dev/null +++ b/conda-recipe/conda_build_config.yaml @@ -0,0 +1,3 @@ +numpy: + - 1.26 + - 2.0 diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml new file mode 100644 index 0000000..47afabf --- /dev/null +++ b/conda-recipe/meta.yaml @@ -0,0 +1,64 @@ +{% set name = "python-pgplot" %} +{% set version = "1.6.1" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/python_pgplot-{{ version }}.tar.gz + sha256: 0ac1cd4808a5b80a6e79dea4562ac4201028818ca890abf8cb06186585858919 + +build: + number: 0 + skip: true # [win] # Windows not supported + +requirements: + build: + - {{ compiler('c') }} + - {{ compiler('fortran') }} + - {{ cdt('xorg-x11-proto-devel') }} # [linux] + - pkg-config + - make + - wget # [unix] + - tar # [unix] + - gzip # [unix] + - xorg-libx11 + host: + - python + - pip + - setuptools >=45 + - wheel + - numpy >=2.0.0rc1 + - pkgconfig + - cairo + - xorg-libx11 + run: + - python + - {{ pin_compatible('numpy') }} + - cairo + - xorg-libx11 + +test: + imports: + - ppgplot + - ppgplot._ppgplot + commands: + - python -c "import ppgplot; print('python-pgplot imported successfully')" + +about: + home: https://github.com/haavee/ppgplot + license: LGPL-2.0-only + license_file: LICENSE + license_family: GPL + summary: Python bindings for PGPLOT + description: | + Python bindings for PGPLOT graphics library. PGPLOT is a Fortran- or + C-callable, device-independent graphics package for making simple scientific + graphs. This package provides Python bindings through the giza library. + doc_url: https://github.com/haavee/ppgplot + dev_url: https://github.com/haavee/ppgplot + +extra: + recipe-maintainers: + - haavee diff --git a/examples/ex_arro.py b/examples/ex_arro.py deleted file mode 100644 index 0ea88bf..0000000 --- a/examples/ex_arro.py +++ /dev/null @@ -1,26 +0,0 @@ -#/usr/bin/env python - -from Numeric import * -from ppgplot import * - -# initialize ploting. -pgbeg("?",1,1) # open ploting device -pgask(1) # wait for user to press a key before erasing. -pgswin(-10,10,-10,10) # set axis ranges. - # label the plot. -pgiden() # put user-name and date on plot. - -# calculate a suitable function. -f = arange(0,2*pi,0.25) -fx = cos(f); -fy = sin(f); - -for i in range(f.shape[0]): - pgslw(i%10+1) # set line-width - pgsls(i%5+1) # set line-style - pgsci(i%15+1) # set color-index - pgarro(fx[i],fy[i],10*fx[i],10*fy[i]) - -#close the plot. -pgend() - diff --git a/examples/ex_cont.py b/examples/ex_cont.py deleted file mode 100644 index d83777f..0000000 --- a/examples/ex_cont.py +++ /dev/null @@ -1,36 +0,0 @@ -#/usr/bin/env python - -from Numeric import * -from ppgplot import * - -# initialize ploting. -pgbeg("?",1,1) # open ploting device -pgask(1) # wait for user to press a key before erasing. -pgenv(1,40,1,40) # set axis ranges, and draw axes. - # label the plot. -pglab("x","y","z = cos(.3*sqrt(2*x) - .4*y/3)*cos(.4*x/3) + (x-y)/40.0") -pgiden() # put user-name and date on plot. - -# calculate a suitable function. -surf = zeros([40,40],Float32) -for i in range(1,41): - for j in range(1,41): - surf[i-1,j-1] = cos(.3*sqrt(2*i) - .4*j/3)*cos(.4*i/3) + (i-j)/40.0 -mns, mxs = min(ravel(surf)), max(ravel(surf)) - - -# do the ploting. -pggray_s(surf) # image map of the array surf. -pgsci(2) # change color index to 2 (red). -pgcont_s(surf,10) # trace 10 contours on array surf. -pgsci(3) # set color index to 3 (green). -for i in range(10): # label the contours. - c = mns + i*((mxs - mns) / (10-1)) - pgconl_s(surf,c,str(i)) -pgsci(1) # set colndx back to 1 (white) - # plot a wedge to the right of the image. -pgwedg_s(max(ravel(surf)),min(ravel(surf)), "RG") - -#close the plot. -pgend() - diff --git a/examples/ex_graph.py b/examples/ex_graph.py deleted file mode 100644 index 63ef184..0000000 --- a/examples/ex_graph.py +++ /dev/null @@ -1,26 +0,0 @@ -#/usr/bin/env python -# -# pgex1: freely taken after PGDEMO1.F -# -import ppgplot, Numeric -import sys - -# create an array -xs=Numeric.array([1.,2.,3.,4.,5.]) -ys=Numeric.array([1.,4.,9.,16.,25.]) - -# creat another array -yr = 0.1*Numeric.array(range(0,60)) -xr = yr*yr - - -# pgplotting -if len(sys.argv) > 1: # if we got an argument use the argument as devicename - ppgplot.pgopen(sys.argv[1]) -else: - ppgplot.pgopen('?') -ppgplot.pgenv(0.,10.,0.,20.,0,1) -ppgplot.pglab('(x)', '(y)', 'PGPLOT Example 1: y = x\u2') -ppgplot.pgpt(xs,ys,9) -ppgplot.pgline(xr,yr) -ppgplot.pgclos() diff --git a/examples/ex_panel.py b/examples/ex_panel.py deleted file mode 100644 index 3f36e5f..0000000 --- a/examples/ex_panel.py +++ /dev/null @@ -1,46 +0,0 @@ -#/usr/bin/env python - -from Numeric import * -from ppgplot import * - -def fixenv (xrange=[0,1], yrange=[0,1], fname="none", ci = 2): - # set axis ranges. - pgswin(xrange[0],xrange[1],yrange[0],yrange[1]) - pgsci(ci) # set color index. - pgbox() # draw axes. - pgsci(1) # back to color index 1 (white) - pglab("x","y",fname) # label the plot - - -# initialize ploting. -pgbeg("?",2,2) # open ploting device (2x2 pannels) -pgiden() # put user-name and date on plot. -pgask(1) # wait for user to press a key before erasing. - -# calculate some suitable functions. -x = arange(0.01,6*pi,0.1) -y = zeros([2,2,x.shape[0]],Float64) -label = zeros([2,2],PyObject) -y[0,0] = sin(2*x)/x -label[0,0] = "sin(2*x)/x" -y[1,0] = sin(2*x) -label[1,0] = "sin(2*x)" -y[0,1] = x*sin(2*x) -label[0,1] = "x*sin(2*x)" -y[1,1] = sin(x) + sin(2*x) + sin(3*x) -label[1,1] = "sin(x) + sin(2*x) + sin(3*x)" - -# do the plotting -for i in range(2): - for j in range(2): - pgpanl(i+1,j+1) - fixenv([0.0,6*pi],[min(y[i,j]),max(y[i,j])],label[i,j], i*2+j+2) - pgslw(6); # set line-width to 6/201. - pgsls(i*2+j+1) # set the line style. - pgline(x,y[i,j]) # plot the line. - pgsls(1); # recall line-style - pgslw(1); # recall line-width - -#close the plot. -pgend() - diff --git a/examples/ex_sierp.py b/examples/ex_sierp.py deleted file mode 100644 index 589dcc7..0000000 --- a/examples/ex_sierp.py +++ /dev/null @@ -1,47 +0,0 @@ -#/usr/bin/env python - -from Numeric import * -from ppgplot import * - -s602 = sin(pi/3) / 2 -c602 = cos(pi/3) / 2 - -def drawtriangle (p1, p2, p3, i): - if (i > 5) : - return - l = sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) - pgmove(p1[0], p1[1]) - pgdraw(p2[0], p2[1]) - pgdraw(p3[0], p3[1]) - pgdraw(p1[0], p1[1]) - - pgsci(1) - drawtriangle(p1, [p1[0] + l/2, p1[1]], \ - [p1[0] + l*c602, p1[1] + l*s602], i+1) - pgsci(2) - drawtriangle([p2[0] - l/2, p2[1]], p2, \ - [p2[0] - l*c602, p2[1] + l*s602], i+1) - pgsci(3) - drawtriangle([p3[0] - l*c602, p3[1] - l*s602], \ - [p3[0] + l*c602, p3[1] - l*s602], p3, i+1) - - -l = 1 -p1 = [0,0] -p2 = [l,0] -p3 = [cos(pi/3), sin(pi/3)] - -print p3 - -pgbeg('?') -pgask(1) -pgenv(0,1,0,1) -pgslw(5) -pgsci(1) - - -drawtriangle(p1,p2,p3,0) -pgend() - - - diff --git a/examples/na_ex_arro.py b/examples/na_ex_arro.py deleted file mode 100644 index f18feee..0000000 --- a/examples/na_ex_arro.py +++ /dev/null @@ -1,26 +0,0 @@ -#/usr/bin/env python - -from numarray import * -from ppgplot import * - -# initialize ploting. -pgbeg("?",1,1) # open ploting device -pgask(1) # wait for user to press a key before erasing. -pgswin(-10,10,-10,10) # set axis ranges. - # label the plot. -pgiden() # put user-name and date on plot. - -# calculate a suitable function. -f = arange(0,2*pi,0.25) -fx = cos(f); -fy = sin(f); - -for i in range(f.shape[0]): - pgslw(i%10+1) # set line-width - pgsls(i%5+1) # set line-style - pgsci(i%15+1) # set color-index - pgarro(fx[i],fy[i],10*fx[i],10*fy[i]) - -#close the plot. -pgend() - diff --git a/examples/na_ex_cont.py b/examples/na_ex_cont.py deleted file mode 100644 index 819fc12..0000000 --- a/examples/na_ex_cont.py +++ /dev/null @@ -1,36 +0,0 @@ -#/usr/bin/env python - -from numarray import * -from ppgplot import * - -# initialize ploting. -pgbeg("?",1,1) # open ploting device -pgask(1) # wait for user to press a key before erasing. -pgenv(1,40,1,40) # set axis ranges, and draw axes. - # label the plot. -pglab("x","y","z = cos(.3*sqrt(2*x) - .4*y/3)*cos(.4*x/3) + (x-y)/40.0") -pgiden() # put user-name and date on plot. - -# calculate a suitable function. -surf = zeros([40,40],Float32) -for i in range(1,41): - for j in range(1,41): - surf[i-1,j-1] = cos(.3*sqrt(2*i) - .4*j/3)*cos(.4*i/3) + (i-j)/40.0 -mns, mxs = min(ravel(surf)), max(ravel(surf)) - - -# do the ploting. -pggray_s(surf) # image map of the array surf. -pgsci(2) # change color index to 2 (red). -pgcont_s(surf,10) # trace 10 contours on array surf. -pgsci(3) # set color index to 3 (green). -for i in range(10): # label the contours. - c = mns + i*((mxs - mns) / (10-1)) - pgconl_s(surf,c,str(i)) -pgsci(1) # set colndx back to 1 (white) - # plot a wedge to the right of the image. -pgwedg_s(max(ravel(surf)),min(ravel(surf)), "RG") - -#close the plot. -pgend() - diff --git a/examples/na_ex_graph.py b/examples/na_ex_graph.py deleted file mode 100644 index 462bd01..0000000 --- a/examples/na_ex_graph.py +++ /dev/null @@ -1,26 +0,0 @@ -#/usr/bin/env python -# -# pgex1: freely taken after PGDEMO1.F -# -import ppgplot, numarray -import sys - -# create an array -xs=numarray.array([1.,2.,3.,4.,5.]) -ys=numarray.array([1.,4.,9.,16.,25.]) - -# creat another array -yr = 0.1*numarray.array(range(0,60)) -xr = yr*yr - - -# pgplotting -if len(sys.argv) > 1: # if we got an argument use the argument as devicename - ppgplot.pgopen(sys.argv[1]) -else: - ppgplot.pgopen('?') -ppgplot.pgenv(0.,10.,0.,20.,0,1) -ppgplot.pglab('(x)', '(y)', 'PGPLOT Example 1: y = x\u2') -ppgplot.pgpt(xs,ys,9) -ppgplot.pgline(xr,yr) -ppgplot.pgclos() diff --git a/examples/na_ex_panel.py b/examples/na_ex_panel.py deleted file mode 100644 index 8208e90..0000000 --- a/examples/na_ex_panel.py +++ /dev/null @@ -1,46 +0,0 @@ -#/usr/bin/env python - -from numarray import * -from ppgplot import * - -def fixenv (xrange=[0,1], yrange=[0,1], fname="none", ci = 2): - # set axis ranges. - pgswin(xrange[0],xrange[1],yrange[0],yrange[1]) - pgsci(ci) # set color index. - pgbox() # draw axes. - pgsci(1) # back to color index 1 (white) - pglab("x","y",fname) # label the plot - - -# initialize ploting. -pgbeg("?",2,2) # open ploting device (2x2 pannels) -pgiden() # put user-name and date on plot. -pgask(1) # wait for user to press a key before erasing. - -# calculate some suitable functions. -x = arange(0.01,6*pi,0.1) -y = zeros([2,2,x.shape[0]],Float64) -label = zeros([2,2],PyObject) -y[0,0] = sin(2*x)/x -label[0,0] = "sin(2*x)/x" -y[1,0] = sin(2*x) -label[1,0] = "sin(2*x)" -y[0,1] = x*sin(2*x) -label[0,1] = "x*sin(2*x)" -y[1,1] = sin(x) + sin(2*x) + sin(3*x) -label[1,1] = "sin(x) + sin(2*x) + sin(3*x)" - -# do the plotting -for i in range(2): - for j in range(2): - pgpanl(i+1,j+1) - fixenv([0.0,6*pi],[min(y[i,j]),max(y[i,j])],label[i,j], i*2+j+2) - pgslw(6); # set line-width to 6/201. - pgsls(i*2+j+1) # set the line style. - pgline(x,y[i,j]) # plot the line. - pgsls(1); # recall line-style - pgslw(1); # recall line-width - -#close the plot. -pgend() - diff --git a/examples/na_ex_sierp.py b/examples/na_ex_sierp.py deleted file mode 100644 index 5282ac5..0000000 --- a/examples/na_ex_sierp.py +++ /dev/null @@ -1,47 +0,0 @@ -#/usr/bin/env python - -from numarray import * -from ppgplot import * - -s602 = sin(pi/3) / 2 -c602 = cos(pi/3) / 2 - -def drawtriangle (p1, p2, p3, i): - if (i > 5) : - return - l = sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) - pgmove(p1[0], p1[1]) - pgdraw(p2[0], p2[1]) - pgdraw(p3[0], p3[1]) - pgdraw(p1[0], p1[1]) - - pgsci(1) - drawtriangle(p1, [p1[0] + l/2, p1[1]], \ - [p1[0] + l*c602, p1[1] + l*s602], i+1) - pgsci(2) - drawtriangle([p2[0] - l/2, p2[1]], p2, \ - [p2[0] - l*c602, p2[1] + l*s602], i+1) - pgsci(3) - drawtriangle([p3[0] - l*c602, p3[1] - l*s602], \ - [p3[0] + l*c602, p3[1] - l*s602], p3, i+1) - - -l = 1 -p1 = [0,0] -p2 = [l,0] -p3 = [cos(pi/3), sin(pi/3)] - -print p3 - -pgbeg('?') -pgask(1) -pgenv(0,1,0,1) -pgslw(5) -pgsci(1) - - -drawtriangle(p1,p2,p3,0) -pgend() - - - diff --git a/examples/numpy_ex_arro.py b/examples/numpy_ex_arro.py index e2e446c..7a27365 100644 --- a/examples/numpy_ex_arro.py +++ b/examples/numpy_ex_arro.py @@ -1,6 +1,6 @@ #/usr/bin/env python -from numpy import * +import numpy as np from ppgplot import * # initialize ploting. @@ -11,9 +11,9 @@ pgiden() # put user-name and date on plot. # calculate a suitable function. -f = arange(0,2*pi,0.25) -fx = cos(f); -fy = sin(f); +f = np.arange(0,2*np.pi,0.25) +fx = np.cos(f); +fy = np.sin(f); for i in range(f.shape[0]): pgslw(i%10+1) # set line-width diff --git a/examples/numpy_ex_cont.py b/examples/numpy_ex_cont.py index e5dc38b..99f5fac 100644 --- a/examples/numpy_ex_cont.py +++ b/examples/numpy_ex_cont.py @@ -1,6 +1,6 @@ #/usr/bin/env python -from numpy import * +import numpy as np from ppgplot import * # initialize ploting. @@ -12,11 +12,11 @@ pgiden() # put user-name and date on plot. # calculate a suitable function. -surf = zeros([40,40],Float32) +surf = np.zeros([40,40], dtype=np.float32) for i in range(1,41): for j in range(1,41): - surf[i-1,j-1] = cos(.3*sqrt(2*i) - .4*j/3)*cos(.4*i/3) + (i-j)/40.0 -mns, mxs = min(ravel(surf)), max(ravel(surf)) + surf[i-1,j-1] = np.cos(.3*np.sqrt(2*i) - .4*j/3)*np.cos(.4*i/3) + (i-j)/40.0 +mns, mxs = min(np.ravel(surf)), max(np.ravel(surf)) # do the ploting. @@ -29,8 +29,7 @@ pgconl_s(surf,c,str(i)) pgsci(1) # set colndx back to 1 (white) # plot a wedge to the right of the image. -pgwedg_s(max(ravel(surf)),min(ravel(surf)), "RG") +pgwedg_s(max(np.ravel(surf)),min(np.ravel(surf)), "RG") #close the plot. pgend() - diff --git a/examples/numpy_ex_graph.py b/examples/numpy_ex_graph.py index 01a739b..7502676 100644 --- a/examples/numpy_ex_graph.py +++ b/examples/numpy_ex_graph.py @@ -2,15 +2,16 @@ # # pgex1: freely taken after PGDEMO1.F # -import ppgplot, numpy +import ppgplot +import numpy as np import sys # create an array -xs=numpy.array([1.,2.,3.,4.,5.]) -ys=numpy.array([1.,4.,9.,16.,25.]) +xs=[1.,2.,3.,4.,5.] +ys=np.array([1.,4.,9.,16.,25.]) # creat another array -yr = 0.1*numpy.array(range(0,60)) +yr = 0.1*np.array(range(0,60)) xr = yr*yr @@ -20,7 +21,7 @@ else: ppgplot.pgopen('?') ppgplot.pgenv(0.,10.,0.,20.,0,1) -ppgplot.pglab('(x)', '(y)', 'PGPLOT Example 1: y = x\u2') +ppgplot.pglab('(x)', '(y)', r'PGPLOT Example 1: y = x\u2') ppgplot.pgpt(xs,ys,9) ppgplot.pgline(xr,yr) ppgplot.pgclos() diff --git a/examples/numpy_ex_panel.py b/examples/numpy_ex_panel.py index 255600e..7fb7384 100644 --- a/examples/numpy_ex_panel.py +++ b/examples/numpy_ex_panel.py @@ -1,6 +1,6 @@ #/usr/bin/env python -from numpy import * +import numpy as np from ppgplot import * def fixenv (xrange=[0,1], yrange=[0,1], fname="none", ci = 2): @@ -18,28 +18,28 @@ def fixenv (xrange=[0,1], yrange=[0,1], fname="none", ci = 2): pgask(1) # wait for user to press a key before erasing. # calculate some suitable functions. -x = arange(0.01,6*pi,0.1) -y = zeros([2,2,x.shape[0]],Float64) -label = zeros([2,2],PyObject) -y[0,0] = sin(2*x)/x +x = np.arange(0.01,6*np.pi,0.1) +y = np.zeros([2,2,x.shape[0]], dtype=np.float64) +label = np.zeros([2,2], dtype=str) +y[0,0] = np.sin(2*x)/x label[0,0] = "sin(2*x)/x" -y[1,0] = sin(2*x) +y[1,0] = np.sin(2*x) label[1,0] = "sin(2*x)" -y[0,1] = x*sin(2*x) +y[0,1] = x*np.sin(2*x) label[0,1] = "x*sin(2*x)" -y[1,1] = sin(x) + sin(2*x) + sin(3*x) +y[1,1] = np.sin(x) + np.sin(2*x) + np.sin(3*x) label[1,1] = "sin(x) + sin(2*x) + sin(3*x)" # do the plotting for i in range(2): for j in range(2): - pgpanl(i+1,j+1) - fixenv([0.0,6*pi],[min(y[i,j]),max(y[i,j])],label[i,j], i*2+j+2) - pgslw(6); # set line-width to 6/201. - pgsls(i*2+j+1) # set the line style. - pgline(x,y[i,j]) # plot the line. - pgsls(1); # recall line-style - pgslw(1); # recall line-width + pgpanl(i+1,j+1) + fixenv([0.0,6*np.pi],[min(y[i,j]),max(y[i,j])],label[i,j], i*2+j+2) + pgslw(6); # set line-width to 6/201. + pgsls(i*2+j+1) # set the line style. + pgline(x,y[i,j]) # plot the line. + pgsls(1); # recall line-style + pgslw(1); # recall line-width #close the plot. pgend() diff --git a/examples/numpy_ex_sierp.py b/examples/numpy_ex_sierp.py index 9dabef7..a0226ed 100644 --- a/examples/numpy_ex_sierp.py +++ b/examples/numpy_ex_sierp.py @@ -1,15 +1,15 @@ #/usr/bin/env python -from numpy import * +import math from ppgplot import * -s602 = sin(pi/3) / 2 -c602 = cos(pi/3) / 2 +s602 = math.sin(math.pi/3) / 2 +c602 = math.cos(math.pi/3) / 2 def drawtriangle (p1, p2, p3, i): if (i > 5) : - return - l = sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) + return + l = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) pgmove(p1[0], p1[1]) pgdraw(p2[0], p2[1]) pgdraw(p3[0], p3[1]) @@ -29,9 +29,9 @@ def drawtriangle (p1, p2, p3, i): l = 1 p1 = [0,0] p2 = [l,0] -p3 = [cos(pi/3), sin(pi/3)] +p3 = [math.cos(math.pi/3), math.sin(math.pi/3)] -print p3 +print(p3) pgbeg('?') pgask(1) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2f8e790 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,56 @@ +# https://numpy.org/devdocs/dev/depending_on_numpy.html#numpy-2-abi-handling +[build-system] +requires = ["setuptools>=45", "numpy>=2.0.0rc1", "pkgconfig", "wheel", "cibuildwheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "python-pgplot" +version = "1.6.1" +description = "Python bindings for PGPLOT" +authors = [ + {name = "Marjolein Verkouter", email = "verkouter@jive.eu"}, + {name = "Nick Patavalis" }, + {name = "MA Breddels" }, + {name = "C Bassa" } +] +maintainers = [ + {name = "Marjolein Verkouter", email = "verkouter@jive.eu"} +] +readme = "README.md" +requires-python = ">=3.9" +dependencies = [ + "numpy>=1.19.0", +# "pkgconfig" +] +license = "LGPL-2.0-only" +license-files = [ + "LICENSE", + "AUTHORS" +] + +[external] +build-requires = [ + "virtual:compiler/c", + "pkg:generic/pkg-config", + "pkg:generic/giza", +] +host-requires = [ + "pkg:generic/giza", +] +dependencies = [ + "pkg:generic/giza", +] + +[project.urls] +Homepage = "https://github.com/haavee/ppgplot" + +[tool.setuptools] +packages = ["ppgplot"] +package-dir = {"ppgplot" = "src"} + +[tool.cibuildwheel] +# Test that giza is available +before-build = "pkg-config --exists giza && echo 'giza found' || echo 'giza NOT found'" +# Not on Windhoos, nor on musllinux (wtf) +# No numpy2 on Py3.8 +skip = ["*-win*", "*musllinux*", "cp38-*" ] diff --git a/setup.py b/setup.py index b4264a6..b58e7d6 100644 --- a/setup.py +++ b/setup.py @@ -1,121 +1,128 @@ -from distutils.sysconfig import get_python_inc, get_python_lib +from setuptools import setup, Extension import os import sys +import platform +import operator +# these deps are listed in pyproject.toml so should be able to import w/o probs +import numpy +import pkgconfig -################################################################### -# build the extension -# -define_macros = [] -undef_macros = [] -include_dirs = [] -extra_compile_args = [] -libraries = ["cpgplot", "pgplot"] -library_dirs = [] -name = "ppgplot" +def is_building_sdist(): + """Detect if we're building a source distribution (sdist)""" + # Check for sdist-related commands in sys.argv + sdist_commands = ['sdist', 'egg_info', 'dist_info'] + return any(cmd in sys.argv for cmd in sdist_commands) -found_module = False -try: - # Try to use the "numpy" module (1st option) - # uncomment the following line to disable usage of numpy - #raise ImportError - from numpy.distutils.core import setup, Extension - from numpy.distutils.misc_util import get_numpy_include_dirs - make_extension = Extension - include_dirs.extend(get_numpy_include_dirs()) - define_macros.append(('USE_NUMPY', None)) - undef_macros.append('USE_NUMARRAY') - print >>sys.stderr, "using numpy..." - found_module = True - # uncommenting the following line retains any previous ppgplot - # package and installs this numpy-compatible version as - # the package ppgplot_numpy - #name = "ppgplot_numpy" -except ImportError: - pass +def add_pgplot_from_giza(ext): + # Very convenient - but also breaks the build on Linux (Deb12) *sigh* + # adds an empty string [''] to ext.extra_compile_args + pkgconfig.configure_extension(ext, 'giza', static=True) + ext.extra_compile_args = list( filter(operator.truth, ext.extra_compile_args) ) + # But not sufficient ... + ext.libraries.extend( ['cpgplot', 'pgplot'] ) + return ext -if not found_module: - try: - # Try to use the "numarray" module (2nd option) - # uncomment the following line to disable usage of numarray - #raise ImportError - from distutils.core import setup - from numarray.numarrayext import NumarrayExtension - make_extension = NumarrayExtension - define_macros.append(('USE_NUMARRAY', None)) - print >>sys.stderr, "using numarray..." - found_module = True - # uncommenting the following line retains any previous ppgplot - # package and installs this numpy-compatible version as - # the package ppgplot_numpy - #name = "ppgplot_numarray" - except ImportError: - pass +# Configure the Extension based on stuff found in PGPLOT_DIR +def add_pgplot_from_pgplot_dir(ext, pgplotdir): + if not os.path.isdir(pgplotdir): + raise RuntimeError(f"$PGPLOT_DIR [{pgplotdir}] is not a directory") + darwin = 'darwin' in platform.system().lower() + soext = 'dylib' if darwin else 'so' + mk_rpath = ("-Wl,-rpath,{0}" if darwin else "-Wl,-rpath={0}").format + mk_lib = f"lib{{0}}.{soext}".format + # Find libcpgplot + lib = mk_lib("cpgplot") + for path, _, files in os.walk(pgplotdir): + if lib not in files: + continue + # OK found it! + # Configure runtime library paths + ext.extra_link_args.append( mk_rpath(path) ) -if not found_module: - try: - # Try to use the "Numeric" module (3rd option) - # uncomment the following line to disable usage of Numeric - #raise ImportError - from distutils.core import setup, Extension - make_extension = Extension - include_dirs.append( - os.path.join(get_python_inc(plat_specific=1), "Numeric")) - undef_macros.append('USE_NUMARRAY') - print >>sys.stderr, "using Numeric..." - found_module = True - # uncommenting the following line retains any previous ppgplot - # package and installs this numpy-compatible version as - # the package ppgplot_numpy - #name = "ppgplot_Numeric" - except ImportError: - pass + # Because we're overriding system settings, add + # the libraries with absolute path + ext.extra_link_args.extend( map(lambda l: os.path.join(path, l), + map(mk_lib, ['cpgplot', 'pgplot'])) ) + ext.runtime_library_dirs.append( path ) + ext.include_dirs.append( os.path.join(pgplotdir, "include") ) + break + else: + raise RuntimeError(f"Could not find libcpgplot in $PGPLOT_DIR [{pgplotdir}]") + return ext -if not found_module: - raise Exception, "None of numpy, numarray or Numeric found" +# Extract useful info from the numpy module +def add_numpy(ext): + ext.include_dirs.append( numpy.get_include() ) + return ext -if os.name == "posix": - #libraries.append("png") - libraries.append("X11") - libraries.append("m") - # comment out g2c if compiling with gfortran (typical nowadays) - # you may still need this if using an earlier fortran compiler - # libraries.append("g2c") - library_dirs.append("/usr/X11R6/lib/") - if os.environ.has_key("PGPLOT_DIR"): - library_dirs.append(os.environ["PGPLOT_DIR"]) - include_dirs.append(os.environ["PGPLOT_DIR"]) - # locate Aquaterm dynamic library if running Mac OS X SCISOFT - # (www.stecf.org/macosxscisoft/) - elif os.environ.has_key("SCIDIR"): - libraries.append("aquaterm") - library_dirs.append(os.path.join(os.environ["SCIDIR"], 'lib')) - else: - print >>sys.stderr, "PGPLOT_DIR env var not defined!" -else: - raise Exception, "os not supported" +# Set up X11 libraries, searching standard (Linux...) paths +def add_X11(ext): + ext.libraries.extend(['X11', 'm']) + # Standard X11 library locations + ext.library_dirs.extend( + filter(os.path.isdir, + ["/usr/lib/x86_64-linux-gnu/", "/usr/X11R6/lib/", "/opt/X11/lib", "/opt/homebrew/lib"]) + ) + return ext + +def print_config(ext): + print("===> Extension contents") + print(f"\tname = {ext.name}") + print(f"\tsources = {ext.sources}") + print(f"\tlibraries = {ext.libraries}") + print(f"\tdefine_macros = {ext.define_macros}") + print(f"\tundef_macros = {ext.undef_macros}") + print(f"\tlibrary_dirs = {ext.library_dirs}") + print(f"\tinclude_dirs = {ext.include_dirs}") + print(f"\textra_link_args = {ext.extra_link_args}") + print(f"\truntime_library_dirs = {ext.runtime_library_dirs}") + print(f"\textra_objects = {ext.extra_objects}") + print(f"\textra_compile_args = {ext.extra_compile_args}") + print(f"\texport_symbols = {ext.export_symbols}") + print(f"\tswig_opts = {ext.swig_opts}") + print(f"\tdepends = {ext.depends}") + print(f"\tlanguage = {ext.language}") + print(f"\toptional = {ext.optional}") + print(f"\tpy_limited_api = {ext.py_limited_api}") + return ext -ext_ppgplot = make_extension(name+'._ppgplot', - [os.path.join('src', '_ppgplot.c')], - include_dirs=include_dirs, - libraries=libraries, - library_dirs=library_dirs, - define_macros=define_macros, - extra_compile_args=extra_compile_args) +# This is the main Extension configuration step +# We go over the dependencies, each of which +# can modify the build env as needed +def set_extension_config(ext): + # yah ... maybe later if we grow up widen this + if os.name != "posix": + raise Exception("OS not supported") + # Skip extension configuration during sdist creation + if is_building_sdist(): + print("Building sdist - skipping extension configuration") + return ext + # modify the extension to taste + add_X11(ext) + add_numpy(ext) + + # Where to source pgplot from + pgplot_dir = os.environ.get('PGPLOT_DIR', None) + if pgplot_dir is not None: + add_pgplot_from_pgplot_dir(ext, pgplot_dir) + else: + add_pgplot_from_giza(ext) + # uncomment and run "pip -v install [-e] ." to see output + #print_config(ext) + return ext -################################################################### -# the package -# +########################################################### +# This triggers the whole build # +########################################################### +setup( + name="python-pgplot", + ext_modules=[ + set_extension_config( Extension('ppgplot._ppgplot', + sources=[os.path.join('src', '_ppgplot.c')]) ), + ] +) -setup(name=name, - version="1.4", - description="Python / Numeric-Python bindings for PGPLOT", - author="Nick Patavalis", - author_email="npat@efault.net", - url="http://code.google.com/p/ppgplot/", - packages=[name], - package_dir={name:'src'}, - ext_modules=[ext_ppgplot]) diff --git a/src/__init__.py b/src/__init__.py index 544f39d..a3b59dd 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1 +1 @@ -from _ppgplot import * +from . _ppgplot import * diff --git a/src/_ppgplot.c b/src/_ppgplot.c index f9ece92..b24c805 100644 --- a/src/_ppgplot.c +++ b/src/_ppgplot.c @@ -1,3 +1,19 @@ +/* Copyright (c) 1999-2025 N Patavalis, MA Breddels, C Bassa, M Verkouter + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + + * This library 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 Lesser + * General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * . +*/ /* * FILE: * _ppgplot.c @@ -8,23 +24,28 @@ * Linux (v2.4.x). * AUTHOR(S): * Nick Patavalis (npat@efault.net) + * Marjolein Verkouter (verkouter@jive.eu) - keep it alive * NOTES: * - A few ppgplot functions have not been interfaced yet. * - The pythonic calling conventions of some functions are *not* * identical to the original PGPLOT ones. */ + #include #include #include -#ifndef USE_NUMPY -#include -#else -#include +/* It's 2025, we only support numpy anymore */ +/* Target NumPy 1.19 API for maximum compatibility while avoiding deprecated APIs */ +#ifndef NPY_TARGET_VERSION + #define NPY_TARGET_VERSION NPY_1_19_API_VERSION #endif +#define NPY_NO_DEPRECATED_API NPY_TARGET_VERSION +#include +#include /************************************************************************/ @@ -66,6 +87,8 @@ static PyObject *PpgIOErr; static PyObject *PpgTYPEErr; static PyObject *PpgMEMErr; +float xcurs=0.0, ycurs=0.0; + /**************************************************************************/ /* support functions */ /**************************************************************************/ @@ -73,161 +96,134 @@ static PyObject *PpgMEMErr; static PyObject * tofloatvector (PyObject *o, float **v, int *vsz) { - PyArrayObject *a1, *af1, *af2; - int ownedaf1=0; + /* Set up for transforming to array of floats */ + int const requirements = NPY_ARRAY_FORCECAST|NPY_ARRAY_C_CONTIGUOUS|NPY_ARRAY_ALIGNED; + npy_intp dims; + PyArray_Descr *descr = PyArray_DescrFromType(NPY_FLOAT); + PyArrayObject *af=NULL; - /* Check if args are arrays. */ + /* Check if arg is array */ if (!PyArray_Check(o)) { - PyErr_SetString(PpgTYPEErr,"object is not an array"); - return(NULL); - } - a1 = (PyArrayObject *)o; - /* Check if args are vectors. */ - if (a1->nd != 1) { - PyErr_SetString(PpgTYPEErr,"object is not a vector"); - return(NULL); + /* Nope, but maybe it can be converted to an array - note, 1D only! */ + if( (af=(PyArrayObject*)PyArray_FromAny(o, descr, 1 /*min_depth*/, 1/*max_depth*/, requirements, NULL/*context*/))==NULL ) { + PyErr_SetString(PpgTYPEErr,"cannot cast input to vector of floats"); + return NULL; + } + } else { + /* Yes, already an array, check dims and try to convert */ + PyArrayObject *a1 = (PyArrayObject *)o; + + /* Check if args are vectors. */ + if( PyArray_NDIM(a1)!=1) { + PyErr_SetString(PpgTYPEErr, "object is not a vector"); + return NULL; + } + + /* Get a FLOAT array out of the current array */ + if( (af=(PyArrayObject*)PyArray_FromArray(a1, descr, requirements))==NULL ) { + PyErr_SetString(PpgTYPEErr, "cannot cast vector to floats"); + return NULL; + } } - -#ifdef DEBUG_TOARRAY - fprintf(stderr,"(tofloatvector): array type = %d\n",a1->descr->type_num); -#endif - switch (a1->descr->type_num) { - case PyArray_FLOAT: - af1 = a1; - break; - case PyArray_CHAR: -#ifndef USE_NUMARRAY - case PyArray_UBYTE: -#endif -#ifndef USE_NUMPY - case PyArray_SBYTE: -#endif - case PyArray_SHORT: - case PyArray_INT: -#ifndef USE_NUMARRAY - case PyArray_LONG: -#endif - case PyArray_DOUBLE: - if (!(af1 = (PyArrayObject *)PyArray_Cast(a1,PyArray_FLOAT))) { - PyErr_SetString(PpgTYPEErr,"cannot cast vector to floats"); - return(NULL); - } - ownedaf1 = 1; - break; - default: - PyErr_SetString(PpgTYPEErr,"cannot cast vector to floats"); - return(NULL); - break; - } - -#ifdef DEBUG_TOARRAY - fprintf(stderr,"(tofloatvector): array type = %d\n",a1->descr->type_num); -#endif - - af2 = af1; - if (PyArray_As1D((PyObject **)&af2, (char **)v, vsz, - PyArray_FLOAT) == -1) { - af2 = NULL; + /* af1 now points at a new array object. + * Ask the library to transform it into a C-Array */ + if( PyArray_AsCArray((PyObject **)&af, (void *)v, &dims, 1, descr) == -1) { + PyErr_SetString(PpgTYPEErr, "cannot cast array to C-array of floats"); + return NULL; } - - if (ownedaf1) { Py_DECREF(af1); } - - return((PyObject *)af2); + *vsz = dims; + /* Tell the system we have this object and the data descriptor */ + Py_INCREF(descr); + Py_INCREF(af); + return (PyObject *)af; } /*************************************************************************/ static PyObject * -tofloatmat(PyObject *o, float **m, int *nr, int *nc) +tofloatmat(PyObject *o, float **m, int *nr, int* nc) { - PyArrayObject *a1, *af1, *af2; - int ownedaf1=0; - char **tmpdat; - - /* Check if args are arrays. */ + /* Set up for transforming to array of floats */ + int const requirements = NPY_ARRAY_FORCECAST|NPY_ARRAY_C_CONTIGUOUS|NPY_ARRAY_ALIGNED; + npy_intp dims[2]; + PyArray_Descr *descr = PyArray_DescrFromType(NPY_FLOAT); + PyArrayObject *af=NULL; + + /* Check if arg is array */ if (!PyArray_Check(o)) { - PyErr_SetString(PpgTYPEErr,"object is not and array"); - return(NULL); + /* Nope, but maybe it can be converted to an array - note, 2D only! */ + if( (af=(PyArrayObject*)PyArray_FromAny(o, descr, 2 /*min_depth*/, 2/*max_depth*/, requirements, NULL/*context*/))==NULL ) { + PyErr_SetString(PpgTYPEErr,"cannot cast input to matrix of floats"); + return NULL; + } + } else { + /* Yes, already an array, check dims and try to convert */ + PyArrayObject *a1 = (PyArrayObject *)o; + + /* Check if arg is matrix. */ + if( PyArray_NDIM(a1)!=2) { + PyErr_SetString(PpgTYPEErr, "object is not a matrix"); + return NULL; + } + + /* Get a FLOAT array out of the current array */ + if( (af=(PyArrayObject*)PyArray_FromArray(a1, descr, requirements))==NULL ) { + PyErr_SetString(PpgTYPEErr, "cannot cast matrix to floats"); + return NULL; + } } - a1 = (PyArrayObject *)o; - /* Check if args are matrices. */ - if (a1->nd != 2) { - PyErr_SetString(PpgTYPEErr,"object is not a matrix"); - return(NULL); + + /* af1 now points at a new array object. + * Ask the library to transform it into a C-Array */ + if( PyArray_AsCArray((PyObject **)&af, (void *)m, &dims[0], 2, descr) == -1) { + PyErr_SetString(PpgTYPEErr, "cannot cast array to C-array of floats"); + return NULL; } - + *nr = dims[0]; + *nc = dims[1]; + /* Tell the system we have this object and the data type descriptor */ + Py_INCREF(descr); + Py_INCREF(af); + return (PyObject *)af; +} + + +/**************************************************************************/ + #ifdef DEBUG_TOARRAY - fprintf(stderr,"(tofloatmat): array type = %d\n",a1->descr->type_num); -#endif + +PYF(tstvec) +{ + PyObject *o=NULL; + PyArrayObject *af=NULL; + float *v; + int i=0,j=0, n=0; - switch (a1->descr->type_num) { - case PyArray_FLOAT: - af1 = a1; - break; - case PyArray_CHAR: -#ifndef USE_NUMARRAY - case PyArray_UBYTE: -#endif -#ifndef USE_NUMPY - case PyArray_SBYTE: -#endif - case PyArray_SHORT: - case PyArray_INT: -#ifndef USE_NUMARRAY - case PyArray_LONG: -#endif - case PyArray_DOUBLE: - if (!(af1 = (PyArrayObject *)PyArray_Cast(a1,PyArray_FLOAT))) { - PyErr_SetString(PpgTYPEErr,"cannot cast matrix to floats"); - return(NULL); - } - ownedaf1 = 1; - break; - default: - PyErr_SetString(PpgTYPEErr,"cannot cast matrix to floats"); - return(NULL); - break; - } + if(!PyArg_ParseTuple(args,"O",&o)) return(NULL); -#ifdef DEBUG_TOARRAY - fprintf(stderr,"(tofloatmat): array type = %d\n",a1->descr->type_num); -#endif + if (!(af =(PyArrayObject *)tofloatvector(o,&v,&n))) goto fail; - af2 = af1; - if (PyArray_As2D((PyObject **)&af2, (char ***)&tmpdat, nr, nc, - PyArray_FLOAT) == -1) { - af2 = NULL; - goto bailout; + for (i=0; i0 && (i%10)==0 ) + fprintf(stderr, "\n"); } - - /* WARNING: What follows is a little tricky and I dunno if I'm - really allowed to do this. On the other hand it really conserves - time and memory! So this assert statement will make sure that - the program *will* blow in your face if what I'm doing here - turns-out be bogus. */ - assert((af2->dimensions[1] * af2->descr->elsize) == af2->strides[0]); - - /* Phew! we 're clear! */ - *m = (float *)(*tmpdat); - /* tmpdat was malloc'ed inside PyArray_As2D. We must free it. - Look at the code of PyArray_As2D for details... */ - free(tmpdat); + fprintf(stderr, "\n"); -bailout: - if (ownedaf1) { Py_DECREF(af1); } - return((PyObject *)af2); -} - -/**************************************************************************/ + Py_DECREF(af); + PYRN; -#ifdef DEBUG_TOARRAY +fail: + if (af) Py_DECREF(af); + return(NULL); +} PYF(tstmat) { PyObject *o=NULL; PyArrayObject *af=NULL; - float *v; + float **v; int i=0,j=0, nc=0, nr=0; if(!PyArg_ParseTuple(args,"O",&o)) return(NULL); @@ -235,9 +231,13 @@ PYF(tstmat) if (!(af =(PyArrayObject *)tofloatmat(o,&v,&nr,&nc))) goto fail; for (i=0; i= 3 + static struct PyModuleDef ppgplotdef = { + PyModuleDef_HEAD_INIT, + "_ppgplot", /* m_name */ + "PPGPLOT Module", /* m_doc */ + -1, /* m_size */ + PpgMethods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ + }; +#endif + /************************************************************************/ -void -init_ppgplot (void) + + +static PyObject * +moduleinit(void) { PyObject *m, *d; +#if PY_MAJOR_VERSION <= 2 m = Py_InitModule("_ppgplot", PpgMethods); +#else + m = PyModule_Create(&ppgplotdef); +#endif d = PyModule_GetDict(m); - import_array(); - PpgIOErr = PyString_FromString("_ppgplot.ioerror"); +#if PY_MAJOR_VERSION <= 2 + PpgIOErr = PyString_FromString("_ppgplot.ioerror"); PpgTYPEErr = PyString_FromString("_ppgplot.typeerror"); - PpgMEMErr = PyString_FromString("_ppgplot.memerror"); + PpgMEMErr = PyString_FromString("_ppgplot.memerror"); +#else + PpgIOErr = PyErr_NewException("_ppgplot.ioerror", NULL, NULL); + PpgTYPEErr = PyErr_NewException("_ppgplot.typeerror", NULL, NULL); + PpgMEMErr = PyErr_NewException("_ppgplot.memerror", NULL, NULL); +#endif PyDict_SetItemString(d, "ioerror", PpgIOErr); PyDict_SetItemString(d, "typeerror", PpgTYPEErr); PyDict_SetItemString(d, "memerror", PpgMEMErr); + return m; } +#if PY_MAJOR_VERSION < 3 + void + init_ppgplot(void) + { + import_array(); + moduleinit(); + } +#else + PyMODINIT_FUNC + PyInit__ppgplot(void) + { + import_array(); + return moduleinit(); + } +#endif /************************************************************************/ /* End of _ppgplot.c */ /************************************************************************/