From 60cd602fe65b1fb284219655b86f509c29cebf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 12 Jul 2021 17:05:08 -0300 Subject: [PATCH] fix pip install (#1686) --- setup.cfg | 1 - setup.py | 8 +++-- tardis/scripts/{tardis.py => tardis} | 45 ++++++++++++++-------------- 3 files changed, 28 insertions(+), 26 deletions(-) rename tardis/scripts/{tardis.py => tardis} (96%) diff --git a/setup.cfg b/setup.cfg index a5777392b12..b8374d460e5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,6 +74,5 @@ exclude_lines = [options.entry_points] console_scripts = - tardis = tardis.scripts.tardis cmfgen2tardis = tardis.scripts.cmfgen2tardis:main tardis_test_runner = tardis.tests.integration_tests.runner:run_tests diff --git a/setup.py b/setup.py index f6273397008..dd5a522af29 100755 --- a/setup.py +++ b/setup.py @@ -74,6 +74,10 @@ version = '{version}' """.lstrip() -setup(use_scm_version={'write_to': os.path.join('tardis', 'version.py'), +# Pure Python scripts that are not entry points, required for `pip install`. +scripts = ['tardis/scripts/tardis'] + +setup(scripts=scripts, + use_scm_version={'write_to': os.path.join('tardis', 'version.py'), 'write_to_template': VERSION_TEMPLATE, - 'version_scheme': 'calver-by-date'}) + 'version_scheme': 'calver-by-date'},) diff --git a/tardis/scripts/tardis.py b/tardis/scripts/tardis similarity index 96% rename from tardis/scripts/tardis.py rename to tardis/scripts/tardis index 813dab9c8bc..8abf78ad82b 100755 --- a/tardis/scripts/tardis.py +++ b/tardis/scripts/tardis @@ -1,13 +1,25 @@ #!/usr/bin/env python -from tardis.io import config_reader -from tardis.simulation import Simulation +import warnings +import argparse +import logging import numpy as np +from tardis.io import config_reader +from tardis.simulation import Simulation -import logging -import argparse -import warnings +def get_virtual_spectrum(): + # Catch warning when acessing invalid spectrum_virtual + with warnings.catch_warnings(record=True) as w: + spectrum = simulation.runner.spectrum_virtual + + if len(w) > 0 and w[-1]._category_name == "UserWarning": + warnings.warn( + "Virtual spectrum is not available, using the " + "real packet spectrum instead." + ) + spectrum = simulation.runner.spectrum + return spectrum tardis_description = """ @@ -80,44 +92,31 @@ tardis_config = config_reader.Configuration.from_yaml(args.config_fname) simulation = Simulation.from_config(tardis_config) - -def get_virtual_spectrum(): - # Catch warning when acessing invalid spectrum_virtual - with warnings.catch_warnings(record=True) as w: - spectrum = simulation.runner.spectrum_virtual - - if len(w) > 0 and w[-1]._category_name == "UserWarning": - warnings.warn( - "Virtual spectrum is not available, using the " - "real packet spectrum instead." - ) - spectrum = simulation.runner.spectrum - return spectrum - - print("Saving the {} spectrum.".format(tardis_config.spectrum.method)) -# Believe it or not, that is a fancy switch-case statement -# We need functions so that only one spectrum is accessed so we can catch +# Believe it or not, that is a fancy switch-case statement. We need +# functions so that only one spectrum is accessed so we can catch # the warning properly + get_spectrum = { "real": lambda: simulation.runner.spectrum, "virtual": get_virtual_spectrum, "integrated": lambda: simulation.runner.spectrum_integrated, }[tardis_config.spectrum.method] - if args.gdb: import os print(os.getpid()) raw_input() # Workaround to attach gdb + if args.profile: import cProfile cProfile.runctx( "simulation.run()", locals(), globals(), filename=args.profiler_log_file ) + else: simulation.run()