From 09d7611e33b85155df7ea9f3b370a23f133c3c33 Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Mon, 31 Mar 2025 15:45:57 +0200 Subject: [PATCH 1/2] pyproject --- .github/workflows/pythonpackage.yml | 3 +- publish.sh | 4 +- pyproject.toml | 74 +++++++++++++++++++++++++++++ requirements-dev.txt | 5 -- setup.cfg | 7 --- setup.py | 63 ++++-------------------- 6 files changed, 86 insertions(+), 70 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements-dev.txt delete mode 100644 setup.cfg diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index f8475cb..34d9386 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -26,8 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements-dev.txt - pip install -e . + pip install .[dev] - name: Test with pytest run: | pytest diff --git a/publish.sh b/publish.sh index b621a36..4ecb351 100755 --- a/publish.sh +++ b/publish.sh @@ -1,5 +1,5 @@ # build and publish to # https://pypi.org/project/livelossplot/ -rm -r dist/ -python setup.py sdist bdist_wheel +rm -rf dist/ +python -m build twine upload dist/* diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4525337 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,74 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "livelossplot" +dynamic = ["version"] # Version is read from version.py via setuptools config +description = "Live training loss plot in Jupyter Notebook for Keras, PyTorch and others." +readme = "README.md" +requires-python = ">=3.7" +license = {text = "MIT"} +keywords = ["keras", "pytorch", "plot", "chart", "deep-learning"] +authors = [ + {name = "Piotr Migdał", email = "pmigdal@gmail.com"} +] +classifiers = [ + "Development Status :: 4 - Beta", + "Framework :: Jupyter", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Topic :: Scientific/Engineering :: Visualization", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "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", + "Programming Language :: Python :: 3.12", +] +dependencies = [ + 'ipython==7.*; python_version<"3.8"', + 'matplotlib', + 'bokeh', + 'numpy<1.22; python_version<"3.8"', +] + +[project.urls] +Homepage = "https://github.com/stared/livelossplot" + +[project.optional-dependencies] +dev = [ + "pytest", + "flake8", + "twine", + "wheel", + "build", + # Add other dev dependencies if needed (e.g., from the old requirements-dev.txt) +] + +[tool.setuptools.dynamic] +# Read version from livelossplot/version.py +version = {attr = "livelossplot.version.__version__"} + +[tool.setuptools.packages.find] +# Look for packages in the root directory (no src layout) +where = ["."] + +[tool.flake8] +exclude = ".git,*migrations*,build*,old*,dist" +max-line-length = 120 + +[tool.yapf] +based_on_style = "facebook" +column_limit = 120 + +# --- Add configuration for tools like flake8 if desired --- +# Example: [tool.flake8] +# ignore = "E501,W503" +# max-line-length = 88 +# exclude = ".git,__pycache__,build,dist" \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index f9a3464..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,5 +0,0 @@ -pytest -flake8 -yapf -jupyter -pdoc3 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 8ca4264..0000000 --- a/setup.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -exclude = .git,*migrations*,build*,old* -max-line-length = 120 - -[yapf] -based_on_style = facebook -column_limit = 120 diff --git a/setup.py b/setup.py index 0e435df..7de9d51 100644 --- a/setup.py +++ b/setup.py @@ -1,58 +1,13 @@ -from setuptools import setup, find_packages -from os import path -import re - - -def readme(): - with open('README.md', encoding='utf-8') as f: - return f.read() - - -def version(): - this_directory = path.abspath(path.dirname(__file__)) - with open(path.join(this_directory, 'livelossplot/version.py')) as f: - version_file = f.read() - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) - version = version_match.group(1) - - return version +from setuptools import setup +# Most configuration is now in pyproject.toml +# This setup.py remains for compatibility and +# potentially for features not yet supported in pyproject.toml +# or for dynamic configuration needs. setup( - name='livelossplot', - version=version(), - python_requires=">=3.7", - install_requires=[ - 'ipython==7.*;python_version<"3.8"', - 'matplotlib', 'bokeh', - 'numpy<1.22;python_version<"3.8"', - ], - description='Live training loss plot in Jupyter Notebook for Keras, PyTorch and others.', - long_description=readme(), - long_description_content_type='text/markdown', - url='https://github.com/stared/livelossplot', - author='Piotr Migdał', - author_email='pmigdal@gmail.com', - keywords=['keras', 'pytorch', 'plot', 'chart', 'deep-learning'], - license='MIT', - classifiers=[ - 'Development Status :: 4 - Beta', - 'Framework :: Jupyter', - 'Intended Audience :: Developers', - 'Intended Audience :: Education', - 'Intended Audience :: Science/Research', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: Artificial Intelligence', - 'Topic :: Scientific/Engineering :: Visualization', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - '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', - 'Programming Language :: Python :: 3.12', - ], - packages=find_packages(), - zip_safe=False + # If you need to pass specific arguments to setuptools that + # cannot be configured in pyproject.toml, you can add them here. + # For example: + # ext_modules=... ) From 90ad68d144db562347fd10a08a44d2de7240dc38 Mon Sep 17 00:00:00 2001 From: Piotr Migdal Date: Mon, 31 Mar 2025 15:51:02 +0200 Subject: [PATCH 2/2] gha to pypi publishing --- .github/workflows/publish.yml | 47 +++++++++++++++++++++++++++++++++++ publish.sh | 5 ---- setup.py | 13 ---------- 3 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/publish.yml delete mode 100755 publish.sh delete mode 100644 setup.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7f5c8e4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,47 @@ +# This workflow builds and publishes the package to PyPI when a tag is pushed + +name: Publish Python Package + +on: + push: + tags: + - 'v*' # Trigger on tags starting with 'v' + +jobs: + deploy: + runs-on: ubuntu-latest + + # Grant GITHUB_TOKEN the permissions required to create a release + permissions: + contents: read + id-token: write # Required for trusted publishing + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' # Use a recent Python version for building + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + + - name: Build package + run: python -m build + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + # No API token needed if using trusted publishing + # with: + # password: ${{ secrets.PYPI_API_TOKEN }} # Use an API Token if not using Trusted Publishing + + # Optional: Create a GitHub Release + # - name: Create GitHub Release + # uses: softprops/action-gh-release@v1 + # with: + # files: dist/* + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/publish.sh b/publish.sh deleted file mode 100755 index 4ecb351..0000000 --- a/publish.sh +++ /dev/null @@ -1,5 +0,0 @@ -# build and publish to -# https://pypi.org/project/livelossplot/ -rm -rf dist/ -python -m build -twine upload dist/* diff --git a/setup.py b/setup.py deleted file mode 100644 index 7de9d51..0000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -from setuptools import setup - -# Most configuration is now in pyproject.toml -# This setup.py remains for compatibility and -# potentially for features not yet supported in pyproject.toml -# or for dynamic configuration needs. - -setup( - # If you need to pass specific arguments to setuptools that - # cannot be configured in pyproject.toml, you can add them here. - # For example: - # ext_modules=... -)