Skip to content

Commit 65f1b89

Browse files
committed
wip: dependencies cleanup
1 parent 7d372fd commit 65f1b89

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ You can make sure that dependencies are configured correctly by running:
265265
266266
python3 -m open_fortran_parser --deps
267267
268+
If the depenencies changed since you first ran the wrapper from the source tree, you can cleanup
269+
outdated dependencies by executing:
270+
271+
.. code:: bash
272+
273+
python3 -m open_fortran_parser --cleanup-deps
274+
268275
269276
as script
270277
~~~~~~~~~

open_fortran_parser/dependencies.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
pathlib.Path('antlr-3.3-complete.jar')),
2626
'Open Fortran Parser 0.8.4-2': (
2727
urllib.parse.urlparse(
28-
'https://github.com/mbdevpl/open-fortran-parser/releases/download/v0.8.4-2/'),
29-
pathlib.Path('OpenFortranParser-0.8.4-2.jar')),
28+
# 'https://github.com/mbdevpl/open-fortran-parser/releases/download/v0.8.4-2/'),
29+
'https://dl.bintray.com/mbdevpl/pkgs/open-fortran-parser-v0.8.5.dev4+8f933cfc/linux-openjdk7/'),
30+
pathlib.Path('OpenFortranParser-0.8.4-3.jar')),
3031
'Apache Commons CLI 1.4': (
3132
urllib.parse.urlparse(
3233
'https://github.com/mbdevpl/open-fortran-parser-xml/releases/download/v0.1.0/'),
@@ -45,9 +46,6 @@
4546

4647
DEPENDENCIES_PATH = pathlib.Path(__file__).resolve().parent
4748

48-
OUTDATED_DEPENDENCIES = {
49-
'Open Fortran Parser 0.8.4-1': pathlib.Path('OpenFortranParser-0.8.4-2.jar')}
50-
5149

5250
def ensure_dependencies(
5351
dependencies: t.Mapping[str, t.Tuple[urllib.parse.ParseResult, pathlib.Path]],
@@ -73,5 +71,27 @@ def ensure_dependencies(
7371
if platform.system() != 'Windows':
7472
_LOG.warning('export CLASSPATH="${CLASSPATH}:%s"', classpath)
7573

76-
if __name__ == '__main__':
77-
ensure_dependencies(DEPENDENCIES, DEPENDENCIES_PATH)
74+
75+
OUTDATED_DEPENDENCIES = {
76+
'Open Fortran Parser 0.8.4-1': pathlib.Path('OpenFortranParser-0.8.4-1.jar'),
77+
'Open Fortran Parser 0.8.4-2': pathlib.Path('OpenFortranParser-0.8.4-2.jar')}
78+
79+
80+
def cleanup_old_dependencies(
81+
outdated_dependencies, current_dir: pathlib.Path,
82+
backup_dir: t.Optional[pathlib.Path] = None):
83+
if backup_dir is not None and not backup_dir.exists():
84+
_LOG.warning('Creating directory "%s"...', backup_dir)
85+
os.makedirs(str(backup_dir), exist_ok=True)
86+
for dependency, filename in outdated_dependencies.items():
87+
path = current_dir.joinpath(filename)
88+
if not path.is_file():
89+
_LOG.debug('%s already does not exist.', dependency)
90+
continue
91+
if backup_dir is None:
92+
_LOG.warning('Deleting %s in path "%s"...', dependency, current_dir)
93+
path.unlink()
94+
else:
95+
_LOG.warning('Moving %s from path "%s" to path "%s"...',
96+
dependency, current_dir, backup_dir)
97+
path.move()

open_fortran_parser/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from ._version import VERSION
99
from .parser_wrapper import execute_parser
1010
from .dependencies import \
11-
DEV_DEPENDENCIES, DEV_DEPENDENCIES_PATH, DEPENDENCIES, DEPENDENCIES_PATH, ensure_dependencies
11+
DEV_DEPENDENCIES, DEV_DEPENDENCIES_PATH, DEPENDENCIES, DEPENDENCIES_PATH, ensure_dependencies, \
12+
OUTDATED_DEPENDENCIES, cleanup_old_dependencies
1213

1314
logging.basicConfig()
1415

@@ -40,6 +41,9 @@ def main(args=None, namespace=None):
4041
parser.add_argument(
4142
'--get-development-dependencies', '--dev-deps', action='store_true',
4243
help=argparse.SUPPRESS)
44+
parser.add_argument(
45+
'--cleanup-dependencies', '--cleanup-deps', action='store_true',
46+
help=argparse.SUPPRESS)
4347

4448
args = parser.parse_args(args, namespace)
4549

@@ -51,6 +55,9 @@ def main(args=None, namespace=None):
5155
ensure_dependencies(DEPENDENCIES, DEPENDENCIES_PATH)
5256
return
5357

58+
if args.cleanup_dependencies:
59+
cleanup_old_dependencies(OUTDATED_DEPENDENCIES, DEPENDENCIES_PATH)
60+
5461
if not args.input:
5562
parser.print_help(sys.stderr)
5663
parser.exit(2)

0 commit comments

Comments
 (0)