Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: upgrade dev dependency versions #60

Merged
merged 2 commits into from
Aug 24, 2023
Merged

Conversation

marcofavoritobi
Copy link
Contributor

@marcofavoritobi marcofavoritobi commented Aug 24, 2023

Proposed changes

This PR upgrades pyproject.toml dev dependencies' versions, and syncs tox.ini dependencies with the new versions.

@marcofavoritobi
Copy link
Contributor Author

Many of the changes in a2b9ea8 have been produced by the following script:

import toml
import requests


def get_latest_compatible_version(package_name, min_py_version="3.8", max_py_version="3.11"):
    """
    Fetch the latest version of a package from PyPI that's compatible with the specified Python version range.
    """
    response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
    if response.status_code == 200:
        data = response.json()
        versions = list(data["releases"].keys())

        # Sort versions in descending order
        versions.sort(key=lambda v: tuple(map(int, v.split('.'))), reverse=True)

        for version in versions:
            classifiers = data["releases"][version][0].get("classifiers", [])
            for classifier in classifiers:
                if classifier.startswith("Programming Language :: Python ::"):
                    supported_version = classifier.split()[-1]
                    if min_py_version <= supported_version < max_py_version:
                        return "^" + version
        return None
    else:
        print(f"Failed to get version for {package_name}. Using existing version.")
        return None


def main():
    # Read the pyproject.toml file
    with open("pyproject.toml", "r") as f:
        data = toml.load(f)

    # Check if dev-dependencies exist
    if "tool" in data and "poetry" in data["tool"] and "dev-dependencies" in data["tool"]["poetry"]:
        dev_dependencies = data["tool"]["poetry"]["dev-dependencies"]

        # Fetch latest version for each dev dependency
        for package, version in dev_dependencies.items():
            print(f"Fetching latest version for {package}...")
            latest_version = get_latest_version(package)
            if latest_version:
                dev_dependencies[package] = "^" + latest_version

        # Update the pyproject.toml file with the latest versions
        with open("pyproject.toml", "w") as f:
            toml.dump(data, f)
        print("Dev dependencies have been updated to their latest versions.")
    else:
        print("No dev-dependencies found in pyproject.toml.")


if __name__ == "__main__":
    main()

The sync by another simple script that: exports pyproject.toml in requirements.txt format with the command poetry export --without-hashes --with dev, and for each dependency, it replaces occurrences of the dependency name with {depname}=={depversion} (roughly).

@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2023

Codecov Report

Merging #60 (937855e) into main (8afc486) will not change coverage.
The diff coverage is n/a.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #60   +/-   ##
=======================================
  Coverage   91.36%   91.36%           
=======================================
  Files          42       42           
  Lines        1737     1737           
=======================================
  Hits         1587     1587           
  Misses        150      150           

@marcofavoritobi
Copy link
Contributor Author

Simple PR, nothing special, ready for review.

@muxator
Copy link

muxator commented Aug 24, 2023

Lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants