Skip to content

Commit

Permalink
Fixing entry points
Browse files Browse the repository at this point in the history
Whilst checking up on #9 I was browsing the other issues and thought I might be
Work related to #6

Fixes the entry points (also known as Command Line Interface) by...

* Adding `if __name__ == "__main__:"` to each of the `cll.*` submodules to instantiate and run the classes defined
  within.
* Changes some of the dependencies (`matplotlib`) to not be conditional on installing the CLI optional dependencies.
* Corrects the entry points defined in `pyproject.toml`

```bash
(igor2) ❱ pip install -e .
(igor2) ❱ igorbinarywave -f tests/data/mac-double.ibw
5
4
3
2
1
(igor2) ❱ igorpackedexperiment -f tests/data/polar-graphs-demo.pxp
[<UnknownRecord-11 139944549273552>,
 <UnknownRecord-12 139944553167504>,
 <UnknownRecord-13 139944550564240>,
 <UnknownRecord-13 139944549266768>,
 <UnknownRecord-13 139944550696400>,
 <UnknownRecord-13 139944561918096>,
 <UnknownRecord-13 139944549482768>,
 <UnknownRecord-13 139944549486032>,
 <UnknownRecord-13 139944549484816>,
 <UnknownRecord-14 139944561920272>,
 <UnknownRecord-15 139944549492432>,
 <UnknownRecord-16 139944549498448>,
 <UnknownRecord-16 139944549491792>,
 <UnknownRecord-17 139944549496784>,
 <UnknownRecord-17 139944549498704>,
 <UnknownRecord-17 139944549496912>,
 <UnknownRecord-17 139944549497040>,
 <UnknownRecord-17 139944549497232>,
 <UnknownRecord-17 139944549497296>,
 <UnknownRecord-16 139944549497424>,
 <UnknownRecord-17 139944549497552>,
 <UnknownRecord-17 139944549497680>,
 <UnknownRecord-17 139944549497872>,
 <UnknownRecord-17 139944549498512>,
 <UnknownRecord-17 139944549532496>,
 <UnknownRecord-17 139944549532816>,
 <UnknownRecord-18 139944549532112>,
 <UnknownRecord-11 139944549532176>,
 <UnknownRecord-26 139944549531984>,
 <UnknownRecord-26 139944549533072>,
 <VariablesRecord 139944549532944>,
 <HistoryRecord 139944549536208>,
 <WaveRecord 139944549536528>,
 <WaveRecord 139944549361232>,
 <WaveRecord 139944552677264>,
 <WaveRecord 139944558782928>,
 <WaveRecord 139944551312848>,
 <WaveRecord 139944552724496>,
 <WaveRecord 139944578160784>,
 <WaveRecord 139944548687696>,
 <FolderStartRecord 139944560740304>,
 <FolderStartRecord 139944561017296>,
 <VariablesRecord 139944549535312>,
 <FolderEndRecord 139944549482640>,
 <FolderStartRecord 139944548760272>,
 <VariablesRecord 139944561920208>,
 <FolderEndRecord 139944548686224>,
 <FolderEndRecord 139944556294736>,
 <RecreationRecord 139944548890320>,
 <GetHistoryRecord 139944549546960>,
 <ProcedureRecord 139944554896400>]
```

I'm not sure if this is the expected output but the entry points work in some manner. I couldn't work out the difference
between the test data files (I'm on GNU/Linux rather than OSX/Windows).

However, I don't think this should be the final solution as there is still a dependency on the original `igor` as the
[`Script`](https://github.com/wking/igor/blob/master/igor/script.py) module is imported and it would make more sense to
have the entry points defined wholly within `igor2`.
  • Loading branch information
slackline committed Dec 9, 2023
1 parent 3b958af commit acc8b1c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 48 deletions.
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."""

0 comments on commit acc8b1c

Please sign in to comment.