Skip to content

Commit

Permalink
Change setup.cfg to pyproject.toml (#2694)
Browse files Browse the repository at this point in the history
* Shifting metadata from setup.cfg to pyproject.toml

* updating metadata in pyproject.toml file

* Updating project and urls section

* Add dependencies

* Add package data

* Add pytest tools and console scripts

* Renaming metadata to project

* Fixing duplicate keys error

* Add edit_on_github as custom config under tools section

* Fixign astropy-header pytest error

* removing scripts

* Removing setup.cfg

* Fix formatting

* Fixing KeyError: 'setuptools_scm'

* Rearranging the sections as per astropy's pyproject.toml

* Remove reading config.cfg file in conf.py in docs dir

* Removing astropy header

* removing doctest plus

* Removing comments and using consistent double quotes
  • Loading branch information
KasukabeDefenceForce authored Jul 10, 2024
1 parent 467decd commit 26cd336
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 109 deletions.
33 changes: 17 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import datetime
import tardis # FIXME: this import is required by astropy.constants
from importlib import import_module
import toml
from pathlib import Path

try:
from sphinx_astropy.conf.v1 import * # noqa
Expand All @@ -39,13 +41,15 @@
)
sys.exit(1)

# Get configuration information from setup.cfg
from configparser import ConfigParser
#Get configuration information from pyproject.toml
toml_conf_path = Path(__file__).parent.parent / "pyproject.toml"

conf = ConfigParser()

conf.read([os.path.join(os.path.dirname(__file__), "..", "setup.cfg")])
setup_cfg = dict(conf.items("metadata"))
with open(toml_conf_path, 'r') as f_toml:
toml_config = toml.load(f_toml)
toml_config_project_dict = toml_config["project"]
toml_config_tool_dict = toml_config['tool']
for k,v in toml_config_project_dict.items():
print(k,v)

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

Expand Down Expand Up @@ -182,16 +186,16 @@
# -- Project information ------------------------------------------------------

# This does not *have* to match the package name, but typically does
project = setup_cfg["name"]
author = setup_cfg["author"]
project = toml_config_project_dict["name"]
author = toml_config_project_dict["authors"][0]["name"]
copyright = "2013-{0}, {1}".format(datetime.datetime.now().year, 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(toml_config_project_dict["name"])
package = sys.modules[toml_config_project_dict["name"]]

# The short X.Y version.
version = "latest" # package.__version__.split("-", 1)[0]
Expand Down Expand Up @@ -277,21 +281,18 @@

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

if setup_cfg.get("edit_on_github").lower() == "true":
if toml_config_tool_dict["tardis"]['edit_on_github'] == True:

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

edit_on_github_project = setup_cfg["github_project"]
edit_on_github_project = toml_config_project_dict["github_project"]
edit_on_github_branch = "main"

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 = toml_config_project_dict['urls']['Issues']

# -- Options for linkcheck output -------------------------------------------
linkcheck_retry = 5
Expand Down
56 changes: 54 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
[project]
name = "tardis"
authors = [{ name = "TARDIS Collaboration", email = "[email protected]" }]
license = { text = "BSD-3-Clause" }
classifiers = ["License :: OSI Approved :: BSD License"]
description = "TARDIS - Temperature And Radiative Diffusion In Supernovae"
readme = { file = "README.rst", content-type = "text/x-rst" }
requires-python = ">=3.7"
dependencies = ["astropy"]
dynamic = ["version"]

[project.optional-dependencies]
test = ["pytest-astropy"]
docs = ["sphinx-astropy"]

[project.scripts]
cmfgen2tardis = "tardis.scripts.cmfgen2tardis:main"

[project.urls]
Homepage = "https://tardis-sn.github.io/"
Documentation = "https://tardis-sn.github.io/tardis/"
Repository = "https://github.com/tardis-sn/tardis"
Issues = "https://github.com/tardis-sn/tardis/issues/"
Changelog = "https://tardis-sn.github.io/tardis/contributing/CHANGELOG.html"

[build-system]
requires = ["setuptools",
"setuptools_scm",
"wheel"]
build-backend = 'setuptools.build_meta'
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 80
target-version = ['py36']
target-version = ["py36"]
exclude = '''
(
/(
Expand Down Expand Up @@ -137,3 +162,30 @@ known-first-party = ["tardis", "carsus", "stardis"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.setuptools]
packages = ["tardis"]
license-files = ["LICENSE.rst", "licenses/*.rst"]

[tool.setuptools.package-data]
tardis = ["data/*"]
tardis_grid = ["tests/data/*", "./"]
tardis_io = [
"configuration/schemas/*",
"configuration/tests/data/*",
"model/readers/tests/data/*"
]
tardis_model_tests = ["data/*"]
tardis_montecarlo_tests = ["data/*"]
tardis_plasma_tests = ["data/*"]
tardis_scripts = ["debug/*"]
tardis_tests_integration_tests = ["**/*"]
tardis_visualization = ["tools/tests/data/*"]

[tool.pytest.ini_options]
testpaths = ["tardis"]
astropy_header = true
text_file_format = "rst"

[tool.tardis]
edit_on_github = false
91 changes: 0 additions & 91 deletions setup.cfg

This file was deleted.

0 comments on commit 26cd336

Please sign in to comment.