Skip to content

Commit 8b31071

Browse files
authored
Switch from setup.py to pyproject.toml for configuration (realpython#15)
* Switch from setup.py to pyproject.toml * Switch bumpversion to bumpver * Move to a src/ based structure * Add explicit configuration of isort * Use TOML instead of INI for configuration
1 parent 0387003 commit 8b31071

File tree

11 files changed

+75
-59
lines changed

11 files changed

+75
-59
lines changed

.bumpversion.cfg

Lines changed: 0 additions & 11 deletions
This file was deleted.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include reader/*.cfg
1+
include src/reader/*.cfg

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "realpython-reader"
7+
version = "1.0.0"
8+
description = "Read the latest Real Python tutorials"
9+
readme = "README.md"
10+
authors = [{ name = "Real Python", email = "info@realpython.com" }]
11+
license = { file = "LICENSE" }
12+
classifiers = [
13+
"License :: OSI Approved :: MIT License",
14+
"Programming Language :: Python",
15+
"Programming Language :: Python :: 3",
16+
]
17+
keywords = ["feed", "reader", "tutorial"]
18+
dependencies = ["feedparser", "html2text", 'tomli; python_version < "3.11"']
19+
requires-python = ">=3.7"
20+
21+
[project.optional-dependencies]
22+
build = ["build", "twine"]
23+
dev = ["black", "bumpver", "isort", "mypy", "pytest"]
24+
25+
[project.scripts]
26+
realpython = "reader.__main__:main"
27+
28+
[project.urls]
29+
repository = "https://github.com/realpython/reader"
30+
documentation = "https://realpython.com/pypi-publish-python-package/"
31+
32+
33+
[tool.bumpver]
34+
current_version = "1.0.0"
35+
version_pattern = "MAJOR.MINOR.PATCH"
36+
commit_message = "bump version {old_version} -> {new_version}"
37+
commit = true
38+
tag = true
39+
push = false
40+
41+
[tool.bumpver.file_patterns]
42+
"pyproject.toml" = [
43+
'current_version = "{version}"',
44+
'version = "{version}"',
45+
]
46+
"src/reader/__init__.py" = ["{version}"]
47+
"src/reader/__main__.py" = ["- realpython-reader v{version}"]
48+
49+
[tool.isort]
50+
profile = "black"
51+
import_heading_stdlib = "Standard library imports"
52+
import_heading_thirdparty = "Third party imports"
53+
import_heading_firstparty = "Reader imports"
54+
55+
[tool.mypy]
56+
strict = true
57+
58+
[[tool.mypy.overrides]]
59+
module = "feedparser"
60+
ignore_missing_imports = true

reader/config.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
"""Setup script for realpython-reader"""
2-
3-
# Standard library imports
4-
import pathlib
5-
6-
# Third party imports
71
from setuptools import setup
82

9-
# The directory containing this file
10-
HERE = pathlib.Path(__file__).resolve().parent
11-
12-
# The text of the README file is used as a description
13-
README = (HERE / "README.md").read_text()
14-
15-
# This call to setup() does all the work
16-
setup(
17-
name="realpython-reader",
18-
version="1.0.0",
19-
description="Read the latest Real Python tutorials",
20-
long_description=README,
21-
long_description_content_type="text/markdown",
22-
url="https://github.com/realpython/reader",
23-
author="Real Python",
24-
author_email="info@realpython.com",
25-
license="MIT",
26-
classifiers=[
27-
"License :: OSI Approved :: MIT License",
28-
"Programming Language :: Python",
29-
"Programming Language :: Python :: 3",
30-
],
31-
packages=["reader"],
32-
include_package_data=True,
33-
install_requires=["feedparser", "html2text"],
34-
entry_points={"console_scripts": ["realpython=reader.__main__:main"]},
35-
)
3+
setup()

reader/__init__.py renamed to src/reader/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
99
See https://github.com/realpython/reader/ for more information.
1010
"""
11-
from configparser import ConfigParser
11+
# Standard library imports
1212
from importlib import resources
1313

14+
try:
15+
import tomllib
16+
except ModuleNotFoundError:
17+
# Third party imports
18+
import tomli as tomllib
19+
20+
1421
# Version of realpython-reader package
1522
__version__ = "1.0.0"
1623

17-
# Read URL of feed from config file
18-
cfg = ConfigParser()
19-
with resources.path("reader", "config.cfg") as path:
20-
cfg.read(str(path))
21-
22-
URL = cfg.get("feed", "url")
24+
# Read URL of the Real Python feed from config file
25+
_cfg = tomllib.loads(resources.read_text("reader", "config.toml"))
26+
URL = _cfg["feed"]["url"]
File renamed without changes.

src/reader/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[feed]
2+
url = "https://realpython.com/atom.xml"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)