nya-codeblock 0.1.0__tar.gz → 0.1.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.
Files changed (22) hide show
  1. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/PKG-INFO +2 -1
  2. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/pyproject.toml +4 -1
  3. nya_codeblock-0.1.1/src/nya_codeblock/_version.py +1 -0
  4. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/src/nya_codeblock/codeblock.py +10 -5
  5. nya_codeblock-0.1.1/tests/test_codeblocks.py +26 -0
  6. nya_codeblock-0.1.1/tests/test_uncodeblock.py +29 -0
  7. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/uv.lock +13 -0
  8. nya_codeblock-0.1.0/src/nya_codeblock/_version.py +0 -1
  9. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/.editorconfig +0 -0
  10. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/.gitignore +0 -0
  11. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/.gitmodules +0 -0
  12. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/.python-version +0 -0
  13. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/README.md +0 -0
  14. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/pypi-uv-publish.sh/LICENSE +0 -0
  15. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/pypi-uv-publish.sh/README.md +0 -0
  16. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/pypi-uv-publish.sh/publish.sh +0 -0
  17. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/ruff.toml +0 -0
  18. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/src/nya_codeblock/__init__.py +0 -0
  19. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/src/nya_codeblock/__main__.py +0 -0
  20. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/src/nya_codeblock/uncodeblock.py +0 -0
  21. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/tests/__init__.py +0 -0
  22. {nya_codeblock-0.1.0 → nya_codeblock-0.1.1}/tests/test_codeblock.py +0 -0
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nya-codeblock
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Provide helpful functions to convert str into a markdown/discord codeblock. Ported from my own package, tcrutils.
5
5
  Requires-Python: >=3.11
6
+ Requires-Dist: nya-extract-error>=0.1.0
6
7
  Description-Content-Type: text/markdown
7
8
 
8
9
  # nya-codeblock
@@ -4,7 +4,10 @@ dynamic = ['version']
4
4
  description = 'Provide helpful functions to convert str into a markdown/discord codeblock. Ported from my own package, tcrutils.'
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
- dependencies = []
7
+
8
+ dependencies = [ #
9
+ "nya-extract-error>=0.1.0",
10
+ ]
8
11
 
9
12
  [build-system]
10
13
  requires = ["hatchling"]
@@ -0,0 +1 @@
1
+ __version__: str = "0.1.1"
@@ -1,5 +1,7 @@
1
1
  from collections.abc import Callable
2
2
 
3
+ from nya_extract_error import extract_error, extract_traceback
4
+
3
5
  BACKTICK = "`"
4
6
  BACKTICKS = 3 * BACKTICK
5
7
  NEWLINE = "\n"
@@ -62,7 +64,7 @@ def codeblock(
62
64
 
63
65
 
64
66
  def codeblocks(
65
- text0: str,
67
+ text: str,
66
68
  *texts: str,
67
69
  langcodes: tuple[str, ...] | None = None,
68
70
  max_length: int = 1984,
@@ -70,12 +72,15 @@ def codeblocks(
70
72
  smart_empty: bool = True,
71
73
  convert_three_backticks_to_apostrophes: bool = False,
72
74
  ) -> str:
73
- r"""Mutliple-`codeblock()`. For more info read codeblock() docstring.
75
+ r"""Mutliple-`codeblock()`. For more info read `codeblock()` docstring.
76
+
77
+ !!! ⚠️ Warning
78
+ Max length is not guaranteed to be respected, since this is doing codeblock() in a loop, and the lowest amount of characters that can be returned is `((7 + len(langcode)) := len(`"```{langcode}\n```"`)) * len((text, *texts))`, therefore it can overflow max_length by this amount. Set a more conservative max_length or do further processing like a hard cutoff (`output[:2000]`) (breaks formatting, but can be acceptable if doesnt triggerr in 99.9% of cases), or fork/compose this function if you need more control.
74
79
 
75
80
  Args:
76
- text0: The first text to put in the codeblock body.
81
+ text: The first text to put in the codeblock body.
77
82
  *texts: The rest of the texts to put in the codeblock body.
78
- langcodes: The language codes to use in discord codeblock, for example "py". If None, all langcodes will be empty strings. If provided, must be of same length as the total amount of texts passed in including text0.
83
+ langcodes: The language codes to use in discord codeblock, for example "py". If None, all langcodes will be empty strings. If provided, must be of same length as the total amount of all texts passed in (by all texts here i mean `(text, *texts)`).
79
84
  max_length: The maximum length of the output str.
80
85
  fn_cut_at: A Callable[[str, int], str] which's returned string is of or less than the passed in int in length.
81
86
  smart_empty: If true, if `text` is '' (an empty string) it will be changed to ' ' (a space). This prevents the codeblock to think langcode is the body of the codeblock if no text is supplied.
@@ -83,7 +88,7 @@ def codeblocks(
83
88
  Returns:
84
89
  str: A str of the form ```langcode\ntext``` with a length of or less than max_length.
85
90
  """
86
- texts = text0, *texts
91
+ texts = text, *texts
87
92
 
88
93
  if langcodes is None:
89
94
  langcodes: tuple[str, ...] = ("",) * len(texts)
@@ -0,0 +1,26 @@
1
+ from nya_codeblock import codeblocks
2
+
3
+
4
+ def test_codeblocks():
5
+ code1 = "print('Hello, World!')"
6
+ code2 = "print('Goodbye, World!')"
7
+
8
+ result = codeblocks(
9
+ code1,
10
+ code2,
11
+ langcodes=("python", "python"),
12
+ )
13
+
14
+ assert result == f"```python\n{code1}``````python\n{code2}```"
15
+
16
+
17
+ def test_codeblocks_no_langcodes():
18
+ code1 = "print('Hello, World!')"
19
+ code2 = "print('Goodbye, World!')"
20
+
21
+ result = codeblocks(
22
+ code1,
23
+ code2,
24
+ )
25
+
26
+ assert result == f"```\n{code1}``````\n{code2}```"
@@ -0,0 +1,29 @@
1
+ from nya_codeblock import codeblock, uncodeblock
2
+
3
+
4
+ def test_uncodeblock():
5
+ code = "print('Hello, World!')"
6
+ langcode = "python"
7
+ code_block = f"```{langcode}\n{code}\n```"
8
+
9
+ extracted_code = uncodeblock(code_block)
10
+
11
+ assert extracted_code == code
12
+
13
+
14
+ def test_uncodeblock_no_langcode():
15
+ code = "print('Hello, World!')"
16
+ code_block = f"```\n{code}\n```"
17
+
18
+ extracted_code = uncodeblock(code_block)
19
+
20
+ assert extracted_code == code
21
+
22
+
23
+ def test_uncodeblock_from_codeblock():
24
+ code = "print('Hello, World!')"
25
+
26
+ code_block = codeblock(code, langcode="python")
27
+ extracted_code = uncodeblock(code_block)
28
+
29
+ assert extracted_code == code
@@ -23,6 +23,9 @@ wheels = [
23
23
  [[package]]
24
24
  name = "nya-codeblock"
25
25
  source = { editable = "." }
26
+ dependencies = [
27
+ { name = "nya-extract-error" },
28
+ ]
26
29
 
27
30
  [package.dev-dependencies]
28
31
  dev = [
@@ -30,10 +33,20 @@ dev = [
30
33
  ]
31
34
 
32
35
  [package.metadata]
36
+ requires-dist = [{ name = "nya-extract-error", specifier = ">=0.1.0" }]
33
37
 
34
38
  [package.metadata.requires-dev]
35
39
  dev = [{ name = "pytest", specifier = ">=9.1.1" }]
36
40
 
41
+ [[package]]
42
+ name = "nya-extract-error"
43
+ version = "0.1.1"
44
+ source = { registry = "https://pypi.org/simple" }
45
+ sdist = { url = "https://files.pythonhosted.org/packages/7d/05/1eb511b342311eaafeae48d91bb70db33037d4fa242aa4592f26797a0aca/nya_extract_error-0.1.1.tar.gz", hash = "sha256:097a5eb70e59eb58facfbf15518a2495abfa0032e6c78e3e938deba794bb8c63", size = 13880, upload-time = "2026-07-20T09:26:44.157Z" }
46
+ wheels = [
47
+ { url = "https://files.pythonhosted.org/packages/25/33/eaac4e16f3733a4f2e54d063fd8f549a3ad08814fc7461296a5eef63a310/nya_extract_error-0.1.1-py3-none-any.whl", hash = "sha256:bfc6b3025db1f68f89ac251aac6877471c7f781575d83939be9282478966ed42", size = 2199, upload-time = "2026-07-20T09:26:43.262Z" },
48
+ ]
49
+
37
50
  [[package]]
38
51
  name = "packaging"
39
52
  version = "26.2"
@@ -1 +0,0 @@
1
- __version__: str = "0.1.0"
File without changes
File without changes
File without changes
File without changes