|
3 | 3 | import codecs |
4 | 4 | import os |
5 | 5 |
|
| 6 | +try: |
| 7 | + import requests |
| 8 | + requests_installed = True |
| 9 | +except ImportError: |
| 10 | + requests_installed = False |
| 11 | + |
6 | 12 | #VERSION = '0.0.1' |
7 | | -VERSION = ( |
8 | | - subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE) |
9 | | - .stdout.decode("utf-8") |
10 | | - .strip() |
11 | | -) |
| 13 | +# VERSION = ( |
| 14 | +# subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE) |
| 15 | +# .stdout.decode("utf-8") |
| 16 | +# .strip() |
| 17 | +# ) |
| 18 | + |
| 19 | +def get_pypi_version(): |
| 20 | + if not requests_installed: |
| 21 | + print("Warning: 'requests' module is not installed. Using default version.") |
| 22 | + return "0.0.1" |
| 23 | + try: |
| 24 | + response = requests.get("https://pypi.org/pypi/easyPythonpi/json") |
| 25 | + data = response.json() |
| 26 | + return str(data["info"]["version"]) |
| 27 | + except Exception as e: |
| 28 | + print(f"Error fetching version from PyPI: {e}") |
| 29 | + return "0.0.1" |
| 30 | + |
| 31 | +def increment_version(version): |
| 32 | + major, minor, patch = map(int, version.split('.')) |
| 33 | + patch += 1 |
| 34 | + if patch > 9: |
| 35 | + patch = 0 |
| 36 | + minor += 1 |
| 37 | + if minor > 9: |
| 38 | + minor = 0 |
| 39 | + major += 1 |
| 40 | + return f"{major}.{minor}.{patch}" |
| 41 | + |
| 42 | +def get_version(): |
| 43 | + pypi_version = get_pypi_version() |
| 44 | + new_version = increment_version(pypi_version) |
| 45 | + |
| 46 | + try: |
| 47 | + git_describe = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) |
| 48 | + git_version = git_describe.stdout.decode("utf-8").strip() |
| 49 | + |
| 50 | + if "-" in git_version: |
| 51 | + v, i, s = git_version.split("-") |
| 52 | + git_version = f"{new_version}+{i}.git.{s}" |
| 53 | + else: |
| 54 | + git_version = new_version |
| 55 | + except subprocess.CalledProcessError: |
| 56 | + git_version = new_version |
| 57 | + |
| 58 | + return git_version |
| 59 | + |
| 60 | +VERSION = get_version() |
| 61 | + |
| 62 | +print("Version: ", VERSION) |
12 | 63 |
|
13 | | -if "-" in VERSION: |
| 64 | +if VERSION and "-" in VERSION: |
14 | 65 | # when not on tag, git describe outputs: "1.3.3-22-gdf81228" |
15 | 66 | # pip has gotten strict with version numbers |
16 | 67 | # so change it to: "1.3.3+22.git.gdf81228" |
|
39 | 90 | description=DESCRIPTION, |
40 | 91 | long_description_content_type="text/markdown", |
41 | 92 | packages=find_packages(), |
42 | | - install_requires=["numpy >= 1.19.5"], |
| 93 | + install_requires=["numpy >= 1.19.5"] + (["requests >= 2.25.1"] if not requests_installed else []), |
| 94 | + setup_requires=["requests >= 2.25.1"], |
43 | 95 | keywords=['python', 'sorting', 'beginners', 'sockets'], |
44 | 96 | classifiers=[ |
45 | 97 | "Development Status :: 1 - Planning", |
|
0 commit comments