Skip to content

Commit

Permalink
Eliminated the usage of astropy logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kr-2003 committed Feb 11, 2024
1 parent 9ea0f8d commit 004f1ae
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 51 deletions.
1 change: 1 addition & 0 deletions docs/changes/799.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Eliminated the usage of astropy logging
70 changes: 29 additions & 41 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@
try:
from sphinx_astropy.conf.v1 import * # noqa
except ImportError:
print(
'ERROR: the documentation requires the sphinx-astropy package to be installed'
)
print("ERROR: the documentation requires the sphinx-astropy package to be installed")
sys.exit(1)

# Get configuration information from setup.cfg
conf = ConfigParser()

conf.read([os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')])
setup_cfg = dict(conf.items('metadata'))
conf.read([os.path.join(os.path.dirname(__file__), "..", "setup.cfg")])
setup_cfg = dict(conf.items("metadata"))

# -- General configuration ----------------------------------------------------

Expand All @@ -59,10 +57,7 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns += ['_templates',
'notebooks/README.rst',
'notebooks/Debug',
'changes']
exclude_patterns += ["_templates", "notebooks/README.rst", "notebooks/Debug", "changes"]

# This is added to the end of RST files - a good place to put substitutions to
# be used globally.
Expand All @@ -72,20 +67,19 @@
# -- Project information ------------------------------------------------------

# This does not *have* to match the package name, but typically does
project = setup_cfg['name']
author = setup_cfg['author']
copyright = '{0}, {1}'.format(datetime.datetime.now().year,
setup_cfg['author'])
project = setup_cfg["name"]
author = setup_cfg["author"]
copyright = "{0}, {1}".format(datetime.datetime.now().year, setup_cfg["author"])

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.

import_module(setup_cfg['name'])
package = sys.modules[setup_cfg['name']]
import_module(setup_cfg["name"])
package = sys.modules[setup_cfg["name"]]

# The short X.Y version.
version = package.__version__.split('-', 1)[0]
version = package.__version__.split("-", 1)[0]
# The full version, including alpha/beta/rc tags.
release = package.__version__

Expand All @@ -110,15 +104,17 @@
html_css_files = ["css/custom.css"]

html_theme_options = {
'logotext1': 'Sting', # white, semi-bold
'logotext2': 'ray', # orange, light
'logotext3': ':docs' # white, light
"logotext1": "Sting", # white, semi-bold
"logotext2": "ray", # orange, light
"logotext3": ":docs", # white, light
}

extensions += [
'matplotlib.sphinxext.plot_directive', 'sphinx.ext.autodoc',
'sphinx.ext.napoleon', 'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting'
"matplotlib.sphinxext.plot_directive",
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"nbsphinx",
"IPython.sphinxext.ipython_console_highlighting",
]

# Custom sidebar templates, maps document names to template names.
Expand All @@ -139,47 +135,43 @@

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
html_title = '{0} v{1}'.format(project, release)
html_title = "{0} v{1}".format(project, release)

# Output file base name for HTML help builder.
htmlhelp_basename = project + 'doc'
htmlhelp_basename = project + "doc"

# -- Options for LaTeX output -------------------------------------------------

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [('index', project + '.tex', project + u' Documentation',
author, 'manual')]
latex_documents = [("index", project + ".tex", project + " Documentation", author, "manual")]

# -- Options for manual page output -------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [('index', project.lower(), project + u' Documentation', [author],
1)]
man_pages = [("index", project.lower(), project + " Documentation", [author], 1)]

# Trust the links from doi.org, even if they might have Client errors or other minor issues
linkcheck_ignore = [r"https://doi.org/"]

# -- Options for the edit_on_github extension ---------------------------------

if setup_cfg.get('edit_on_github').lower() == 'true':
if setup_cfg.get("edit_on_github").lower() == "true":
extensions += ["sphinx_astropy.ext.edit_on_github"]

extensions += ['sphinx_astropy.ext.edit_on_github']

edit_on_github_project = setup_cfg['github_project']
edit_on_github_project = setup_cfg["github_project"]
edit_on_github_branch = "master"

edit_on_github_source_root = ""
edit_on_github_doc_root = "docs"

# -- Resolving issue number to links in changelog -----------------------------
github_issues_url = 'https://github.com/{0}/issues/'.format(
setup_cfg['github_project'])
github_issues_url = "https://github.com/{0}/issues/".format(setup_cfg["github_project"])

# -- Configuration for nbsphinx -----------------------------------------------
# disable notebook execution
nbsphinx_execute = 'never'
nbsphinx_execute = "never"

# -- Generate DOI listing from Zenodo -----------------------------------------
import json
Expand Down Expand Up @@ -207,18 +199,14 @@ def zenodo_url(self):

@property
def github_url(self):
return (
f"https://github.com/StingraySoftware/stingray/releases/tag/{self.version}"
)
return f"https://github.com/StingraySoftware/stingray/releases/tag/{self.version}"

@property
def bibtex_url(self):
return self.zenodo_url + "/export/hx"


params = urllib.parse.urlencode(
{"q": f'conceptdoi: "{CONCEPT_DOI}"', "all_versions": 1}
)
params = urllib.parse.urlencode({"q": f'conceptdoi: "{CONCEPT_DOI}"', "all_versions": 1})
try:
with urllib.request.urlopen(ZENODO_API_ENDPOINT + "?" + params) as url:
data = json.loads(url.read().decode("utf-8"))
Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
http://docs.astropy.org/en/latest/development/testguide.html#running-tests
"""

if 'test' in sys.argv:
if "test" in sys.argv:
print(TEST_HELP)
sys.exit(1)

Expand All @@ -58,7 +58,7 @@
http://docs.astropy.org/en/latest/install.html#builddocs
"""

if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv:
if "build_docs" in sys.argv or "build_sphinx" in sys.argv:
print(DOCS_HELP)
sys.exit(1)

Expand All @@ -75,6 +75,7 @@

setup(
use_scm_version={
'write_to': os.path.join('stingray', 'version.py'),
'write_to_template': VERSION_TEMPLATE
})
"write_to": os.path.join("stingray", "version.py"),
"write_to_template": VERSION_TEMPLATE,
}
)
1 change: 1 addition & 0 deletions stingray/deadtime/fad.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

logger = setup_logger()


def FAD(
data1,
data2,
Expand Down
1 change: 1 addition & 0 deletions stingray/deadtime/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

logger = setup_logger()


def r_in(td, r_0):
"""Calculate incident countrate given dead time and detected countrate."""
tau = 1 / r_0
Expand Down
1 change: 1 addition & 0 deletions stingray/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

logger = setup_logger()


class Window1D(object):
"""
Make a top hat filter (window function) for power spectrum or cross
Expand Down
9 changes: 4 additions & 5 deletions stingray/loggingconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

logger = None

class CustomFormatter(logging.Formatter):

class CustomFormatter(logging.Formatter):
grey = "\x1b[38;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
Expand All @@ -16,7 +16,7 @@ class CustomFormatter(logging.Formatter):
logging.INFO: grey + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
logging.CRITICAL: bold_red + format + reset,
}

def format(self, record):
Expand All @@ -27,7 +27,7 @@ def format(self, record):

def setup_logger():
global logger

if not logger:
logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
Expand All @@ -36,5 +36,4 @@ def setup_logger():
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)


return logger
return logger

0 comments on commit 004f1ae

Please sign in to comment.