cmon2lib 0.0.1__tar.gz

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.
cmon2lib-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Simon Dorr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: cmon2lib
3
+ Version: 0.0.1
4
+ Summary: my personal python library for convenient personalized functionality
5
+ Author: Simon Dorr
6
+ Author-email: simon@ich-bin-simon.de
7
+ Requires-Python: >=3.7
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Provides-Extra: test
12
+ Requires-Dist: pytest ; extra == "test"
13
+ Requires-Dist: pytest-cov ; extra == "test"
14
+ Requires-Dist: python-taiga (>=1.3.2,<2.0.0)
15
+ Project-URL: Homepage, https://github.com/cmon2/cmon2lib
16
+ Description-Content-Type: text/markdown
17
+
18
+ # cmon2lib
19
+ my personal python library for convenient personalized functionality
20
+
@@ -0,0 +1,2 @@
1
+ # cmon2lib
2
+ my personal python library for convenient personalized functionality
@@ -0,0 +1 @@
1
+ __version__ = "0.0.5"
File without changes
@@ -0,0 +1,46 @@
1
+ from cmon2lib.taiga.taiga_user_functions import authenticate, get_authenticated_user_projects
2
+ from cmon2lib.utils.cmon_logging import clog
3
+
4
+
5
+ def cprint_project(project):
6
+ """
7
+ Return a styled string containing all user story statuses with their user stories as a sublist for the given project.
8
+
9
+ Format:
10
+ === Project: <id> | <name> ===
11
+ [<status1>]
12
+ • <story1>
13
+ • <story2>
14
+ [<status2>]
15
+ ...
16
+ Args:
17
+ project: The Taiga project object.
18
+ Returns:
19
+ str: A formatted string with statuses and their user stories.
20
+ """
21
+ clog('info', f"Formatting project {project.id} - {project.name}")
22
+ result = [f"\n=== Project: {project.id} | {project.name} ==="]
23
+ statuses = project.list_user_story_statuses()
24
+ user_stories = project.list_user_stories()
25
+ # Map status id to status name
26
+ status_map = {status.id: status.name for status in statuses}
27
+ # Group user stories by status
28
+ stories_by_status = {status.id: [] for status in statuses}
29
+ for story in user_stories:
30
+ stories_by_status.setdefault(story.status, []).append(story)
31
+ # Build output
32
+ for status in statuses:
33
+ result.append(f" [{status.name}]")
34
+ stories = stories_by_status.get(status.id, [])
35
+ for story in stories:
36
+ result.append(f" • {story.id}: {story.subject}")
37
+ if not stories:
38
+ clog('debug', f"No user stories for status '{status.name}' in project {project.id}")
39
+ return "\n".join(result)
40
+
41
+ if __name__ == "__main__":
42
+ clog('info', "Fetching authenticated user projects...")
43
+ projects = get_authenticated_user_projects()
44
+ for project in projects:
45
+ print(cprint_project(project))
46
+ clog('info', f"Printed project {project.id} - {project.name}")
@@ -0,0 +1,75 @@
1
+ import os
2
+ from taiga import TaigaAPI, exceptions
3
+ from cmon2lib.utils.cmon_logging import clog
4
+
5
+ # Use the base URL (no /api/v1/ at the end)
6
+ TAIGA_API_URL = os.environ.get("TAIGA_API_URL", "https://api.taiga.io/")
7
+ TAIGA_USERNAME = os.environ.get("TAIGA_USERNAME")
8
+ TAIGA_PASSWORD = os.environ.get("TAIGA_PASSWORD")
9
+ TAIGA_TOKEN = os.environ.get("TAIGA_TOKEN")
10
+
11
+ def authenticate():
12
+ """Authenticate to Taiga and return the API object."""
13
+ api = TaigaAPI(host=TAIGA_API_URL)
14
+ try:
15
+ if TAIGA_TOKEN:
16
+ api.auth(token=TAIGA_TOKEN)
17
+ elif TAIGA_USERNAME and TAIGA_PASSWORD:
18
+ api.auth(username=TAIGA_USERNAME, password=TAIGA_PASSWORD)
19
+ else:
20
+ raise EnvironmentError("Set TAIGA_USERNAME and TAIGA_PASSWORD or TAIGA_TOKEN environment variables.")
21
+ except exceptions.TaigaRestException as e:
22
+ raise RuntimeError(f"Taiga authentication failed: {e}")
23
+ return api
24
+
25
+ def get_authenticated_user():
26
+ """
27
+ Get the authenticated user's information and log the user ID.
28
+ Returns:
29
+ user: The authenticated Taiga user object.
30
+ Raises:
31
+ RuntimeError: If authentication fails or user cannot be fetched.
32
+ """
33
+ api = authenticate()
34
+ try:
35
+ user = api.me()
36
+ clog('info', f"Authenticated user ID: {user.id}")
37
+ return user
38
+ except exceptions.TaigaRestException as e:
39
+ clog('error', f"Failed to get authenticated user: {e}")
40
+ raise RuntimeError(f"Failed to get authenticated user: {e}")
41
+
42
+
43
+ def get_authenticated_user_projects():
44
+ """
45
+ Get the authenticated user's projects using their user ID and log the project names.
46
+ Returns:
47
+ list: List of Taiga project objects the user is a member of.
48
+ Raises:
49
+ RuntimeError: If projects cannot be fetched.
50
+ """
51
+ api = authenticate()
52
+ try:
53
+ user = api.me()
54
+ page_size = 15 # Default Taiga API page size
55
+ projects = api.projects.list(page=1, member=user.id, page_size=page_size)
56
+ # Check if there might be more projects than fit on one page
57
+ if hasattr(projects, '__len__') and len(projects) == page_size:
58
+ clog('warning', f"Project list may be truncated: found {len(projects)} projects (page size limit). There may be more projects for user {user.id}.")
59
+ if projects:
60
+ clog('info', f"Found {len(projects)} projects for user {user.id}.")
61
+ for project in projects:
62
+ clog('debug', f"Project: {project.id}: {project.name}")
63
+ else:
64
+ clog('warning', f"No projects found for user {user.id}.")
65
+ return projects
66
+ except exceptions.TaigaRestException as e:
67
+ clog('error', f"Failed to get projects for user: {e}")
68
+ raise RuntimeError(f"Failed to get projects for user: {e}")
69
+
70
+ if __name__ == "__main__":
71
+ try:
72
+ get_authenticated_user()
73
+ get_authenticated_user_projects()
74
+ except Exception as e:
75
+ clog('error', f"Error: {e}")
@@ -0,0 +1,11 @@
1
+ def sum(a, b):
2
+ """Returns the sum of a and b."""
3
+ return a + b
4
+
5
+ def subtract(a, b):
6
+ """Returns the difference of a and b."""
7
+ return a - b
8
+
9
+ def multiply(a, b):
10
+ """Returns the product of a and b."""
11
+ return a * b
@@ -0,0 +1,17 @@
1
+ import logging
2
+
3
+ # Set up a harmonized logger for cmon2lib
4
+ logger = logging.getLogger("cmon2lib")
5
+ logger.setLevel(logging.INFO) # Default level, can be changed by user
6
+ handler = logging.StreamHandler()
7
+ formatter = logging.Formatter('[cmon2lib] %(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
8
+ handler.setFormatter(formatter)
9
+ if not logger.hasHandlers():
10
+ logger.addHandler(handler)
11
+
12
+ def clog(level, msg, *args, **kwargs):
13
+ """Central logging gateway for cmon2lib. Usage: clog('info', 'message')"""
14
+ if hasattr(logger, level):
15
+ getattr(logger, level)(msg, *args, **kwargs)
16
+ else:
17
+ logger.info(msg, *args, **kwargs)
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+ [project]
6
+ name = "cmon2lib"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name = "Simon Dorr", email = "simon@ich-bin-simon.de" }
10
+ ]
11
+ description = "my personal python library for convenient personalized functionality"
12
+ readme = "README.md"
13
+ requires-python = ">=3.7"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = ["python-taiga (>=1.3.2,<2.0.0)"]
20
+
21
+ [project.urls]
22
+ "Homepage" = "https://github.com/cmon2/cmon2lib"
23
+
24
+ [tool.setuptools.packages.find]
25
+ include = ["cmon2lib", "cmon2lib.*"]
26
+
27
+ [project.optional-dependencies]
28
+ test = [
29
+ "pytest",
30
+ "pytest-cov"
31
+ ]
32
+
33
+ [tool.pytest.ini_options]
34
+ addopts = "--cov=cmon2lib --cov-report=xml --cov-report=term"
35
+ testpaths = "tests"
36
+ pythonpath = "."