Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing entry points #10

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ igor2/_version.py

*.egg-info
.env

# Emacs
*~
\#*
33 changes: 13 additions & 20 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,26 @@ Igor2
|PyPI Version| |Build Status| |Coverage Status|


Python parser for Igor Binary Waves (.ibw) and Packed Experiment
(.pxp) files written by WaveMetrics' IGOR Pro software.
Python parser for Igor Binary Waves (``.ibw``) and Packed Experiment
(``.pxp``) files written by WaveMetrics' IGOR Pro software.

Igor2 is the continuation of the inactive
`igor <https://github.com/wking/igor>`_ project.

Igor2 is the continuation of the inactive igor project, forked
from W. Trevor King and originally written by Paul Kienzle (see
git history).

Installation
------------
You can install igor2 via pip::

pip install igor2

The commands ``igorbinarywave`` and ``igorpackedexperiment`` are currently
not properly implemented (see https://github.com/AFM-analysis/igor2/issues/6),
but it should be straight-forward to fix this.

To install igor2 with the command-line interface (CLI), run::

pip install igor2[CLI]


Usage
-----
This package is a direct replacement of `igor`. Your scripts should work
without any issues if you replace::


import igor

with::
Expand All @@ -42,7 +35,7 @@ See the docstrings and unit tests for examples using the Python API.

CLI
---
The package also installs to scripts, ``igorbinarywave`` and
The package also installs two scripts, ``igorbinarywave`` and
``igorpackedexperiment`` which can be used to dump files to stdout.
For details on their usage, use the ``--help`` option. For example::

Expand All @@ -52,14 +45,14 @@ For details on their usage, use the ``--help`` option. For example::
Testing
-------

Run internal unit tests with pytest::
Run internal unit tests by cloning the repository and installing the
test requirements ``pytest`` and then running the tests::

pip install -r tests/requirements.txt
pytest tests
git clone https://github.com/AFM-analysis/igor2.git
cd igor2
pip install -e .[dev]
pytest

The data in the ``test/data`` directory is in the Git repository, but
it is not bundled with the source code. If you want the test data,
you'll have to clone the Git repository or download a snapshot.

Licence
-------
Expand Down
20 changes: 11 additions & 9 deletions igor2/cli/igorbinarywave.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/usr/bin/env python
"""IBW -> ASCII conversion"""

import pprint

import numpy

from igor.binarywave import load
from igor2.binarywave import load
from igor.script import Script


class WaveScript (Script):
class WaveScript(Script):
def _run(self, args):
wave = load(args.infile)
numpy.savetxt(
args.outfile, wave['wave']['wData'], fmt='%g', delimiter='\t')
numpy.savetxt(args.outfile, wave["wave"]["wData"], fmt="%g", delimiter="\t")
self.plot_wave(args, wave)
if args.verbose > 0:
wave['wave'].pop('wData')
wave["wave"].pop("wData")
pprint.pprint(wave)


s = WaveScript(description=__doc__)
s.run()
def main():
s = WaveScript(description=__doc__)
s.run()


if __name__ == "__main__":
main()
25 changes: 13 additions & 12 deletions igor2/cli/igorpackedexperiment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
#
# This file is part of igor.
Expand All @@ -16,27 +14,26 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with igor. If not, see <http://www.gnu.org/licenses/>.

"PXP -> ASCII conversion"

import pprint

from igor.packed import load, walk
from igor.record.wave import WaveRecord
from igor2.packed import load, walk
from igor2.record.wave import WaveRecord
from igor.script import Script


class PackedScript (Script):
class PackedScript(Script):
def _run(self, args):
self.args = args
records, filesystem = load(args.infile)
if hasattr(args.outfile, 'write'):
if hasattr(args.outfile, "write"):
f = args.outfile # filename is actually a stream object
else:
f = open(args.outfile, 'w')
f = open(args.outfile, "w")
try:
f.write(pprint.pformat(records))
f.write('\n')
f.write("\n")
finally:
if f != args.outfile:
f.close()
Expand All @@ -49,6 +46,10 @@ def _plot_wave_callback(self, dirpath, key, value):
self.plot_wave(self.args, value.wave, title=dirpath + [key])


s = PackedScript(
description=__doc__, filetype='IGOR Packed Experiment (.pxp) file')
s.run()
def main():
s = PackedScript(description=__doc__, filetype="IGOR Packed Experiment (.pxp) file")
s.run()


if __name__ == "__main__":
main()
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ classifiers = [
]
license = {text = "GNU Lesser General Public License v3 or later (LGPLv3+)"}
dependencies = [
"numpy>=1.25.1",
"igor",
"numpy>=1.25.1",
"matplotlib",
]
dynamic = ["version"]

[project.optional-dependencies]
CLI = [
"matplotlib",
]
dev = [
"pytest",
]

[project.scripts]
igorbinarywave = 'igor2.cli:igorbinarywave'
igorpackedexperiment = 'igor2.cli:igorpackedexperiment'
igorbinarywave = 'igor2.cli.igorbinarywave:main'
igorpackedexperiment = 'igor2.cli.igorpackedexperiment:main'

[tool.setuptools]
packages = ["igor2"]
Expand Down
1 change: 0 additions & 1 deletion tests/requirements.txt

This file was deleted.

11 changes: 11 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Test the CLI entry points."""
from igor2.cli.igorbinarywave import WaveScript
from igor2.cli.igorpackedexperiment import PackedScript


def test_wavescript(capsys):
"""Test the WaveScript class entry point."""


def test_wavescript(capsys):
"""Test the PackedScript class entry point."""