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

fix #329: fmt.diff checks same paths as ci._check_files #332

Merged
merged 7 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 14 additions & 12 deletions pykern/pkcli/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def run():
check_eof_newline()
check_main()
check_prints()
fmt.diff(pkio.py_path())
fmt.diff(*_paths(pkio.py_path()))
test.default_command()


Expand All @@ -122,17 +122,6 @@ def _error(m):
r = []
n = 0

def _paths(cwd):
if pkio.py_path("setup.py").isfile() and (
pkio.py_path("README.rst").isfile() or pkio.py_path("README.md").isfile()
):
return (
cwd.basename,
"tests",
"setup.py",
)
return (pkio.py_path(),)

c = pkio.py_path()
for p in _paths(c):
for f in pkio.walk_tree(p, d.include_files):
Expand All @@ -147,3 +136,16 @@ def _paths(cwd):
_error("no files found")
if r:
_error("\n".join(r))


def _paths(cwd):
if cwd.join("setup.py").isfile() and (
cwd.join("README.rst").isfile() or cwd.join("README.md").isfile()
):
return (
# POSIT: repo name
cwd.basename,
rorour marked this conversation as resolved.
Show resolved Hide resolved
"tests",
"setup.py",
)
return (pkio.py_path(),)
rorour marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 15 additions & 13 deletions pykern/pkcli/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,47 @@
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from pykern.pkdebug import pkdp, pkdlog
import py
import pykern.pksubprocess


def run(path):
def run(*paths):
"""Run black formatter on `path`

Args:
path (object): string or py.path to file or directory
*paths (strs or py.paths): strings or py.paths to file or directory
"""
_black(path)
_black(paths)


def diff(path):
"""Run diff on file comparing formated vs. current file state
def diff(*paths):
"""Run diff on file comparing formatted vs. current file state

Args:
path (object): string or py.path to file or directory
*paths (strs or py.paths): strings or py.paths to file or directory
"""
_black(path, "--diff", "--check", "--no-color")
_black(paths, "--diff", "--check", "--no-color")


def check(path):
def check(*paths):
"""Returns True if there would be diff else return False

Args:
path (object): string or py.path to file or directory
*paths (strs or py.paths): strings or py.paths to file or directory
"""
try:
_black(path, "--check")
_black(paths, "--check")
except RuntimeError as e:
if str(e) == "error exit(1)":
pykern.pkcli.command_error("path={} needs to be formatted", path)
pykern.pkcli.command_error("paths={} need to be formatted", paths)
raise


def _black(path, *args):
def _black(paths, *args):
"""Helper function invokes black with options

Args:
*paths (strs or py.paths): strings or py.paths to file or directory
*args (strs): options to be passed to black
"""
from pykern import pkunit
Expand All @@ -57,6 +59,6 @@ def _black(path, *args):
"--extend-exclude",
f"/{test.SUITE_D}/.*{pkunit.DATA_DIR_SUFFIX}/|/{pksetup.PACKAGE_DATA}/",
*args,
f"{path}",
*paths,
],
)
1 change: 0 additions & 1 deletion pykern/pkcli/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def collaborators(org, filename, affiliation="outside", private=True):


def create_issue(repo, title, body="", assignees=None, labels=None, milestone=None):

g = GitHub()
r = g.repo_arg(repo)
a = PKDict()
Expand Down
1 change: 0 additions & 1 deletion pykern/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ def _save(self):


class _Fmt(PKDict):

_MAP = PKDict(
top=PKDict(top=True),
bold=PKDict(bold=True),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
author_email="pip@pykern.org",
install_requires=[
"argh>=0.26",
"black>=22",
"black==22.12",
rorour marked this conversation as resolved.
Show resolved Hide resolved
"future>=0.14",
"github3.py>=1.1",
# for virtualenv
Expand Down
2 changes: 1 addition & 1 deletion tests/pkcli/fmt_data/check1.out/pkexcept
Original file line number Diff line number Diff line change
@@ -1 +1 @@
path=check1 needs to be formatted
paths=(local('check1'),) need to be formatted
rorour marked this conversation as resolved.
Show resolved Hide resolved