dataplot 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ # This workflow will upload a Python Package using Twine when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ deploy:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - name: Checkout
24
+ uses: actions/checkout@v3
25
+ with:
26
+ submodules: recursive
27
+ - name: Set up Python
28
+ uses: actions/setup-python@v3
29
+ with:
30
+ python-version: "3.12.7"
31
+ - name: Upgrade pip
32
+ run: python -m pip install --upgrade pip
33
+ - name: Install yaml
34
+ run: python -m pip install pyyaml
35
+ - name: Install build
36
+ run: python -m pip install build
37
+ - name: Install twine
38
+ run: python -m pip install twine
39
+ - name: Install cfgtools
40
+ run: python -m pip install cfgtools
41
+ - name: Install re-extensions
42
+ run: python -m pip install re-extensions
43
+ - name: Build package
44
+ run: python install.py
45
+ - name: Publish package
46
+ run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,160 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
dataplot-0.1.6/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Chitaoji
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: dataplot
3
+ Version: 0.1.6
4
+ Summary: Provides plotting tools useful in datascience.
5
+ Project-URL: Documentation, https://github.com/Chitaoji/dataplot/blob/main/README.md
6
+ Project-URL: Repository, https://github.com/Chitaoji/dataplot/
7
+ Author-email: Chitaoji <2360742040@qq.com>
8
+ Maintainer-email: Chitaoji <2360742040@qq.com>
9
+ License-Expression: BSD-3-Clause
10
+ License-File: LICENSE
11
+ Keywords: plot
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.13
15
+ Requires-Dist: lazyr
16
+ Requires-Dist: matplotlib
17
+ Requires-Dist: numpy
18
+ Requires-Dist: pandas
19
+ Requires-Dist: scipy
20
+ Requires-Dist: seaborn
21
+ Requires-Dist: validating
22
+ Description-Content-Type: text/markdown
23
+
24
+ # dataplot
25
+ Provides plotting tools useful in datascience.
26
+
27
+ ## Installation
28
+ ```sh
29
+ $ pip install dataplot
30
+ ```
31
+
32
+ ## Requirements
33
+ ```txt
34
+ validating
35
+ lazyr
36
+ matplotlib
37
+ numpy
38
+ pandas
39
+ scipy
40
+ seaborn
41
+ ```
42
+
43
+ ## See Also
44
+ ### Github repository
45
+ * https://github.com/Chitaoji/dataplot/
46
+
47
+ ### PyPI project
48
+ * https://pypi.org/project/dataplot/
49
+
50
+ ## License
51
+ This project falls under the BSD 3-Clause License.
52
+
53
+ ## History
54
+ ### v0.1.6
55
+ * New method `PlotDataSet.scatter()` to draw true scatter charts while keeping `PlotDataSet.plot()` as line chart behavior.
56
+ * Improved automatic label inference for `dp.data(...)`, plotting labels, and x-axis labels in interactive contexts.
57
+ * Plot builders now use deferred drawing; removed `dp.show()` and improved axis/figure rendering in object representations.
58
+ * Refined rendering stability with fixes for empty-axis cleanup and figure re-rendering in `FigWrapper.__repr__`.
59
+ * Updated minimum required Python version to >=3.13.
60
+
61
+ ### v0.1.5
62
+ * Fixed issue: unworking figure settings in the artist methods.
63
+
64
+ ### v0.1.4
65
+ * Fixed issue: incorrectly displayed histogram statistics when the x-label had been modified by the user.
66
+
67
+ ### v0.1.3
68
+ * Allowed users to set the plot-settings by kwargs in artist methods like `PlotDataSet.hist()`, `PlotDataSet.plot()`, etc.
69
+ * New operation methods `PlotDataSet.signedpow()` and `PlotDataSet.log10()`.
70
+ * Renamed `PlotDataSet.signlog()` to `.signedlog()`; renamed `PlotDataSet.opclear()` to `.undo_all()`; removed `PlotDataSet.opclear_records_only()`.
71
+ * New optional parameter `format_label=` for `PlotDataSet.set_plot()` to decide whether to format the label when painting on the axes.
72
+ * When defining the data classes, used *dataclasses* instead of *attrs* for a faster import.
73
+
74
+ ### v0.1.2
75
+ * New methods `PlotDataSet.corrmap()`, `PlotDataSet.ppplot()`, and `PlotDataSet.resample()`.
76
+ * New optional parameter `fmt=` for `PlotDataSet.plot()`, `PlotDataSet.qqplot()`, `PlotDataSet.ppplot()`, and `PlotDataSet.ksplot()`.
77
+ * Bugfix.
78
+
79
+ ### v0.1.1
80
+ * New module-level function `dp.show()`.
81
+ * New methods `PlotDataSet.qqplot()`, `PlotDataSet.ksplot()` and `PlotDataSet.abs()`.
82
+ * All the plotting method (e.g., `.hist()`) will now return an `Artist` object instead of None.
83
+ * New plot settings: `grid` and `grid_alpha`.
84
+ * Parameters of `FigWrapper.set_figure()`, `AxesWrapper.set_axes()` and `PlotDataSet.set_plot()` are keyword-only now.
85
+ * The returns of `.set_figure()` and `.set_axes()` will be None (instead of `self`) to avoid misunderstandings.
86
+ * New optional parameter `inplace=` for `PlotDataSet.set_plot()` to decide whether the changes will happen in-place (which is the only option before) or in a new copy.
87
+ * Parameter `ticks=` for `PlotDataSet.plot()` can be set to a `PlotDataSet` object now.
88
+
89
+ ### v0.1.0
90
+ * `PlotDataSet` now supports binary operations including +, -, *, /, and **.
91
+ * New methods `FigWrapper.set_figure()` and `AxesWrapper.set_axes()` - use them instead of `*.set_plot()`.
92
+ * Simplified the usage of `AxesWrapper`.
93
+ * New plot settings: `subplots_adjust=`, `fontdict=` and `dpi=`.
94
+ * After this version, the required Python version is updated to >=3.11.9. Download and install v0.0.2 if the user is under lower Python version (>=3.8.13).
95
+
96
+ ### v0.0.2
97
+ * Updated the meta-data.
98
+
99
+ ### v0.0.1
100
+ * Initial release.
@@ -0,0 +1,77 @@
1
+ # dataplot
2
+ Provides plotting tools useful in datascience.
3
+
4
+ ## Installation
5
+ ```sh
6
+ $ pip install dataplot
7
+ ```
8
+
9
+ ## Requirements
10
+ ```txt
11
+ validating
12
+ lazyr
13
+ matplotlib
14
+ numpy
15
+ pandas
16
+ scipy
17
+ seaborn
18
+ ```
19
+
20
+ ## See Also
21
+ ### Github repository
22
+ * https://github.com/Chitaoji/dataplot/
23
+
24
+ ### PyPI project
25
+ * https://pypi.org/project/dataplot/
26
+
27
+ ## License
28
+ This project falls under the BSD 3-Clause License.
29
+
30
+ ## History
31
+ ### v0.1.6
32
+ * New method `PlotDataSet.scatter()` to draw true scatter charts while keeping `PlotDataSet.plot()` as line chart behavior.
33
+ * Improved automatic label inference for `dp.data(...)`, plotting labels, and x-axis labels in interactive contexts.
34
+ * Plot builders now use deferred drawing; removed `dp.show()` and improved axis/figure rendering in object representations.
35
+ * Refined rendering stability with fixes for empty-axis cleanup and figure re-rendering in `FigWrapper.__repr__`.
36
+ * Updated minimum required Python version to >=3.13.
37
+
38
+ ### v0.1.5
39
+ * Fixed issue: unworking figure settings in the artist methods.
40
+
41
+ ### v0.1.4
42
+ * Fixed issue: incorrectly displayed histogram statistics when the x-label had been modified by the user.
43
+
44
+ ### v0.1.3
45
+ * Allowed users to set the plot-settings by kwargs in artist methods like `PlotDataSet.hist()`, `PlotDataSet.plot()`, etc.
46
+ * New operation methods `PlotDataSet.signedpow()` and `PlotDataSet.log10()`.
47
+ * Renamed `PlotDataSet.signlog()` to `.signedlog()`; renamed `PlotDataSet.opclear()` to `.undo_all()`; removed `PlotDataSet.opclear_records_only()`.
48
+ * New optional parameter `format_label=` for `PlotDataSet.set_plot()` to decide whether to format the label when painting on the axes.
49
+ * When defining the data classes, used *dataclasses* instead of *attrs* for a faster import.
50
+
51
+ ### v0.1.2
52
+ * New methods `PlotDataSet.corrmap()`, `PlotDataSet.ppplot()`, and `PlotDataSet.resample()`.
53
+ * New optional parameter `fmt=` for `PlotDataSet.plot()`, `PlotDataSet.qqplot()`, `PlotDataSet.ppplot()`, and `PlotDataSet.ksplot()`.
54
+ * Bugfix.
55
+
56
+ ### v0.1.1
57
+ * New module-level function `dp.show()`.
58
+ * New methods `PlotDataSet.qqplot()`, `PlotDataSet.ksplot()` and `PlotDataSet.abs()`.
59
+ * All the plotting method (e.g., `.hist()`) will now return an `Artist` object instead of None.
60
+ * New plot settings: `grid` and `grid_alpha`.
61
+ * Parameters of `FigWrapper.set_figure()`, `AxesWrapper.set_axes()` and `PlotDataSet.set_plot()` are keyword-only now.
62
+ * The returns of `.set_figure()` and `.set_axes()` will be None (instead of `self`) to avoid misunderstandings.
63
+ * New optional parameter `inplace=` for `PlotDataSet.set_plot()` to decide whether the changes will happen in-place (which is the only option before) or in a new copy.
64
+ * Parameter `ticks=` for `PlotDataSet.plot()` can be set to a `PlotDataSet` object now.
65
+
66
+ ### v0.1.0
67
+ * `PlotDataSet` now supports binary operations including +, -, *, /, and **.
68
+ * New methods `FigWrapper.set_figure()` and `AxesWrapper.set_axes()` - use them instead of `*.set_plot()`.
69
+ * Simplified the usage of `AxesWrapper`.
70
+ * New plot settings: `subplots_adjust=`, `fontdict=` and `dpi=`.
71
+ * After this version, the required Python version is updated to >=3.11.9. Download and install v0.0.2 if the user is under lower Python version (>=3.8.13).
72
+
73
+ ### v0.0.2
74
+ * Updated the meta-data.
75
+
76
+ ### v0.0.1
77
+ * Initial release.
@@ -0,0 +1,155 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# Managing the working directory.\n",
10
+ "# NOTE: You DON'T want to change this.\n",
11
+ "import sys\n",
12
+ "from pathlib import Path\n",
13
+ "\n",
14
+ "p = Path(\"\").cwd().parent.as_posix()\n",
15
+ "if p not in sys.path:\n",
16
+ " sys.path.append(p)"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": null,
22
+ "metadata": {},
23
+ "outputs": [],
24
+ "source": [
25
+ "try:\n",
26
+ " from ..src import dataplot as dp\n",
27
+ "except ImportError:\n",
28
+ " import src.dataplot as dp"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": null,
34
+ "metadata": {},
35
+ "outputs": [],
36
+ "source": [
37
+ "import numpy as np\n",
38
+ "\n",
39
+ "np.random.seed(42)\n",
40
+ "\n",
41
+ "x1 = dp.data(np.random.randn(1000))\n",
42
+ "x2 = dp.data(np.random.randn(1000))\n",
43
+ "x3 = dp.data(np.random.randn(1000))\n",
44
+ "x4 = dp.data(np.random.randn(1000))\n",
45
+ "x5 = dp.data(np.random.randn(1000))"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "s = x1.join(x1 + x2, x1 + x2 + x3)\n",
55
+ "a0 = s.hist(title=\"Sums of i.i.d Normal Distributions\")\n",
56
+ "a0"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": null,
62
+ "metadata": {},
63
+ "outputs": [],
64
+ "source": [
65
+ "a1 = (\n",
66
+ " x1.join(x2, x3, x4, x5)\n",
67
+ " .cumsum()\n",
68
+ " .plot(title=\"Cummulative Sums of Random Numbers\", xlabel=\"num\", ylabel=\"value\")\n",
69
+ ")\n",
70
+ "a1"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": null,
76
+ "metadata": {},
77
+ "outputs": [],
78
+ "source": [
79
+ "a2 = x1.join(x1.exp()).qqplot()\n",
80
+ "a2"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": null,
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": [
89
+ "noise = dp.data(\n",
90
+ " (\n",
91
+ " np.minimum(x1.data.max() - x1.data, x1.data - x1.data.min())\n",
92
+ " / (x1.data.max() - x1.data.min())\n",
93
+ " ),\n",
94
+ " label=\"noise\",\n",
95
+ ")\n",
96
+ "a3 = (x1 + noise).ksplot()\n",
97
+ "a3"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": null,
103
+ "metadata": {},
104
+ "outputs": [],
105
+ "source": [
106
+ "a4 = x1.join(x1 + x2 + x3).ppplot()\n",
107
+ "a4"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": null,
113
+ "metadata": {},
114
+ "outputs": [],
115
+ "source": [
116
+ "sum4 = x1 + x2 + x3 + x4\n",
117
+ "sum5 = sum4 + x5\n",
118
+ "a5 = s.join(sum4, sum5).corrmap()\n",
119
+ "a5"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": null,
125
+ "metadata": {},
126
+ "outputs": [],
127
+ "source": [
128
+ "dp.figure(\n",
129
+ " [a0, a1, a2, a3, a4, a5], title=\"Figure Collections\", subplots_adjust={\"top\": 0.92}\n",
130
+ ")"
131
+ ]
132
+ }
133
+ ],
134
+ "metadata": {
135
+ "kernelspec": {
136
+ "display_name": "base",
137
+ "language": "python",
138
+ "name": "python3"
139
+ },
140
+ "language_info": {
141
+ "codemirror_mode": {
142
+ "name": "ipython",
143
+ "version": 3
144
+ },
145
+ "file_extension": ".py",
146
+ "mimetype": "text/x-python",
147
+ "name": "python",
148
+ "nbconvert_exporter": "python",
149
+ "pygments_lexer": "ipython3",
150
+ "version": "3.13.11"
151
+ }
152
+ },
153
+ "nbformat": 4,
154
+ "nbformat_minor": 2
155
+ }
@@ -0,0 +1,100 @@
1
+ """Install the package."""
2
+
3
+ #!/usr/bin/env python
4
+ # -*- coding: utf-8 -*-
5
+ import os
6
+ import re
7
+ from pathlib import Path
8
+ from typing import Final
9
+
10
+ import cfgtools as cfg
11
+ from re_extensions import rsplit, word_wrap
12
+
13
+ here = Path(__file__).parent
14
+
15
+ # Load the package's meta-data from pyproject.toml.
16
+ f = cfg.read_toml(here / "pyproject.toml")
17
+ project = f["project"].asdict()
18
+ NAME: Final[str] = project["name"]
19
+ SUMMARY: Final[str] = project["description"]
20
+ HOMEPAGE: Final[str] = project["urls"]["Repository"]
21
+ REQUIRES: Final[list[str]] = project["dependencies"]
22
+ SOURCE = "src"
23
+ LICENSE = (here / project["license-files"][0]).read_text().partition("\n")[0]
24
+
25
+ # Import the README and use it as the long-description.
26
+ readme_path = here / project["readme"]
27
+ if readme_path.exists():
28
+ long_description = "\n" + readme_path.read_text(encoding="utf-8")
29
+ else:
30
+ long_description = SUMMARY
31
+
32
+
33
+ def _readme2doc(
34
+ readme: str,
35
+ name: str = NAME,
36
+ requires: list[str] = REQUIRES,
37
+ homepage: str = HOMEPAGE,
38
+ pkg_license: str = LICENSE,
39
+ ) -> tuple[str, str]:
40
+ doc, rd = "", ""
41
+ for i, s in enumerate(rsplit("\n## ", readme)):
42
+ head = re.search(" .*\n", s).group()[1:-1]
43
+ if i == 0:
44
+ s = re.sub("^\n# .*", f"\n# {name}", s)
45
+ elif head == "Requirements":
46
+ s = re.sub(
47
+ "```txt.*```",
48
+ "```txt\n" + "\n".join(requires) + "\n```",
49
+ s,
50
+ flags=re.DOTALL,
51
+ )
52
+ elif head == "Installation":
53
+ s = re.sub(
54
+ "```sh.*```", f"```sh\n$ pip install {name}\n```", s, flags=re.DOTALL
55
+ )
56
+ elif head == "See Also":
57
+ pypipage = f"https://pypi.org/project/{name}/"
58
+ s = re.sub(
59
+ "### PyPI project\n.*",
60
+ f"### PyPI project\n* {pypipage}",
61
+ re.sub(
62
+ "### Github repository\n.*",
63
+ f"### Github repository\n* {homepage}",
64
+ s,
65
+ ),
66
+ )
67
+ elif head == "License":
68
+ s = f"\n## License\nThis project falls under the {pkg_license}.\n"
69
+
70
+ rd += s
71
+ if head not in {"Installation", "Requirements", "History"}:
72
+ doc += s
73
+ doc = re.sub("<!--html-->.*<!--/html-->", "", doc, flags=re.DOTALL)
74
+ return word_wrap(doc, maximum=88) + "\n\n", rd
75
+
76
+
77
+ def _quote(readme: str) -> str:
78
+ if "'''" in readme and '"""' in readme:
79
+ raise ReadmeFormatError("Both \"\"\" and ''' are found in the README")
80
+ if '"""' in readme:
81
+ return f"'''{readme}'''"
82
+ else:
83
+ return f'"""{readme}"""'
84
+
85
+
86
+ class ReadmeFormatError(Exception):
87
+ """Raised when the README has a wrong format."""
88
+
89
+
90
+ if __name__ == "__main__":
91
+ # Import the __init__.py and change the module docstring.
92
+ init_path = here / SOURCE / NAME / "__init__.py"
93
+ module_file = init_path.read_text(encoding="utf-8")
94
+ new_doc, long_description = _readme2doc(long_description)
95
+ module_file = re.sub(
96
+ "^\"\"\".*\"\"\"|^'''.*'''|^", _quote(new_doc), module_file, flags=re.DOTALL
97
+ )
98
+ init_path.write_text(module_file, encoding="utf-8")
99
+ readme_path.write_text(long_description.strip(), encoding="utf-8")
100
+ os.system(f"cd {here} && python -m build")