c2cciutils 1.7.0.dev173__py3-none-any.whl → 1.7.3.dev2__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.

Potentially problematic release.


This version of c2cciutils might be problematic. Click here for more details.

c2cciutils/__init__.py CHANGED
@@ -11,7 +11,6 @@ import sys
11
11
  from re import Match, Pattern
12
12
  from typing import Any, Optional, TypedDict, cast
13
13
 
14
- import magic
15
14
  import requests
16
15
  import ruamel.yaml
17
16
 
@@ -22,7 +21,6 @@ def get_repository() -> str:
22
21
  """
23
22
  Get the current GitHub repository like `organization/project`.
24
23
  """
25
-
26
24
  if "GITHUB_REPOSITORY" in os.environ:
27
25
  return os.environ["GITHUB_REPOSITORY"]
28
26
 
@@ -47,7 +45,6 @@ def merge(default_config: Any, config: Any) -> Any:
47
45
  default_config: The default config that will be applied
48
46
  config: The base config, will be modified
49
47
  """
50
-
51
48
  if not isinstance(default_config, dict) or not isinstance(config, dict):
52
49
  return config
53
50
 
@@ -79,7 +76,6 @@ def get_config() -> c2cciutils.configuration.Configuration:
79
76
  """
80
77
  Get the configuration, with project and auto detections.
81
78
  """
82
-
83
79
  config: c2cciutils.configuration.Configuration = {}
84
80
  if os.path.exists("ci/config.yaml"):
85
81
  with open("ci/config.yaml", encoding="utf-8") as open_file:
@@ -129,8 +125,6 @@ def get_config() -> c2cciutils.configuration.Configuration:
129
125
 
130
126
  default_config = {
131
127
  "publish": publish_config,
132
- "pr-checks": c2cciutils.configuration.PULL_REQUEST_CHECKS_DEFAULT,
133
- "audit": c2cciutils.configuration.AUDIT_DEFAULT,
134
128
  }
135
129
  merge(default_config, config)
136
130
 
@@ -279,7 +273,6 @@ def print_versions(config: c2cciutils.configuration.PrintVersions) -> bool:
279
273
  Arguments:
280
274
  config: The print configuration
281
275
  """
282
-
283
276
  for version in config.get("versions", c2cciutils.configuration.PRINT_VERSIONS_VERSIONS_DEFAULT):
284
277
  try:
285
278
  sys.stdout.flush()
@@ -383,7 +376,6 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) ->
383
376
  Return the data result
384
377
  In case of error it throw an exception
385
378
  """
386
-
387
379
  with open(os.path.join(os.path.dirname(__file__), query_file), encoding="utf-8") as query_open:
388
380
  query = query_open.read()
389
381
 
@@ -416,164 +408,8 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) ->
416
408
  return cast(dict[str, Any], json_response["data"])
417
409
 
418
410
 
419
- def get_git_files_mime(
420
- mime_type: Optional[list[str]] = None,
421
- extensions: Optional[list[str]] = None,
422
- ignore_patterns_re: Optional[list[str]] = None,
423
- ) -> list[str]:
424
- """
425
- Get list of paths from git with all the files that have the specified mime type.
426
-
427
- Arguments:
428
- mime_type: The considered MIME type
429
- extensions: The considered extensions
430
- ignore_patterns_re: A list of regular expressions of files that we should ignore
431
- """
432
- if mime_type is None:
433
- mime_type = ["text/x-python", "text/x-script.python"]
434
- if extensions is None:
435
- extensions = [".py"]
436
- ignore_patterns_compiled = [re.compile(p) for p in ignore_patterns_re or []]
437
- result = []
438
-
439
- for filename in subprocess.check_output(["git", "ls-files"]).decode().strip().split("\n"):
440
- if os.path.isfile(filename) and (
441
- os.path.splitext(filename)[1] in extensions or magic.from_file(filename, mime=True) in mime_type
442
- ):
443
- accept = True
444
- for pattern in ignore_patterns_compiled:
445
- if pattern.search(filename):
446
- accept = False
447
- break
448
- if accept:
449
- result.append(filename)
450
- return result
451
-
452
-
453
- def get_branch(branch: Optional[str], master_branch: str = "master") -> str:
454
- """
455
- Get the branch name.
456
-
457
- Arguments:
458
- branch: The forced to use branch name
459
- master_branch: The master branch name, can be used as default value
460
-
461
- Return the branch name
462
- """
463
-
464
- if branch is not None:
465
- return branch
466
- try:
467
- branch = (
468
- subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], check=True, stdout=subprocess.PIPE)
469
- .stdout.decode()
470
- .strip()
471
- )
472
- except subprocess.CalledProcessError as exception:
473
- print(f"Error getting branch: {exception}")
474
- branch = "HEAD"
475
-
476
- if branch == "HEAD":
477
- branch = os.environ.get("GITHUB_HEAD_REF", master_branch)
478
- assert branch is not None
479
- return branch
480
-
481
-
482
- def get_based_on_master(
483
- repo: list[str],
484
- override_current_branch: Optional[str],
485
- master_branch: str,
486
- config: c2cciutils.configuration.Configuration,
487
- ) -> bool:
488
- """
489
- Check that we are not on a release branch (to avoid errors in versions check).
490
-
491
- This function will check the last 20 commits in current branch,
492
- and for each other branch (max 50) check if any commit in last 10 commits is the current one.
493
-
494
- Arguments:
495
- repo: The repository [<organization>, <name>]
496
- override_current_branch: The branch to use instead of the current one
497
- master_branch: The master branch name
498
- config: The full configuration
499
- """
500
- if os.environ.get("GITHUB_REF", "").startswith("refs/tags/"):
501
- # The tags are never consider as based on master
502
- return False
503
- current_branch = get_branch(override_current_branch, master_branch)
504
- if current_branch == master_branch:
505
- return True
506
- branches_re = compile_re(config["version"].get("branch_to_version_re", []))
507
- if does_match(current_branch, branches_re):
508
- return False
509
- if os.environ.get("GITHUB_BASE_REF"):
510
- return os.environ.get("GITHUB_BASE_REF") == master_branch
511
- commits_repository_json = graphql(
512
- "commits.graphql", {"name": repo[1], "owner": repo[0], "branch": current_branch}
513
- ).get("repository", {})
514
- commits_json = (
515
- commits_repository_json.get("ref", {}).get("target", {}).get("history", {}).get("nodes", [])
516
- if commits_repository_json.get("ref")
517
- else []
518
- )
519
- branches_json = [
520
- branch
521
- for branch in (
522
- graphql("branches.graphql", {"name": repo[1], "owner": repo[0]})["repository"]["refs"]["nodes"]
523
- )
524
- if branch["name"] != current_branch and does_match(branch["name"], branches_re)
525
- ]
526
- based_branch = master_branch
527
- found = False
528
- for commit in commits_json:
529
- for branch in branches_json:
530
- commits = [
531
- branch_commit
532
- for branch_commit in branch["target"]["history"]["nodes"]
533
- if commit["oid"] == branch_commit["oid"]
534
- ]
535
- if commits:
536
- based_branch = branch["name"]
537
- found = True
538
- break
539
- if found:
540
- break
541
- return based_branch == master_branch
542
-
543
-
544
- def get_codespell_command(config: c2cciutils.configuration.Configuration, fix: bool = False) -> list[str]:
545
- """
546
- Get the codespell command.
547
-
548
- Arguments:
549
- config: The full configuration
550
- fix: If we should fix the errors
551
- """
552
- codespell_config = config.get("codespell", {})
553
- codespell_config = codespell_config if isinstance(codespell_config, dict) else {}
554
- command = ["codespell"]
555
- if fix:
556
- command.append("--write-changes")
557
- for spell_ignore_file in (
558
- ".github/spell-ignore-words.txt",
559
- "spell-ignore-words.txt",
560
- ".spell-ignore-words.txt",
561
- ):
562
- if os.path.exists(spell_ignore_file):
563
- command.append(f"--ignore-words={spell_ignore_file}")
564
- break
565
- dictionaries = codespell_config.get(
566
- "internal_dictionaries", c2cciutils.configuration.CODESPELL_DICTIONARIES_DEFAULT
567
- )
568
- if dictionaries:
569
- command.append("--builtin=" + ",".join(dictionaries))
570
- command += codespell_config.get("arguments", c2cciutils.configuration.CODESPELL_ARGUMENTS_DEFAULT)
571
- return command
572
-
573
-
574
411
  def snyk_exec() -> tuple[str, dict[str, str]]:
575
412
  """Get the Snyk cli executable path."""
576
-
577
413
  if not os.path.exists(os.path.join(os.path.dirname(__file__), "node_modules")):
578
414
  subprocess.run(["npm", "install"], cwd=os.path.dirname(__file__), check=True) # nosec
579
415
 
@@ -587,59 +423,3 @@ def snyk_exec() -> tuple[str, dict[str, str]]:
587
423
  subprocess.run(["snyk", "config", "set", f"org={env['SNYK_ORG']}"], check=True, env=env)
588
424
 
589
425
  return os.path.join(os.path.dirname(os.path.abspath(__file__)), "node_modules/snyk/bin/snyk"), env
590
-
591
-
592
- def create_pull_request_if_needed(
593
- current_branch: str,
594
- new_branch: str,
595
- commit_message: str,
596
- pull_request_extra_arguments: Optional[list[str]] = None,
597
- ) -> bool:
598
- """
599
- Create a pull request if there are changes.
600
- """
601
-
602
- if pull_request_extra_arguments is None:
603
- pull_request_extra_arguments = ["--fill"]
604
-
605
- diff_proc = subprocess.run(["git", "diff", "--quiet"]) # pylint: disable=subprocess-run-check
606
- if diff_proc.returncode != 0:
607
- print("::group::Diff")
608
- sys.stdout.flush()
609
- sys.stderr.flush()
610
- subprocess.run(["git", "diff"], check=True)
611
- print("::endgroup::")
612
-
613
- git_hash = subprocess.run(
614
- ["git", "rev-parse", "HEAD"], check=True, stdout=subprocess.PIPE, encoding="utf-8"
615
- ).stdout.strip()
616
- subprocess.run(["git", "checkout", "-b", new_branch], check=True)
617
- subprocess.run(["git", "add", "--all"], check=True)
618
- subprocess.run(["git", "commit", f"--message={commit_message}"], check=True)
619
- if os.environ.get("TEST") != "TRUE":
620
- subprocess.run(
621
- ["git", "push", "--force", "origin", new_branch],
622
- check=True,
623
- )
624
- env = os.environ.copy()
625
- if "GH_TOKEN" not in env:
626
- if "GITHUB_TOKEN" in env:
627
- env["GH_TOKEN"] = env["GITHUB_TOKEN"]
628
- else:
629
- env["GH_TOKEN"] = str(c2cciutils.gopass("gs/ci/github/token/gopass"))
630
- subprocess.run(
631
- [
632
- "gh",
633
- "pr",
634
- "create",
635
- f"--base={current_branch}",
636
- *pull_request_extra_arguments,
637
- ],
638
- check=True,
639
- env=env,
640
- )
641
- else:
642
- subprocess.run(["git", "reset", "--hard"], check=True)
643
- subprocess.run(["git", "checkout", git_hash], check=True)
644
-
645
- return diff_proc.returncode != 0
@@ -1,4 +1,4 @@
1
1
  # https://docs.renovatebot.com/modules/datasource/#github-releases-datasource
2
- k3d-io/k3d: v5.6.0 # github-releases
3
- postgresql: 14.0.5 # helm - https://charts.bitnami.com/bitnami
2
+ k3d-io/k3d: v5.7.5 # github-releases
3
+ postgresql: 16.0.6 # helm - https://charts.bitnami.com/bitnami
4
4
  helm/chart-releaser: v1.6.1 # github-releases
@@ -4,31 +4,31 @@ Automatically generated file from a JSON schema.
4
4
 
5
5
  from typing import Literal, TypedDict, Union
6
6
 
7
- # Application configuration.
8
- #
9
- # An application configuration
7
+ # | Application configuration.
8
+ # |
9
+ # | An application configuration
10
10
  ApplicationConfiguration = TypedDict(
11
11
  "ApplicationConfiguration",
12
12
  {
13
- # URL pattern.
14
- #
15
- # URL pattern, to be used for files that didn't come from GitHub release, available arguments: {version}
13
+ # | URL pattern.
14
+ # |
15
+ # | URL pattern, to be used for files that didn't come from GitHub release, available arguments: {version}
16
16
  "url-pattern": str,
17
- # The type of file.
18
- #
19
- # The type of file
17
+ # | The type of file.
18
+ # |
19
+ # | The type of file
20
20
  "type": "TheTypeOfFile",
21
- # The filename to get.
22
- #
23
- # The name of the file to get in the GitHub release
21
+ # | The filename to get.
22
+ # |
23
+ # | The name of the file to get in the GitHub release
24
24
  "get-file-name": str,
25
- # The created tile name.
26
- #
27
- # The name of the final tile we will create
25
+ # | The created tile name.
26
+ # |
27
+ # | The name of the final tile we will create
28
28
  "to-file-name": str,
29
- # The tile name to get in the tar file.
29
+ # | The tile name to get in the tar file.
30
30
  "tar-file-name": str,
31
- # The commands to run after the tile creation.
31
+ # | The commands to run after the tile creation.
32
32
  "finish-commands": list[list[str]],
33
33
  },
34
34
  total=False,