Skip to content

Commit

Permalink
Merge pull request #11 from kbairak/square_brackets_and_black
Browse files Browse the repository at this point in the history
Add square-bracket notation and black
  • Loading branch information
Konstantinos Bairaktaris authored Sep 20, 2022
2 parents ca897ee + 8db3529 commit 440b666
Show file tree
Hide file tree
Showing 22 changed files with 967 additions and 635 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

name: Test and publish

on: [push]
Expand All @@ -8,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, pypy-3.7]
python-version: [3.7, 3.8, 3.9, '3.10', pypy-3.7, pypy-3.8, pypy-3.9]

steps:
- uses: actions/checkout@v2
Expand All @@ -22,6 +24,7 @@ jobs:
python -m pip install -r test_requirements.txt
python -m pip install flake8
python -m pip install isort
python -m pip install black
- name: Run checks
run: pymake checks
- name: Test with pytest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
dist
.coverage
htmlcov
__pycache__
41 changes: 25 additions & 16 deletions Makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,73 @@


def test():
""" Run tests """
"""Run tests"""

from pipepy import pytest

pytest()


def covtest():
""" Run tests and produce coverge report """
"""Run tests and produce coverge report"""

from pipepy import pytest

pytest(cov="src/pipepy", cov_report="term-missing")()


def html(covtest):
""" Run tests and open coverage report in browser """
"""Run tests and open coverage report in browser"""

from pipepy import coverage, xdg_open

coverage.html()
xdg_open("htmlcov/index.html")()


def watchtest():
""" Automatically run tests when a source file changes """
"""Automatically run tests when a source file changes"""

from pipepy import pytest_watch

pytest_watch()


def debugtest():
""" Run tests without capturing their output. This makes using an
interactive debugger possible
"""Run tests without capturing their output. This makes using an
interactive debugger possible
"""

from pipepy import pytest
pytest('-s')()

s = "s"
cmd = pytest - s # noqa: E225
cmd()


def checks():
""" Run static checks on the code (flake8, isort) """
"""Run static checks on the code (flake8, isort)"""

from pipepy import black, flake8, isort

from pipepy import flake8, isort
flake8()
isort('.', check_only=True)()
isort(".", check_only=True)()
black(".")


def clean():
""" Clean up build directories """
"""Clean up build directories"""

rm('-rf', "build", "dist")()
rm("-rf", "build", "dist")()


def build(clean):
""" Build package """
"""Build package"""

python('-m', "build")()
python("-m", "build")()


def publish(build):
""" Publish package to PyPI """
"""Publish package to PyPI"""

python('-m', "twine").upload("dist/*")()
python("-m", "twine").upload("dist/*")()
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,27 @@ than a shell pipe operation, ie if you want to pass a command's input as an
argument, you can use the `_input` keyword argument:

```python
grep('foo', _input="foo\nbar\n")
from pipepy import grep, ls

grep('setup', _input=ls)
# Is equivalent to
ls | grep('setup')
```

or use the square-bracket notation:

```python
from pipepy import grep, ls

grep('setup')[ls]
# Is equivalent to
"foo\nbar\n" | grep('foo')
ls | grep('setup')
```

_(We use parentheses for arguments and square brackets for input because
parentheses allow us to take advantage of keyword arguments which are a good
fit for command-line options)_

This works both for inputs that are iterables and commands.

### 3. Right operand is a function
Expand Down Expand Up @@ -1286,7 +1302,7 @@ ways:

msg = "world"

def greeting(msg):
def greeting():
print(f"hello {msg}")
```

Expand Down
2 changes: 1 addition & 1 deletion check_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
git_tag = str(git.describe(tags=True)).strip()
print(f"git tag is: {git_tag}")

python_tag = pkg_resources.require('pipepy')[0].version
python_tag = pkg_resources.require("pipepy")[0].version
print(f"python tag is: {python_tag}")

if git_tag == python_tag:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ requires = [
"wheel"
]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ where=src

[options.entry_points]
console_scripts =
pymake = pipepy.pymake:pymake
pymake = pipepy.pymake:main

[flake8]
max-line-length=88
16 changes: 11 additions & 5 deletions src/pipepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from subprocess import TimeoutExpired # noqa
from subprocess import TimeoutExpired # noqa: F401

from .exceptions import PipePyError # noqa
from .misc import * # noqa
from .pipepy import (PipePy, jobs, set_always_raise, set_always_stream, # noqa
set_interactive, wait_jobs)
from .exceptions import PipePyError # noqa: F401
from .misc import * # noqa: F401 F403
from .pipepy import ( # noqa: F401
PipePy,
jobs,
set_always_raise,
set_always_stream,
set_interactive,
wait_jobs,
)
Loading

0 comments on commit 440b666

Please sign in to comment.