From 6e50b501fc95ed9286642d724c81052096d0fa14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 16:41:17 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - https://github.com/ambv/black → https://github.com/psf/black - [github.com/psf/black: 026c81b83454f176a9f9253cbfb70be2c159d822 → 21.11b1](https://github.com/psf/black/compare/026c81b83454f176a9f9253cbfb70be2c159d822...21.11b1) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e531187..dc73e99 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: -- repo: https://github.com/ambv/black - rev: 026c81b83454f176a9f9253cbfb70be2c159d822 +- repo: https://github.com/psf/black + rev: 21.11b1 hooks: - id: black language_version: python3.6 From 872ec7714e025281f9a7c0aee2da621b3ee1d205 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 16:41:28 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pidiff/_impl/dump/dump.py | 4 +-- scripts/make-pr | 42 +++++++++++++++++--------------- setup.py | 2 +- tests/command/test_command.py | 3 ++- tests/command/test_pipargs.py | 7 +++++- tests/command/test_virtualenv.py | 2 +- tests/dump/test_dump_version.py | 28 ++++++++++++--------- 7 files changed, 51 insertions(+), 37 deletions(-) diff --git a/pidiff/_impl/dump/dump.py b/pidiff/_impl/dump/dump.py index 55645fe..6f53c12 100644 --- a/pidiff/_impl/dump/dump.py +++ b/pidiff/_impl/dump/dump.py @@ -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) diff --git a/scripts/make-pr b/scripts/make-pr index 0bfd92e..981f54e 100755 --- a/scripts/make-pr +++ b/scripts/make-pr @@ -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) @@ -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:]) diff --git a/setup.py b/setup.py index 6ed7ecd..c536519 100644 --- a/setup.py +++ b/setup.py @@ -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/", diff --git a/tests/command/test_command.py b/tests/command/test_command.py index d89bbe8..8028078 100644 --- a/tests/command/test_command.py +++ b/tests/command/test_command.py @@ -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 = [ diff --git a/tests/command/test_pipargs.py b/tests/command/test_pipargs.py index beb914c..a3de006 100644 --- a/tests/command/test_pipargs.py +++ b/tests/command/test_pipargs.py @@ -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) diff --git a/tests/command/test_virtualenv.py b/tests/command/test_virtualenv.py index ee08cda..d34d351 100644 --- a/tests/command/test_virtualenv.py +++ b/tests/command/test_virtualenv.py @@ -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() diff --git a/tests/dump/test_dump_version.py b/tests/dump/test_dump_version.py index 093cb37..a47c2aa 100644 --- a/tests/dump/test_dump_version.py +++ b/tests/dump/test_dump_version.py @@ -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") @@ -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" @@ -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"