diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2735923..8d1b7b6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,37 +1,96 @@ -name: Publish distributions to PyPI +name: Build & Publish package to PyPI -# if this workflow is modified to be a generic CI workflow then -# add an if statement to the publish step so it only runs on tags. +# CI setup instructions: +# 1. Replace 'pvlib/twoaxistracking' and 'twoaxistracking' with your GitHub organization and repository name +# 2. Create a new environment for additional protection and security in the GitHub UI: +# Settings > Environments +# Name: release +# 3. Setup trusted publishing for the release environment: +# https://docs.pypi.org/trusted-publishers/ +# 4. Ensure your main development branch is named 'main'; if not, update the workflow or rename the branch + +# This workflow is triggered on pull requests that target the main branch +# on pushes to the main branch new tags that start with 'v' (for example, 'v1.0.0'). +# Only the main branch is used for publishing to PyPI, in the second job. on: + pull_request: + branches: + - main push: + branches: + - main tags: - "v*" +env: + python-version: "3.12" + jobs: - build-n-publish: - name: Build and publish distributions to PyPI - if: github.repository == 'pvlib/twoaxistracking' + build-distribution: + name: Build distribution runs-on: ubuntu-latest - permissions: - id-token: write # This is required for requesting the JWT - contents: read # This is required for actions/checkout steps: - # fetch all commits and tags so versioneer works - uses: actions/checkout@v4 + # Deep clone to fetch all commits and tags, by setting the fetch-depth to 0 with: fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.12" + python-version: ${{ env.python-version }} - name: Install build tools run: | python -m pip install --upgrade pip - python -m pip install --upgrade setuptools wheel build + python -m pip install --upgrade setuptools wheel build twine + - name: Build packages - run: python -m build --sdist --wheel + # creates the necessary distribution files to /dist + run: python -m build + + - name: Check metadata verification + # this step ensures the metadata is correct and complete + # it is a good practice to run this before publishing to PyPI + run: python -m twine check --strict dist/* + + - name: Distribution files & installation sizes + # this step is useful to get some useful metrics and ensure changes do not break the size of the distribution + run: | + echo "Distribution files sizes" + du -sh dist/* + python -m pip install dist/*.whl --target /tmp/pvlib --quiet --quiet + echo "Installation size of wheel" + du -sh /tmp/pvlib/twoaxistracking + + - name: Upload artifact with distribution files + # this step uploads the distribution files to the GitHub artifact store if they are needed later to publish to PyPI + if: github.repository == 'pvlib/twoaxistracking' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + uses: actions/upload-artifact@v4 + with: + name: distro-files + path: dist/ + if-no-files-found: error # files are required in the next job + retention-days: 1 # delete the artifact after 1 day, no need to keep it for too long + compression-level: 0 # no need to compress the files + + publish-distribution: + name: Upload distribution to PyPI + runs-on: ubuntu-latest + needs: build-distribution # first build, then publish + # only publish distribution to PyPI in tagged commits + if: github.repository == 'pvlib/twoaxistracking' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + environment: release + permissions: + id-token: write # this permission mandatory for trusted publishing + steps: + - name: Download artifact with distribution files + uses: actions/download-artifact@v4 + with: + name: distro-files + path: dist/ - - name: Publish distribution to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + - name: Publish distribution to PyPI + # this step publishes the distribution files to PyPI by using PyPI trusted publishers + # https://docs.pypi.org/trusted-publishers/ + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore index 50129fd..1f4d1ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +## .gititnore template file retrieved from +## https://github.com/github/gitignore/blob/main/Python.gitignore in 2025-03-18 + .ipynb_checkpoints .vscode */.ipynb_checkpoints/* @@ -12,3 +15,177 @@ dist/ docs/source/generated .coverage +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc diff --git a/pyproject.toml b/pyproject.toml index 194d75c..2aae426 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,8 @@ description = "twoaxistracking is a python package for simulating two-axis track readme = "README.md" requires-python = ">=3.9" keywords = ["solar energy", "photovoltaics", "solar collector", "shading"] -license = {file = "LICENSE"} +license = "BSD-3-Clause" +license-files = ["LICEN[CS]E*"] classifiers = [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.9", @@ -32,7 +33,6 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", - "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Topic :: Scientific/Engineering", "Intended Audience :: Science/Research", @@ -59,6 +59,7 @@ doc = [ Documentation = "https://twoaxistracking.readthedocs.io" Issues = "https://github.com/pvlib/twoaxistracking/issues" Repository = "https://github.com/pvlib/twoaxistracking.git" +Changelog = "https://github.com/pvlib/twoaxistracking/blob/main/docs/source/whatsnew.md" [tool.pytest.ini_options] addopts = "--cov=twoaxistracking --cov-fail-under=100 --cov-report=term-missing"