Skip to content

Commit b2c0932

Browse files
committed
Merge branch 'dependencies'
2 parents 0fa2e6e + 3536740 commit b2c0932

File tree

8 files changed

+77
-47
lines changed

8 files changed

+77
-47
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,10 @@ install:
8181
- pip install -U pip
8282
- pip install -U -r dev_requirements.txt
8383
# Java
84-
- python -m open_fortran_parser --dev-deps
84+
- python -m open_fortran_parser --deps
8585
- export CLASSPATH="${CLASSPATH}:$(pwd)/lib/*"
8686
- ant -Dpython=python
8787
- export CLASSPATH="${CLASSPATH}:$(pwd)/dist/*"
88-
# Java tests
89-
- wget "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.8.3/org.jacoco.agent-0.8.3-runtime.jar" -O "lib/org.jacoco.agent-0.8.3-runtime.jar"
90-
- wget "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.cli/0.8.3/org.jacoco.cli-0.8.3-nodeps.jar" -O "lib/org.jacoco.cli-0.8.3-nodeps.jar"
9188

9289
script:
9390
- |

README.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ Get dependencies, either manually, or using the provided script:
455455
.. code:: bash
456456
457457
pip3 install -U -r requirements.txt
458-
python3 -m open_fortran_parser --dev-deps
458+
python3 -m open_fortran_parser --deps
459459
export CLASSPATH="${CLASSPATH}:$(pwd)/lib/*"
460460
461461
Build:
@@ -580,7 +580,7 @@ You can make sure that dependencies are configured correctly by running:
580580

581581
.. code:: bash
582582
583-
python3 -m open_fortran_parser --deps
583+
python3 -m open_fortran_parser --check-deps
584584
585585
If the depenencies changed since you first ran the wrapper from the source tree, you can cleanup
586586
outdated dependencies by executing:
@@ -597,7 +597,7 @@ as script
597597
598598
$ python3 -m open_fortran_parser -h
599599
usage: open_fortran_parser [-h] [--version] [-v VERBOSITY]
600-
[--get-dependencies]
600+
[--check-dependencies]
601601
[input] [output]
602602
603603
Python wrapper around XML generator for Open Fortran Parser
@@ -612,8 +612,9 @@ as script
612612
--version show program's version number and exit
613613
-v VERBOSITY, --verbosity VERBOSITY
614614
level of verbosity, from 0 to 100 (default: 100)
615-
--get-dependencies, --deps
616-
download dependencies and exit (default: False)
615+
--check-dependencies, --check-deps
616+
check if all required dependencies are present and
617+
exit (default: False)
617618
618619
Copyright 2017-2019 by the contributors, Apache License 2.0,
619620
https://github.com/mbdevpl/open-fortran-parser-xml
@@ -645,16 +646,15 @@ Run basic tests:
645646
code coverage
646647
~~~~~~~~~~~~~
647648

648-
Getting code coverage results for Java requires JaCoCo agent, and JaCoCo CLI.
649+
Getting code coverage results for Java requires JaCoCo agent, and JaCoCo CLI,
650+
and both are dowonloaded automatically along with other development dependencies.
649651

650-
Set up code coverage for Java:
651-
652-
.. code:: bash
652+
Currently, test setup relies on JaCoCo 0.8.3:
653653

654-
wget "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.8.3/org.jacoco.agent-0.8.3-runtime.jar" -O "lib/org.jacoco.agent-0.8.3-runtime.jar"
655-
wget "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.cli/0.8.3/org.jacoco.cli-0.8.3-nodeps.jar" -O "lib/org.jacoco.cli-0.8.3-nodeps.jar"
654+
* JaCoCo agent 0.8.3 (runtime)
655+
* JaCoCo CLI 0.8.3 (nodeps)
656656

657-
Then, run all test and gather code coverage:
657+
Run all test and gather code coverage:
658658

659659
.. code:: bash
660660

appveyor.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,10 @@ install:
8888
- python -m pip install -U pip
8989
- python -m pip install -U -r dev_requirements.txt
9090
# Java
91-
- python -m open_fortran_parser --dev-deps
91+
- python -m open_fortran_parser --deps
9292
- set CLASSPATH=%cd%\\lib\\*;%CLASSPATH%
9393
- ant -Dpython=python
9494
- set CLASSPATH=%cd%\\dist\\*;%CLASSPATH%
95-
# Java tests
96-
- ps: Invoke-WebRequest "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.8.3/org.jacoco.agent-0.8.3-runtime.jar" -OutFile "lib\\org.jacoco.agent-0.8.3-runtime.jar"
97-
- ps: Invoke-WebRequest "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.cli/0.8.3/org.jacoco.cli-0.8.3-nodeps.jar" -OutFile "lib\\org.jacoco.cli-0.8.3-nodeps.jar"
9895

9996
build: off
10097

open_fortran_parser/config.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
from ._version import VERSION
88

9-
DEV_DEPENDENCIES_PATH = pathlib.Path(os.getcwd(), 'lib')
9+
DEPENDENCIES_PATH = pathlib.Path(__file__).resolve().parent
10+
11+
DEV_DEPENDENCIES_PATH = DEPENDENCIES_PATH.parent.joinpath('lib')
1012

11-
DEV_DEPENDENCIES = {
13+
COMMON_DEPENDENCIES = {
1214
'ANTLR 3.5.2': (
1315
urllib.parse.urlparse(
1416
'https://github.com/mbdevpl/open-fortran-parser/releases/download/v0.8.5-1/'),
@@ -22,9 +24,20 @@
2224
'https://github.com/mbdevpl/open-fortran-parser-xml/releases/download/v0.1.0/'),
2325
pathlib.Path('commons-cli-1.4.jar'))}
2426

25-
DEPENDENCIES_PATH = pathlib.Path(__file__).resolve().parent
27+
DEV_DEPENDENCIES = COMMON_DEPENDENCIES.copy()
28+
29+
DEV_DEPENDENCIES.update({
30+
'JaCoCo agent 0.8.3': (
31+
urllib.parse.urlparse(
32+
'https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.8.3/'),
33+
pathlib.Path('org.jacoco.agent-0.8.3-runtime.jar')),
34+
'JaCoCo CLI 0.8.3': (
35+
urllib.parse.urlparse(
36+
'https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.cli/0.8.3/'),
37+
pathlib.Path('org.jacoco.cli-0.8.3-nodeps.jar')),
38+
})
2639

27-
DEPENDENCIES = DEV_DEPENDENCIES.copy()
40+
DEPENDENCIES = COMMON_DEPENDENCIES.copy()
2841

2942
DEPENDENCIES.update({
3043
'Open Fortran Parser XML {}'.format(VERSION): (

open_fortran_parser/dependencies.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def ensure_dependencies(
2121
os.makedirs(str(target_dir), exist_ok=True)
2222
for dependency, (url_root, filename) in dependencies.items():
2323
path = target_dir.joinpath(filename)
24-
if path.is_file():
24+
if path.is_file() and not silent:
2525
_LOG.warning('%s is present already.', dependency)
2626
continue
2727
if not download:
@@ -32,13 +32,6 @@ def ensure_dependencies(
3232
wget.download(url, str(path), bar=None if silent else wget.bar_adaptive)
3333
if not silent:
3434
print()
35-
if not silent:
36-
classpath = target_dir.joinpath('*')
37-
_LOG.warning('If you wish to use the Open Fortran Parser XML generator directly,'
38-
' please add "%s" to your Java classpath:', classpath)
39-
if platform.system() != 'Windows':
40-
_LOG.warning('export CLASSPATH="${CLASSPATH}:%s"', classpath)
41-
4235

4336
def cleanup_old_dependencies(
4437
outdated_dependencies, current_dir: pathlib.Path,
@@ -57,4 +50,4 @@ def cleanup_old_dependencies(
5750
else:
5851
_LOG.warning('Moving %s from path "%s" to path "%s"...',
5952
dependency, current_dir, backup_dir)
60-
path.move()
53+
path.rename(backup_dir.joinpath(filename))

open_fortran_parser/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ def main(args=None, namespace=None):
3838
'-v', '--verbosity', type=int, default=100, help='''level of verbosity, from 0 to 100''')
3939
parser.add_argument(
4040
'--get-dependencies', '--deps', action='store_true',
41-
help='''download dependencies and exit''')
41+
help=argparse.SUPPRESS) # download dependencies for development and exit
4242
parser.add_argument(
43-
'--get-development-dependencies', '--dev-deps', action='store_true',
44-
help=argparse.SUPPRESS)
43+
'--check-dependencies', '--check-deps', action='store_true',
44+
help='''check if all required dependencies are present and exit''')
4545
parser.add_argument(
4646
'--cleanup-dependencies', '--cleanup-deps', action='store_true',
47-
help=argparse.SUPPRESS)
47+
help=argparse.SUPPRESS) # delete outdated development dependencies and exit
4848

4949
args = parser.parse_args(args, namespace)
5050

51-
if args.get_development_dependencies:
51+
if args.get_dependencies:
5252
ensure_dependencies(DEV_DEPENDENCIES, DEV_DEPENDENCIES_PATH)
5353
return
5454

55-
if args.get_dependencies:
56-
ensure_dependencies(DEPENDENCIES, DEPENDENCIES_PATH)
55+
if args.check_dependencies:
56+
ensure_dependencies(DEPENDENCIES, DEPENDENCIES_PATH, download=False)
5757
return
5858

5959
if args.cleanup_dependencies:

test/test_dependencies.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,45 @@
66
import unittest
77

88
from open_fortran_parser.config import DEV_DEPENDENCIES
9-
from open_fortran_parser.dependencies import ensure_dependencies
9+
from open_fortran_parser.dependencies import ensure_dependencies, cleanup_old_dependencies
10+
11+
EXAMPLE_DEPENDENCY = 'Apache Commons CLI 1.4'
12+
13+
TESTED_DEPENDENCIES = {EXAMPLE_DEPENDENCY: DEV_DEPENDENCIES[EXAMPLE_DEPENDENCY]}
1014

1115

1216
class Tests(unittest.TestCase):
1317

1418
@unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test')
1519
def test_deps(self):
1620
with tempfile.TemporaryDirectory() as temp_dir:
17-
ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=False)
21+
self.assertEqual(len(os.listdir(temp_dir)), 0)
22+
ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), download=False)
23+
self.assertEqual(len(os.listdir(temp_dir)), 0)
24+
ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=False)
1825
self.assertGreater(len(os.listdir(temp_dir)), 0)
26+
ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=False)
1927
with tempfile.TemporaryDirectory() as temp_dir:
2028
os.rmdir(temp_dir)
21-
ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=True)
29+
ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=True)
2230
self.assertGreater(len(os.listdir(temp_dir)), 0)
31+
32+
@unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test')
33+
def test_cleanup_deps(self):
34+
to_clean = {k: v[1] for k, v in TESTED_DEPENDENCIES.items()}
35+
with tempfile.TemporaryDirectory() as temp_dir:
36+
ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=True)
37+
self.assertGreater(len(os.listdir(temp_dir)), 0)
38+
cleanup_old_dependencies(to_clean, pathlib.Path(temp_dir))
39+
self.assertEqual(len(os.listdir(temp_dir)), 0)
40+
cleanup_old_dependencies(to_clean, pathlib.Path(temp_dir))
41+
with tempfile.TemporaryDirectory() as temp_dir:
42+
ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=True)
43+
count = len(os.listdir(temp_dir))
44+
self.assertGreater(count, 0)
45+
with tempfile.TemporaryDirectory() as temp_backup_dir:
46+
os.rmdir(temp_backup_dir)
47+
cleanup_old_dependencies(to_clean, pathlib.Path(temp_dir),
48+
pathlib.Path(temp_backup_dir))
49+
self.assertEqual(len(os.listdir(temp_backup_dir)), count)
50+
self.assertEqual(len(os.listdir(temp_dir)), 0)

test/test_script.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ def test_help(self):
3838
self.assertIn('usage', text)
3939
self.assertIn('open_fortran_parser', text)
4040

41-
@unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test')
42-
def test_deps_flag(self):
41+
def test_check_deps_flag(self):
4342
sio = io.StringIO()
4443
with contextlib.redirect_stderr(sio):
45-
run_module('open_fortran_parser', '--deps')
44+
run_module('open_fortran_parser', '--check-deps')
4645
self.assertGreater(len(sio.getvalue()), 0)
4746
self.assertGreater(len(os.listdir(str(DEPENDENCIES_PATH))), 0)
4847

49-
run_module('open_fortran_parser', '--dev-deps')
48+
@unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test')
49+
def test_development_flags(self):
50+
run_module('open_fortran_parser', '--deps')
51+
run_module('open_fortran_parser', '--cleanup-deps')
5052
self.assertGreater(len(os.listdir(str(DEV_DEPENDENCIES_PATH))), 0)
5153

5254
def test_verbosity_flag(self):

0 commit comments

Comments
 (0)