Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 20, 2021
1 parent bedc9c7 commit 2252b7e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pidiff/_impl/dump/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ def egg_for_root(root_name: str):

def get_version_importlib(module) -> Optional[str]:
module_file = module.__file__
if module_file.endswith('.pyc'):
if module_file.endswith(".pyc"):
module_file = module_file[:-1]

for dist in pkg_resources.working_set: # pylint: disable=not-an-iterable
name = dist.project_name
for file in (dist_files(name) or []):
for file in dist_files(name) or []:
if str(file.locate()) == module_file:
return dist_version(name)

Expand Down
42 changes: 23 additions & 19 deletions scripts/make-pr
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import yaml

import github3

CONFIG_PATH = '~/.config/hub'
OWNER = 'rohanpm'
REPO = 'pidiff'
CONFIG_PATH = "~/.config/hub"
OWNER = "rohanpm"
REPO = "pidiff"


def github_session():
with open(os.path.expanduser(CONFIG_PATH)) as f:
hub_config = yaml.load(f)

creds = hub_config.get('github.com', [])
creds = hub_config.get("github.com", [])
if not creds:
raise RuntimeError("Login with 'hub' command first")
if len(creds) != 1:
raise RuntimeError("Unexpected content in %s" % CONFIG_PATH)

token = creds[0].get('oauth_token')
token = creds[0].get("oauth_token")
if not token:
raise RuntimeError("Missing token in %s" % CONFIG_PATH)

Expand All @@ -34,34 +34,38 @@ def github_session():

def run(raw_args):
parser = ArgumentParser()
parser.add_argument('name', help='name for branch')
parser.add_argument('--remove-branch', action='store_true',
help='remove branch if it already exists')
parser.add_argument('--skip-rebase', action='store_true',
help='do not rebase on master before push')
parser.add_argument('-m', help='pull-request message')
parser.add_argument("name", help="name for branch")
parser.add_argument(
"--remove-branch",
action="store_true",
help="remove branch if it already exists",
)
parser.add_argument(
"--skip-rebase", action="store_true", help="do not rebase on master before push"
)
parser.add_argument("-m", help="pull-request message")
args = parser.parse_args(raw_args)

if args.remove_branch:
try:
check_call(['git', 'branch', '-D', args.name])
check_call(["git", "branch", "-D", args.name])
except CalledProcessError:
pass

check_call(['git', 'checkout', '-b', args.name])
check_call(["git", "checkout", "-b", args.name])

if not args.skip_rebase:
check_call(['git', 'fetch', 'origin'])
check_call(['git', 'rebase', '-i', 'origin/master'])
check_call(["git", "fetch", "origin"])
check_call(["git", "rebase", "-i", "origin/master"])

check_call(['git', 'push', '-f', '--set-upstream', 'origin', args.name])
check_call(["git", "push", "-f", "--set-upstream", "origin", args.name])

pr_cmd = ['hub', 'pull-request']
pr_cmd = ["hub", "pull-request"]
if args.m:
pr_cmd.extend(['-m', args.m])
pr_cmd.extend(["-m", args.m])

check_call(pr_cmd)


if __name__ == '__main__':
if __name__ == "__main__":
run(sys.argv[1:])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_install_requires():
long_description=get_long_description(),
long_description_content_type="text/markdown",
install_requires=get_install_requires(),
python_requires='>=3.8',
python_requires=">=3.8",
entry_points={"console_scripts": ["pidiff=pidiff._impl.command:main"]},
project_urls={
"Documentation": "https://pidiff.dev/",
Expand Down
3 changes: 2 additions & 1 deletion tests/command/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def test_typical_diff(workdir, testapi, testname, exitcode, extra_args, caplog):


@mark.parametrize(
"testapi,exitcode,stdout", [("minorbad", 0, "1.1.0\n"), ("minorbad_nover", 30, "")],
"testapi,exitcode,stdout",
[("minorbad", 0, "1.1.0\n"), ("minorbad_nover", 30, "")],
)
def test_genversion_diff(workdir, testapi, exitcode, stdout, capsys):
sys.argv = [
Expand Down
7 changes: 6 additions & 1 deletion tests/command/test_pipargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def test_all_pip_args():


def test_empty_pip_args():
parsed = PARSER.parse_args(["src1", "src2",])
parsed = PARSER.parse_args(
[
"src1",
"src2",
]
)

pipargs = PipArgs(parsed)

Expand Down
2 changes: 1 addition & 1 deletion tests/command/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_install_fail_with_logs(caplog, tmpdir):


def test_install_uses_editable_for_local(caplog, tmpdir):
envdir = tmpdir.mkdir('env')
envdir = tmpdir.mkdir("env")

env = VirtualEnvironmentExt(str(envdir))
env.install = mock.Mock()
Expand Down
28 changes: 16 additions & 12 deletions tests/dump/test_dump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ def pkgpath(value):
locate = lambda: Path(value)
return mock.Mock(locate=locate)


def no_files(name):
return []


def test_version_from_egg(tmpdir, monkeypatch):
# Prevent any importlib.metadata matches for this test
monkeypatch.setattr(pidiff._impl.dump.dump, 'dist_files', no_files)
monkeypatch.setattr(pidiff._impl.dump.dump, "dist_files", no_files)

# make some fake egg files
tmpdir.mkdir("egg1").join("top_level.txt").write("foo\nbar\n")
Expand All @@ -33,7 +35,7 @@ def test_version_from_egg(tmpdir, monkeypatch):
str(tmpdir.join("egg5")),
]

fake_dists = [mock.Mock(egg_info=path, project_name='x') for path in fake_dists]
fake_dists = [mock.Mock(egg_info=path, project_name="x") for path in fake_dists]

# Let some of them have defined versions
fake_dists[1].version = "2.0"
Expand All @@ -49,20 +51,22 @@ def test_version_from_egg(tmpdir, monkeypatch):


def test_version_from_importlib(tmpdir, monkeypatch):
module = mock.Mock(__file__='/some/great/file.pyc')
module = mock.Mock(__file__="/some/great/file.pyc")

def mything_files(name):
assert name == 'mything'
return [pkgpath('foo'), pkgpath('bar'), pkgpath('/some/great/file.py')]
assert name == "mything"
return [pkgpath("foo"), pkgpath("bar"), pkgpath("/some/great/file.py")]

def mything_version(name):
assert name == 'mything'
return '1.2.3'
assert name == "mything"
return "1.2.3"

monkeypatch.setattr(pidiff._impl.dump.dump, 'dist_files', mything_files)
monkeypatch.setattr(pidiff._impl.dump.dump, 'dist_version', mything_version)
monkeypatch.setattr(pidiff._impl.dump.dump, "dist_files", mything_files)
monkeypatch.setattr(pidiff._impl.dump.dump, "dist_version", mything_version)

with mock.patch("pkg_resources.working_set", new=[mock.Mock(project_name='mything')]):
version = get_version('mything', module)
with mock.patch(
"pkg_resources.working_set", new=[mock.Mock(project_name="mything")]
):
version = get_version("mything", module)

assert version == '1.2.3'
assert version == "1.2.3"

0 comments on commit 2252b7e

Please sign in to comment.