Skip to content

Commit

Permalink
fix pip install (#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
epassaro authored Jul 12, 2021
1 parent d1b0a27 commit 60cd602
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},)
45 changes: 22 additions & 23 deletions tardis/scripts/tardis.py → tardis/scripts/tardis
Original file line number Diff line number Diff line change
@@ -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 = """
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 60cd602

Please sign in to comment.