python-flask-dev 0.0.9__py3-none-any.whl → 0.0.11__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,113 @@
1
+ import logging
2
+ import requests
3
+ import tomllib
4
+ import tomli_w
5
+ import argparse
6
+
7
+
8
+ # ENV VARS
9
+ PYPI_BASE_URL = "https://pypi.org/simple/"
10
+ # VERSIONING = "foo_bar_baz"
11
+ VERSIONING = "manual"
12
+ # VERSIONING = "dynamic"
13
+ # VERSIONING = "automatic"
14
+
15
+ # # ARGS
16
+ # parser = argparse.ArgumentParser()
17
+ # parser.add_argument('-v', '--versioning', default="manual", help='Options: "automatic", "dynamic", "manual"')
18
+ # args = parser.parse_args()
19
+
20
+ # LOGGING
21
+ logger = logging.getLogger(__name__)
22
+ logging.basicConfig(level=logging.INFO)
23
+
24
+ def get_pypi_repository_data(toml_data):
25
+ # Retrieve latest version from PyPI API data
26
+ project_name = toml_data["project"]["name"]
27
+ pypi_project_url = f"{PYPI_BASE_URL}{project_name}"
28
+ resp = requests.get(pypi_project_url, headers={"Accept": "application/vnd.pypi.simple.v1+json"}).json()
29
+
30
+ project_versions = resp["versions"]
31
+ project_versions_sorted = sorted(project_versions, key=lambda x: list(map(int, x.split('.'))), reverse=True)
32
+ project_latest_version = project_versions_sorted[0]
33
+
34
+ return {"project_name": project_name, "pypi_project_url": pypi_project_url, "project_versions": project_versions, "project_latest_version": project_latest_version}
35
+
36
+ def update_pyproject_config(toml_data):
37
+ with open("pyproject.toml", "wb") as f:
38
+ tomli_w.dump(toml_data, f)
39
+
40
+ def set_version_manually(toml_data):
41
+ if "version" in toml_data["project"]["dynamic"]:
42
+ toml_data["project"]["dynamic"].remove("version")
43
+ update_pyproject_config(toml_data)
44
+
45
+ logging.info("Manual versioning selected. Please update the version number in pyproject.toml manually.")
46
+
47
+ def set_version_dynamically(toml_data):
48
+ if "version" in toml_data["project"]:
49
+ del toml_data["project"]["version"]
50
+ update_pyproject_config(toml_data)
51
+
52
+ if "version" not in toml_data["project"]["dynamic"]:
53
+ toml_data["project"]["dynamic"].append("version")
54
+ update_pyproject_config(toml_data)
55
+
56
+ logging.info("Dynamic versioning selected. Please set the version number in the 'version.txt' file.")
57
+
58
+ def set_version_automatically(toml_data):
59
+ project_name, pypi_project_url, project_versions, project_latest_version = get_pypi_repository_data(toml_data).values()
60
+
61
+ # Change the version number
62
+ project_versioning_list = project_latest_version.split(".")
63
+ # TODO: int to string
64
+ project_versioning_list[2] = f"{int(project_versioning_list[2]) + 1}"
65
+ logger.info(f"######## project_versioning_list: {project_versioning_list}")
66
+ new_project_version = '.'.join(project_versioning_list)
67
+ logger.info(f"######## new_project_version: {new_project_version}")
68
+
69
+ # Write the new version number
70
+ toml_data["project"]["version"] = new_project_version
71
+ if "version" in toml_data["project"]["dynamic"]:
72
+ toml_data["project"]["dynamic"].remove("version")
73
+ update_pyproject_config(toml_data)
74
+ logging.info(f"Automatic versioning selected. Version number updated to {new_project_version} in pyproject.toml.")
75
+
76
+ def incremental_versioning(versioning):
77
+ # Read project data from pyproject.toml
78
+ with open("pyproject.toml", "rb") as f:
79
+ toml_data = tomllib.load(f)
80
+ logger.info(f"######## toml_data: {toml_data}")
81
+
82
+ if "version" not in toml_data["project"]:
83
+ toml_data["project"]["version"] = ""
84
+ update_pyproject_config(toml_data)
85
+
86
+ if "dynamic" not in toml_data["project"]:
87
+ toml_data["project"]["dynamic"] = []
88
+ update_pyproject_config(toml_data)
89
+
90
+ logging.info(f"######## pypi_project_url: {f"{PYPI_BASE_URL}{toml_data["project"]["name"]}"}")
91
+ logging.info(f"######## Project: {get_pypi_repository_data(toml_data)['project_name']}")
92
+ logging.info(f"######## Version: {get_pypi_repository_data(toml_data)['project_latest_version']}")
93
+
94
+ if versioning == "manual":
95
+ set_version_manually(toml_data)
96
+ elif versioning == "dynamic":
97
+ set_version_dynamically(toml_data)
98
+ elif versioning == "automatic":
99
+ set_version_automatically(toml_data)
100
+ else:
101
+ set_version_manually(toml_data)
102
+ logging.info("Defaulting to manual versioning. Options: 'automatic', 'dynamic', 'manual'")
103
+
104
+ if __name__ == "__main__":
105
+ # TODO: replace in python-flask-dev pkg; passed in as var
106
+ incremental_versioning(VERSIONING)
107
+ #
108
+ # with open("pyproject.toml", "rb") as f:
109
+ # toml_data = tomllib.load(f)
110
+ # logger.info(f"############ toml_data: {toml_data}")
111
+ # #
112
+ # pypi_data = get_pypi_repository_data(toml_data)
113
+ # logger.info(f"############ pypi data: {pypi_data}")
@@ -1,11 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-flask-dev
3
- Version: 0.0.9
3
+ Version: 0.0.11
4
4
  Summary: Package containing modules with 'helper' functions to support the development of Python Flask applications.
5
5
  Author-email: Dani <daniasestan@gmail.com>
6
6
  License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/pypa/sampleproject
8
- Project-URL: Issues, https://github.com/pypa/sampleproject/issues
9
7
  Classifier: Programming Language :: Python :: 3
10
8
  Classifier: Operating System :: POSIX :: Linux
11
9
  Classifier: Framework :: Flask
@@ -8,7 +8,9 @@ python_flask_dev/filtering_data.py,sha256=hB6M-anMztg1Nhi6ilxGBYMEpqUMKGmmGoS0vk
8
8
  python_flask_dev/formatting_data.py,sha256=bGTNnvRaACn_E44-03CoQ9Fc_oK3_aISROaLLJZLdKg,209
9
9
  python_flask_dev/importing_modules.py,sha256=rsRPM46WdeNGiVlp_xbpMucRWLLaE6fA37gFqo3Y9R0,2532
10
10
  python_flask_dev/path_retrieval.py,sha256=8jmSCJ5SKKvtjI6lQtr9gQH6RIFDU9_ouiL2GsaXb00,319
11
- python_flask_dev-0.0.9.dist-info/METADATA,sha256=--rI9ef0yxvOIyJ_XLKYKcQeZ4EU1pQbxYRhzEG42rg,4902
12
- python_flask_dev-0.0.9.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
13
- python_flask_dev-0.0.9.dist-info/top_level.txt,sha256=LhLe2esd0pDfth_R0Ai8vfZMgucbwmfJAEpJla6Vk8w,35
14
- python_flask_dev-0.0.9.dist-info/RECORD,,
11
+ python_flask_dev/packaging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ python_flask_dev/packaging/incremental_versioning.py,sha256=eQ3jiVQ6XQ2a4FFWmIio1FfK31pYGwcWYAhpyXnoHrY,4582
13
+ python_flask_dev-0.0.11.dist-info/METADATA,sha256=Yk1V5GBWljGwVXyWtX0m_ZULrqMlv-OA_NpsDymcHyk,4776
14
+ python_flask_dev-0.0.11.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
15
+ python_flask_dev-0.0.11.dist-info/top_level.txt,sha256=LhLe2esd0pDfth_R0Ai8vfZMgucbwmfJAEpJla6Vk8w,35
16
+ python_flask_dev-0.0.11.dist-info/RECORD,,