Skip to content

Commit

Permalink
FIX: do not convert to pyproject.toml in Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 3, 2023
1 parent 362fd29 commit 55261c8
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 135 deletions.
109 changes: 2 additions & 107 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,115 +1,10 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=58.0",
"setuptools>=36.2.1", # environment markers
"setuptools_scm",
"wheel",
]

[project]
authors = [
{name = "Common Partial Wave Analysis", email = "[email protected]"},
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
"Typing :: Typed",
]
dependencies = [
"PyYAML",
"attrs >=20.1.0", # https://www.attrs.org/en/stable/changelog.html#id82
"html2text",
"ini2toml",
"nbformat",
"pip-tools",
"pre-commit",
"ruamel.yaml", # better YAML dumping
"tomlkit",
]
description = "Pre-commit hooks that ensure that ComPWA repositories have a similar developer set-up"
dynamic = ["version"]
license = {text = "BSD 3-Clause License"}
maintainers = [{email = "[email protected]"}]
name = "repo-maintenance"
requires-python = ">=3.6"

[project.optional-dependencies]
dev = [
"labels",
"repo-maintenance[sty]",
"repo-maintenance[test]",
"tox >=1.9", # for skip_install, use_develop
]
format = [
"black",
]
lint = [
"radon",
"repo-maintenance[mypy]",
'ruff; python_version >="3.7.0"',
]
mypy = [
"mypy",
"types-PyYAML",
"types-setuptools",
"types-toml",
]
sty = [
"pre-commit >=1.4.0",
"repo-maintenance[format]",
"repo-maintenance[lint]",
"repo-maintenance[test]", # for pytest type hints
]
test = [
"pytest",
"pytest-cov",
"pytest-xdist",
]

[project.readme]
content-type = "text/markdown"
file = "README.md"

[project.scripts]
check-dev-files = "repoma.check_dev_files:main"
colab-toc-visible = "repoma.colab_toc_visible:main"
fix-nbformat-version = "repoma.fix_nbformat_version:main"
format-setup-cfg = "repoma.format_setup_cfg:main"
pin-nb-requirements = "repoma.pin_nb_requirements:main"
repoma-self-check = "repoma.self_check:main"
set-nb-cells = "repoma.set_nb_cells:main"

[project.urls]
Source = "https://github.com/ComPWA/repo-maintenance"
Tracker = "https://github.com/ComPWA/repo-maintenance/issues"

[tool.setuptools]
include-package-data = false
license-files = ["LICENSE"]
package-dir = {"" = "src"}

[tool.setuptools.package-data]
repoma = [
".github/*",
".github/**/*",
".template/*",
".template/.*",
"py.typed",
]

[tool.setuptools.packages.find]
namespaces = false
where = ["src"]

[tool.setuptools_scm]
write_to = "src/repoma/version.py"

Expand Down
93 changes: 93 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[metadata]
name = repo-maintenance
author = Common Partial Wave Analysis
author_email = [email protected]
maintainer_email = [email protected]
description = Pre-commit hooks that ensure that ComPWA repositories have a similar developer set-up
long_description = file: README.md
long_description_content_type = text/markdown
project_urls =
Tracker = https://github.com/ComPWA/repo-maintenance/issues
Source = https://github.com/ComPWA/repo-maintenance
license = BSD 3-Clause License
license_files = LICENSE
classifiers =
Development Status :: 3 - Alpha
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Typing :: Typed

[options]
python_requires = >=3.6
setup_requires =
setuptools_scm
install_requires =
attrs >=20.1.0 # https://www.attrs.org/en/stable/changelog.html#id82
html2text
ini2toml
nbformat
pip-tools
pre-commit
PyYAML
ruamel.yaml # better YAML dumping
tomlkit
packages = find:
package_dir =
=src

[options.extras_require]
test =
pytest
pytest-cov
pytest-xdist
format =
black
mypy =
mypy
types-PyYAML
types-setuptools
types-toml
lint =
%(mypy)s
radon
ruff; python_version >="3.7.0"
sty =
%(format)s
%(lint)s
%(test)s # for pytest type hints
pre-commit >=1.4.0
dev =
%(sty)s
%(test)s
labels
tox >=1.9 # for skip_install, use_develop

[options.entry_points]
console_scripts =
check-dev-files = repoma.check_dev_files:main
colab-toc-visible = repoma.colab_toc_visible:main
fix-nbformat-version = repoma.fix_nbformat_version:main
format-setup-cfg = repoma.format_setup_cfg:main
pin-nb-requirements = repoma.pin_nb_requirements:main
repoma-self-check = repoma.self_check:main
set-nb-cells = repoma.set_nb_cells:main

[options.packages.find]
where = src

[options.package_data]
repoma =
.github/*
.github/**/*
.template/*
.template/.*
py.typed
22 changes: 22 additions & 0 deletions src/repoma/check_dev_files/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from repoma.utilities import CONFIG_PATH
from repoma.utilities.executor import Executor
from repoma.utilities.precommit import remove_precommit_hook
from repoma.utilities.project_info import open_setup_cfg
from repoma.utilities.pyproject import load_pyproject, write_pyproject
from repoma.utilities.readme import remove_badge
from repoma.utilities.vscode import (
Expand Down Expand Up @@ -149,6 +150,27 @@ def __remove_file(path: str) -> None:


def __uninstall(package: str) -> None:
__uninstall_from_setup_cfg(package)
__uninstall_from_pyproject_toml(package)

Check warning on line 154 in src/repoma/check_dev_files/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/deprecated.py#L153-L154

Added lines #L153 - L154 were not covered by tests


def __uninstall_from_setup_cfg(package: str) -> None:
if not os.path.exists(CONFIG_PATH.setup_cfg):
return
cfg = open_setup_cfg()
section = "options.extras_require"
if not cfg.has_section(section):
return
for option in cfg[section]:
if not cfg.has_option(section, option):
continue
if package not in cfg.get(section, option):
continue
msg = f'Please remove {package} from the "{section}" section of setup.cfg'
raise PrecommitError(msg)


def __uninstall_from_pyproject_toml(package: str) -> None:
if not os.path.exists(CONFIG_PATH.pyproject):
return
pyproject = load_pyproject()
Expand Down
48 changes: 46 additions & 2 deletions src/repoma/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import os
from copy import deepcopy
from textwrap import dedent
from typing import List, Set

from ruamel.yaml.comments import CommentedMap
from tomlkit.items import Array, Table

from repoma.check_dev_files.setup_cfg import (
has_pyproject_build_system,
has_setup_cfg_build_system,
)
from repoma.errors import PrecommitError
from repoma.utilities import CONFIG_PATH, natural_sorting
from repoma.utilities.executor import Executor
Expand All @@ -17,6 +22,7 @@
from repoma.utilities.project_info import (
get_project_info,
get_supported_python_versions,
open_setup_cfg,
)
from repoma.utilities.pyproject import (
complies_with_subset,
Expand All @@ -36,18 +42,56 @@ def main() -> None:
add_badge,
"[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)",
)
executor(_check_setup_cfg)
executor(_update_nbqa_settings)
executor(_update_ruff_settings)
executor(_update_ruff_per_file_ignores)
executor(_update_ruff_pydocstyle_settings)
executor(_update_precommit_hook)
executor(_update_precommit_nbqa_hook)
executor(_update_setup_cfg)
executor(_update_pyproject)
executor(_update_vscode_settings)
executor.finalize()


def _update_setup_cfg() -> None:
def _check_setup_cfg() -> None:
if not has_setup_cfg_build_system():
return

Check warning on line 59 in src/repoma/check_dev_files/ruff.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/ruff.py#L59

Added line #L59 was not covered by tests
cfg = open_setup_cfg()
extras_require = "options.extras_require"
if not cfg.has_section(extras_require):
msg = f"Please list ruff under a section [{extras_require}] in setup.cfg"
raise PrecommitError(msg)
msg = f"""\
Section [{extras_require}] in setup.cfg should look like this:
[{extras_require}]
...
lint =
ruff
...
sty =
...
%(lint)s
...
dev =
...
%(sty)s
...
"""
msg = dedent(msg).strip()
for section in ("dev", "lint", "sty"):
if cfg.has_option(extras_require, section):
continue
raise PrecommitError(msg)
lint_section = cfg.get(extras_require, "lint")
if not any("ruff" in line for line in lint_section.split("\n")):
raise PrecommitError(msg)


def _update_pyproject() -> None:
if not has_pyproject_build_system():
return
pyproject = load_pyproject()
project_info = get_project_info(pyproject)
package = project_info.name

Check warning on line 97 in src/repoma/check_dev_files/ruff.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/ruff.py#L94-L97

Added lines #L94 - L97 were not covered by tests
Expand Down
Loading

0 comments on commit 55261c8

Please sign in to comment.