Repository: geowurster/pyin

Issue:
Add a flag to skip N input lines
Skip some number of lines before processing.  Using something like `--skip-lines 2` in conjunction with `--lines 10` should skip the first 2 lines and process only the next ten lines.

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 83e97c6..b2bfb42 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,12 @@
+sudo: false
+
 language: python
 
 python:
-  - "2.7"
-  - "3.3"
-  - "3.4"
+  - 2.7
+  - 3.3
+  - 3.4
+  - 3.5
 
 install:
   - pip install -e .\[dev\]
@@ -12,4 +15,4 @@ script:
   - py.test tests --cov pyin --cov-report term-missing
 
 after_success:
-  - coveralls
+  - coveralls || echo "!! intermittent coveralls failure"
diff --git a/LICENSE.txt b/LICENSE.txt
index 9640e3c..9f6aee8 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2015 Kevin D. Wurster
+Copyright (c) 2015-2016 Kevin D. Wurster
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of
 this software and associated documentation files (the "Software"), to deal in
diff --git a/pyin/__init__.py b/pyin/__init__.py
index 4cb5b31..e48091e 100644
--- a/pyin/__init__.py
+++ b/pyin/__init__.py
@@ -16,7 +16,7 @@ __source__ = 'https://github.com/geowurster/pyin'
 __license__ = '''
 MIT
 
-Copyright (c) 2015 Kevin D. Wurster
+Copyright (c) 2015-2016 Kevin D. Wurster
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of
 this software and associated documentation files (the "Software"), to deal in
diff --git a/pyin/cli.py b/pyin/cli.py
index 39295f7..9679678 100644
--- a/pyin/cli.py
+++ b/pyin/cli.py
@@ -25,16 +25,19 @@ import pyin.core
 )
 @click.option(
     '--block', is_flag=True,
-    help="Operate on all input text as though it was a single line."
+    help="Place all input text into the `line` variable."
 )
 @click.option(
     '--no-newline', is_flag=True,
     help="Don't ensure each line ends with a newline character."
 )
+@click.option(
+    '--skip', 'skip_lines', type=click.IntRange(0), metavar='INTEGER', default=0,
+    help='Skip N input lines.')
 @click.argument(
     'expressions', required=True, nargs=-1,
 )
-def main(infile, outfile, expressions, no_newline, block):
+def main(infile, outfile, expressions, no_newline, block, skip_lines):
 
     """
     It's like sed, but Python!
@@ -88,6 +91,12 @@ def main(infile, outfile, expressions, no_newline, block):
         $ python -c "help('pyin.core.pmap')"
     """
 
+    for _ in range(skip_lines):
+        try:
+            next(infile)
+        except StopIteration:
+            raise click.ClickException("Skipped all input")
+
     if block:
         iterator = [infile.read()]
     else:
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..8d0d862
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,2 @@
+[bdist_wheel]
+universal: 1


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..32fcccd
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,12 @@
+"""
+pytest fixtures
+"""
+
+
+from click.testing import CliRunner
+import pytest
+
+
+@pytest.fixture(scope='module')
+def runner():
+    return CliRunner()
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 55e3467..20ef908 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,8 +1,14 @@
+"""
+Unittests for $ pyin
+"""
+
+
 import json
 import os
 from os import path
 
 from click.testing import CliRunner
+import pytest
 
 import pyin.cli
 
@@ -76,3 +82,23 @@ def test_block_mode():
 
     expected = '{"3": null, "4": null, "0": null, "2": null, "1": null}'
     assert json.loads(expected) == json.loads(result.output)
+
+
+@pytest.mark.parametrize("skip_lines", [1, 3])
+def test_skip_single_line(runner, skip_lines):
+    result = runner.invoke(pyin.cli.main, [
+        '--skip', skip_lines,
+        'line'
+    ], input=CSV_WITH_HEADER)
+    assert result.exit_code == 0
+    expected = os.linesep.join(CSV_WITH_HEADER.splitlines()[skip_lines:])
+    assert result.output.strip() == expected.strip()
+
+
+def test_skip_all_input(runner):
+    result = runner.invoke(pyin.cli.main, [
+        '--skip', 100,
+        'line'
+    ], input=CSV_WITH_HEADER)
+    assert result.output != 0
+    assert 'skipped' in result.output.lower()