8000 Merge pull request #73 from jayvdb/blacken · scijava/jgo@26920e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26920e8

Browse files
authored
Merge pull request #73 from jayvdb/blacken
Lint with black & pyflakes
2 parents 579d303 + b272589 commit 26920e8

File tree

8 files changed

+49
-39
lines changed

8 files changed

+49
-39
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ jobs:
3535
pip install -e .
3636
- name: Install pytest
3737
run: |
38-
mamba install -c conda-forge pytest
38+
mamba install -c conda-forge black pyflakes pytest
3939
- name: Test with pytest
4040
run: |
4141
pytest
42-
42+
- name: Lint with pyflakes and black
43+
shell: bash
44+
run: |
45+
pyflakes jgo/*.py
46+
black --check .

jgo/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@
44
maven_scijava_repository,
55
add_jvm_args_as_necessary,
66
)
7+
8+
__all__ = (
9+
"add_jvm_args_as_necessary",
10+
"main_from_endpoint",
11+
"main",
12+
"maven_scijava_repository",
13+
"resolve_dependencies",
14+
)

jgo/jgo.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import shutil
99
import subprocess
1010
import sys
11-
import traceback
1211
import zipfile
1312
import hashlib
1413

@@ -132,10 +131,11 @@ def dependency_string(self):
132131
return xml
133132

134133
def get_coordinates(self):
135-
return ([self.groupId, self.artifactId]
134+
return (
135+
[self.groupId, self.artifactId]
136136
+ ([self.version] if self.version != Endpoint.VERSION_MANAGED else [])
137137
+ ([self.classifier] if self.classifier else [])
138-
)
138+
)
139139

140140
def is_endpoint(string):
141141
endpoint_elements = (
@@ -215,7 +215,7 @@ def link(source, link_name, link_type="auto"):
215215
raise e
216216
try:
217217
return link(source=source, link_name=link_name, link_type="soft")
218-
except OSError as e:
218+
except OSError:
219219
pass
220220

221221
return link(source=source, link_name=link_name, link_type="copy")
@@ -232,17 +232,6 @@ def m2_path():
232232
return os.getenv("M2_REPO", (pathlib.Path.home() / ".m2").absolute())
233233

234234

235-
def expand(string, **shortcuts):
236-
237-
for (k, v) in shortcuts.items():
238-
if string in k:
239-
return "{}{}".format(
240-
v,
241-
)
242-
243-
return string
244-
245-
246235
def launch_java(
247236
jar_dir,
248237
jvm_args,
@@ -297,7 +286,12 @@ def find_endpoint(argv, shortcuts={}):
297286

298287

299288
def jgo_parser(log_levels=_default_log_levels):
300-
289+
usage = (
290+
"usage: jgo [-v] [-u] [-U] [-m] [-q] [--log-level] [--ignore-jgorc]\n"
291+
" [--link-type type] [--additional-jars jar [jar ...]]\n"
292+
" [--additional-endpoints endpoint [endpoint ...]]\n"
293+
" [JVM_OPTIONS [JVM_OPTIONS ...]] <endpoint> [main-args]"
294+
)
301295
epilog = """
302296
The endpoint should have one of the following formats:
303297
@@ -315,10 +309,7 @@ def jgo_parser(log_levels=_default_log_levels):
315309

316310
parser = argparse.ArgumentParser(
317311
description="Run Java main class from Maven coordinates.",
318-
usage="jgo [-v] [-u] [-U] [-m] [-q] [--log-level] [--ignore-jgorc]\n" +
319-
" [--link-type type] [--additional-jars jar [jar ...]]\n" +
320-
" [--additional-endpoints endpoint [endpoint ...]]\n" +
321-
" [JVM_OPTIONS [JVM_OPTIONS ...]] <endpoint> [main-args]",
312+
usage=usage[len("usage: ") :],
322313
epilog=epilog,
323314
formatter_class=argparse.RawTextHelpFormatter,
324315
)
@@ -378,8 +369,8 @@ def jgo_parser(log_levels=_default_log_levels):
378369
"--link-type",
379370
default=None,
380371
type=str,
381-
help="How to link from local Maven repository into jgo cache.\n" +
382-
"Defaults to the `links' setting in ~/.jgorc or 'auto' if not specified.",
372+
help="How to link from local Maven repository into jgo cache.\n"
373+
+ "Defaults to the `links' setting in ~/.jgorc or 'auto' if not specified.",
383374
choices=("hard", "soft", "copy", "auto"),
384375
)
385376
parser.add_argument(
@@ -656,7 +647,7 @@ def resolve_dependencies(
656647
if e.stderr:
657648
err_lines += e.stderr.decode().splitlines()
658649
for l in err_lines:
659-
if l.startswith('[ERROR]'):
650+
if l.startswith("[ERROR]"):
660651
_logger.error("\t%s", l)
661652
else:
662653
_logger.debug("\t%s", l)
@@ -703,8 +694,8 @@ def resolve_dependencies(
703694
jar_file_in_workspace,
704695
link_type=link_type,
705696
)
706-
except FileExistsError as e:
707-
# Do not throw exceptionif target file exists.
697+
except FileExistsError:
698+
# Do not throw exception if target file exists.
708699
pass
709700
pathlib.Path(build_success_file).touch(exist_ok=True)
710701
return primary_endpoint, workspace

jgo/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def add_jvm_args_as_necessary(argv, gc_option="-XX:+UseConcMarkSweepGC"):
2222
return argv
2323

2424
total_memory = psutil.virtual_memory().total
25-
exponent = 3 if total_memory > 2 * 1024 ** 3 else 2
25+
exponent = 3 if total_memory > 2 * 1024**3 else 2
2626
memory_unit = "G" if exponent == 3 else "M"
2727
max_heap_size = "{}{}".format(
28-
max(total_memory // (1024 ** exponent) // 2, 1), memory_unit
28+
max(total_memory // (1024**exponent) // 2, 1), memory_unit
2929
)
3030

3131
argv = ["-Xmx{}".format(max_heap_size)] + argv

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
license="Public domain",
1818
url="https://github.com/scijava/jgo",
1919
packages=["jgo"],
20-
test_suite="nose.collector",
2120
entry_points={"console_scripts": ["jgo=jgo:main"]},
22-
python_requires='>=3.6',
21+
python_requires=">=3.6",
2322
install_requires=["psutil"],
24-
tests_require=["nose>=1.0"],
2523
)

tests/test_managed.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import glob
22
from jgo.jgo import InvalidEndpoint
33
import jgo
4-
import re
54
import os
65
import pathlib
76
import unittest
@@ -33,6 +32,7 @@ def resolve_managed(endpoint, cache_dir, m2_repo):
3332
repositories=REPOSITORIES,
3433
)
3534

35+
3636
def find_jar_matching(jars, pattern):
3737
for jar in jars:
3838
lastindex = jar.rindex(os.sep)
@@ -51,13 +51,13 @@ def test_resolve_managed(self):
5151
)
5252
jars = glob.glob(os.path.join(workspace, "*jar"))
5353
self.assertEqual(len(jars), 4, "Expected four jars in workspace")
54-
sj_common_jar = find_jar_matching(jars, 'scijava-common')
54+
sj_common_jar = find_jar_matching(jars, "scijava-common")
5555
self.assertEqual(
5656
sj_common_jar,
5757
os.path.join(workspace, "scijava-common-%s.jar" % SJC_VERSION),
5858
"Expected scijava-common jar",
5959
)
60-
sj_optional_jar = find_jar_matching(jars, 'scijava-optional')
60+
sj_optional_jar = find_jar_matching(jars, "scijava-optional")
6161
self.assertEqual(
6262
sj_optional_jar,
6363
os.path.join(
@@ -66,8 +66,13 @@ def test_resolve_managed(self):
6666
"Expected scijava-optional jar",
6767
)
6868

69-
pom = (
70-
os.path.join(tmp_dir, 'org.scijava', 'scijava-common', SJC_VERSION, 'd9deda31e3772a497c66ee3593296f33e918cda69b376c33039ba181dab14db4', 'pom.xml')
69+
pom = os.path.join(
70+
tmp_dir,
71+
"org.scijava",
72+
"scijava-common",
73+
SJC_VERSION,
74+
"d9deda31e3772a497c66ee3593296f33e918cda69b376c33039ba181dab14db4",
75+
"pom.xml",
7176
)
7277
with open(pom) as f:
7378
if "RELEASE" in f.read():
@@ -81,7 +86,7 @@ def test_managed_primary(self):
8186
tmp_dir = tempfile.mkdtemp(prefix="jgo-test-cache-dir")
8287
m2_repo = os.path.join(str(pathlib.Path.home()), ".m2", "repository")
8388
try:
84-
with self.assertRaises(InvalidEndpoint) as context:
89+
with self.assertRaises(InvalidEndpoint):
8590
resolve_managed(
8691
MANAGED_PRIMARY_ENDPOINT, cache_dir=tmp_dir, m2_repo=m2_repo
8792
)

tests/test_parsington.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import glob
2-
import io
32
import jgo
43
import os
54
import pathlib

tox.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[tox]
22
envlist =
3+
py3{6,7,8,9,10}
34
lint
45

56
[testenv:lint]
@@ -8,3 +9,7 @@ deps =
89
skip_install = true
910
commands = black jgo/ tests/ setup.py
1011
description = Run black to reformat all code
12+
13+
[testenv]
14+
deps = pytest
15+
commands = pytest {posargs}

0 commit comments

Comments
 (0)
0