randfacts 0.23.0__tar.gz → 0.24.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.
@@ -1,5 +1,5 @@
1
1
  MIT License
2
- Copyright (c) 2020-2024 Connor Sample
2
+ Copyright (c) 2020-2026 Connor Sample
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
5
5
  in the Software without restriction, including without limitation the rights
@@ -1,17 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: randfacts
3
- Version: 0.23.0
3
+ Version: 0.24.1
4
4
  Summary: Package to generate random facts
5
- License: MIT
6
- License-File: LICENSE
5
+ Keywords: facts,random,generator,trivia,cli,dataset
7
6
  Author: TabulateJarl8
8
- Author-email: tabulatejarl8@gmail.com
9
- Requires-Python: >=3.6,<4.0
10
- Classifier: Development Status :: 5 - Production/Stable
11
- Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Natural Language :: English
14
- Classifier: Operating System :: OS Independent
7
+ Author-email: TabulateJarl8 <tabulatejarl8@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
15
10
  Classifier: Programming Language :: Python :: 3
16
11
  Classifier: Programming Language :: Python :: 3.6
17
12
  Classifier: Programming Language :: Python :: 3.7
@@ -22,10 +17,22 @@ Classifier: Programming Language :: Python :: 3.11
22
17
  Classifier: Programming Language :: Python :: 3.12
23
18
  Classifier: Programming Language :: Python :: 3.13
24
19
  Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Natural Language :: English
21
+ Classifier: License :: OSI Approved :: MIT License
22
+ Classifier: Operating System :: OS Independent
23
+ Classifier: Development Status :: 5 - Production/Stable
24
+ Classifier: Environment :: Console
25
+ Classifier: Intended Audience :: Developers
26
+ Classifier: Intended Audience :: End Users/Desktop
27
+ Classifier: Topic :: Games/Entertainment
28
+ Classifier: Topic :: Education
25
29
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
- Requires-Dist: importlib-metadata (>=1.4,<2.0) ; python_version < "3.8"
27
- Project-URL: Homepage, https://tabulate.tech/software/randfacts/
28
- Project-URL: Repository, https://github.com/TabulateJarl8/randfacts
30
+ Requires-Dist: dataclasses>=0.8 ; python_full_version == '3.6.*'
31
+ Requires-Dist: importlib-metadata>=4.8.3 ; python_full_version < '3.8'
32
+ Requires-Python: >=3.6
33
+ Project-URL: homepage, https://tabulate.tech/software/randfacts/
34
+ Project-URL: repository, https://github.com/TabulateJarl8/randfacts
35
+ Project-URL: issues, https://github.com/TabulateJarl8/randfacts/issues
29
36
  Description-Content-Type: text/markdown
30
37
 
31
38
  <p align="center">
@@ -52,20 +59,32 @@ Randfacts is a Python module that generates random facts. You can use `randfacts
52
59
 
53
60
  randfacts can either be installed via pip or via the AUR, whichever way you prefer.
54
61
 
55
- ### Installation via pip:
62
+ ### Installation via uv/pipx/pip:
56
63
 
57
64
  ```sh
65
+ # Install with UV:
66
+ $ uv tool install randfacts
67
+
68
+ # Or just try it out:
69
+ $ uvx randfacts
70
+
71
+ # Install with pipx:
72
+ $ pipx install randfacts
73
+
74
+ # Install with bare pip:
58
75
  $ pip3 install randfacts
59
76
  ```
60
77
 
61
78
  ### Installation via AUR:
62
79
 
63
80
  Via your AUR helper, like paru:
81
+
64
82
  ```sh
65
83
  $ paru -S python-randfacts
66
84
  ```
67
85
 
68
86
  Or manually
87
+
69
88
  ```sh
70
89
  $ git clone https://aur.archlinux.org/python-randfacts.git && cd python-randfacts
71
90
  $ makepkg -si
@@ -78,10 +97,12 @@ import randfacts
78
97
  x = randfacts.get_fact()
79
98
  print(x)
80
99
  ```
100
+
81
101
  The above example will print a random fact like:
82
102
  `Penguins can't taste sweet or savory flavors, only sour and salty ones`
83
103
 
84
104
  This package has a filter option to filter out potentially inappropriate facts. The filter is on by default. To disable the filter, you can just set the `filter_enabled` parameter to `False`.
105
+
85
106
  ```python
86
107
  from randfacts import get_fact
87
108
  print(get_fact(False))
@@ -97,7 +118,6 @@ print(get_fact(only_unsafe=True))
97
118
 
98
119
  If you want to access the list of facts directly, you can just import the `safe_facts`, `unsafe_facts`, or `all_facts` lists from the randfacts module.
99
120
 
100
-
101
121
  ## Command line usage
102
122
 
103
123
  randfacts can be executed via the command line with the following commands:
@@ -126,3 +146,28 @@ More help.
126
146
  $ python3 -m randfacts --help
127
147
  ```
128
148
 
149
+ # Contributing
150
+
151
+ Contributions are welcome, this project uses [uv](https://github.com/astral-sh/uv) to manage it's dependencies, so setup is very simple.
152
+
153
+ ## Development Setup
154
+
155
+ 1. Make sure uv is properly installed
156
+ 2. Fork and clone the repository with `git clone git@github.com:your-username/randfacts.git`
157
+ 3. Install dependencies with `uv sync --dev`
158
+ 4. After making changes, ensure the tests pass, and add any unit tests needed to bring code coverage to 100% with the following command:
159
+
160
+ ```sh
161
+ # check everything, if you're just working on one particular issue,
162
+ # see the Makefile for more granular tasks
163
+ make check-all
164
+ ```
165
+
166
+ ## Duplicate facts test
167
+
168
+ I've created a fairly complex duplicate fact detection test in Rust. It will be easier to run on your machine to check/fix any issues, but it also runs in CI if you don't want to set up Rust. It can be run with the following:
169
+
170
+ ```sh
171
+ cd tests/checkduplicates
172
+ cargo run --release
173
+ ```
@@ -22,20 +22,32 @@ Randfacts is a Python module that generates random facts. You can use `randfacts
22
22
 
23
23
  randfacts can either be installed via pip or via the AUR, whichever way you prefer.
24
24
 
25
- ### Installation via pip:
25
+ ### Installation via uv/pipx/pip:
26
26
 
27
27
  ```sh
28
+ # Install with UV:
29
+ $ uv tool install randfacts
30
+
31
+ # Or just try it out:
32
+ $ uvx randfacts
33
+
34
+ # Install with pipx:
35
+ $ pipx install randfacts
36
+
37
+ # Install with bare pip:
28
38
  $ pip3 install randfacts
29
39
  ```
30
40
 
31
41
  ### Installation via AUR:
32
42
 
33
43
  Via your AUR helper, like paru:
44
+
34
45
  ```sh
35
46
  $ paru -S python-randfacts
36
47
  ```
37
48
 
38
49
  Or manually
50
+
39
51
  ```sh
40
52
  $ git clone https://aur.archlinux.org/python-randfacts.git && cd python-randfacts
41
53
  $ makepkg -si
@@ -48,10 +60,12 @@ import randfacts
48
60
  x = randfacts.get_fact()
49
61
  print(x)
50
62
  ```
63
+
51
64
  The above example will print a random fact like:
52
65
  `Penguins can't taste sweet or savory flavors, only sour and salty ones`
53
66
 
54
67
  This package has a filter option to filter out potentially inappropriate facts. The filter is on by default. To disable the filter, you can just set the `filter_enabled` parameter to `False`.
68
+
55
69
  ```python
56
70
  from randfacts import get_fact
57
71
  print(get_fact(False))
@@ -67,7 +81,6 @@ print(get_fact(only_unsafe=True))
67
81
 
68
82
  If you want to access the list of facts directly, you can just import the `safe_facts`, `unsafe_facts`, or `all_facts` lists from the randfacts module.
69
83
 
70
-
71
84
  ## Command line usage
72
85
 
73
86
  randfacts can be executed via the command line with the following commands:
@@ -95,3 +108,29 @@ More help.
95
108
  ```sh
96
109
  $ python3 -m randfacts --help
97
110
  ```
111
+
112
+ # Contributing
113
+
114
+ Contributions are welcome, this project uses [uv](https://github.com/astral-sh/uv) to manage it's dependencies, so setup is very simple.
115
+
116
+ ## Development Setup
117
+
118
+ 1. Make sure uv is properly installed
119
+ 2. Fork and clone the repository with `git clone git@github.com:your-username/randfacts.git`
120
+ 3. Install dependencies with `uv sync --dev`
121
+ 4. After making changes, ensure the tests pass, and add any unit tests needed to bring code coverage to 100% with the following command:
122
+
123
+ ```sh
124
+ # check everything, if you're just working on one particular issue,
125
+ # see the Makefile for more granular tasks
126
+ make check-all
127
+ ```
128
+
129
+ ## Duplicate facts test
130
+
131
+ I've created a fairly complex duplicate fact detection test in Rust. It will be easier to run on your machine to check/fix any issues, but it also runs in CI if you don't want to set up Rust. It can be run with the following:
132
+
133
+ ```sh
134
+ cd tests/checkduplicates
135
+ cargo run --release
136
+ ```
@@ -1,13 +1,16 @@
1
- [tool.poetry]
1
+ [project]
2
2
  name = "randfacts"
3
- version = "0.23.0"
3
+ version = "0.24.1"
4
4
  description = "Package to generate random facts"
5
- authors = ["TabulateJarl8 <tabulatejarl8@gmail.com>"]
6
- license = "MIT"
7
5
  readme = "README.md"
8
- include = ["randfacts/*.txt"]
9
- homepage = "https://tabulate.tech/software/randfacts/"
10
- repository = "https://github.com/TabulateJarl8/randfacts"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "TabulateJarl8", email = "tabulatejarl8@gmail.com" }]
9
+ requires-python = ">=3.6"
10
+ dependencies = [
11
+ "dataclasses>=0.8 ; python_full_version == '3.6.*'",
12
+ "importlib-metadata>=4.8.3 ; python_full_version < '3.8'",
13
+ ]
11
14
  classifiers = [
12
15
  "Programming Language :: Python :: 3",
13
16
  "Programming Language :: Python :: 3.6",
@@ -23,42 +26,51 @@ classifiers = [
23
26
  "License :: OSI Approved :: MIT License",
24
27
  "Operating System :: OS Independent",
25
28
  "Development Status :: 5 - Production/Stable",
29
+ "Environment :: Console",
26
30
  "Intended Audience :: Developers",
31
+ "Intended Audience :: End Users/Desktop",
32
+ "Topic :: Games/Entertainment",
33
+ "Topic :: Education",
27
34
  "Topic :: Software Development :: Libraries :: Python Modules",
28
35
  ]
29
- packages = [{ include = 'randfacts' }]
36
+ keywords = ["facts", "random", "generator", "trivia", "cli", "dataset"]
37
+
38
+ [project.urls]
39
+ homepage = "https://tabulate.tech/software/randfacts/"
40
+ repository = "https://github.com/TabulateJarl8/randfacts"
41
+ issues = "https://github.com/TabulateJarl8/randfacts/issues"
42
+
43
+ [project.scripts]
44
+ randfacts = "randfacts.__main__:cli_entrypoint"
30
45
 
31
- [tool.poetry.scripts]
32
- randfacts = 'randfacts.randfacts:_cli_entrypoint'
46
+ [tool.uv.build-backend]
47
+ source-include = ["src/randfacts/*.txt"]
33
48
 
34
- [tool.pyright]
35
- reportUnusedCallResult = false
49
+ [dependency-groups]
50
+ dev = [
51
+ "ruff~=0.7.4 ; python_full_version >= '3.7' and python_full_version < '3.9'",
52
+ "ruff>=0.14.14 ; python_full_version >= '3.9'",
53
+ "pytest>=9.0.2 ; python_full_version >= '3.10'",
54
+ "pytest~=8.3.3 ; python_full_version >= '3.8' and python_full_version < '3.10'",
55
+ "pytest~=6.2.0 ; python_full_version >= '3.6' and python_full_version < '3.8'",
56
+ "pytest-cov>=7.0.0 ; python_full_version >= '3.9'",
57
+ "pytest-cov~=5.0.0 ; python_full_version == '3.8.*'",
58
+ "pytest-cov~=4.0.0 ; python_full_version >= '3.6' and python_full_version < '3.8'",
59
+ "mypy>=1.19.1 ; python_full_version >= '3.9'",
60
+ "mypy~=1.14.0 ; python_full_version == '3.8.*'",
61
+ "mypy~=1.4.0 ; python_full_version == '3.7.*'",
62
+ ]
63
+
64
+ [tool.ruff]
65
+ target-version = "py37"
36
66
 
37
67
  [tool.ruff.lint]
38
68
  preview = true
39
69
  select = ["ALL"]
40
-
41
70
  ignore = [
42
- # complains about tab indentation
43
- "W191",
44
- "D206",
45
- # adds a line break before a class docstring
46
- "D203",
47
- # puts the first line summary of a docstring on a different line than the """
48
- "D213",
49
- # tries to add a blank line after the last docstring section
50
- "D413",
51
71
  # yells at you if you use a bool typed function argument
52
72
  "FBT001",
53
73
  "FBT002",
54
- # yells at you for using try-except in a for loop
55
- "PERF203",
56
- # allow for the use of Any
57
- "ANN401",
58
- # false positives for overriding methods (i think)
59
- "PLR6301",
60
- # disable too many branches check
61
- "PLR0912",
62
74
  # copyright at top of file
63
75
  "CPY",
64
76
  # complains about random.choice() not being good for cryptography
@@ -77,16 +89,14 @@ ignore = [
77
89
  "DOC",
78
90
  "INP001",
79
91
  "S",
92
+ "FA100",
80
93
  ]
81
- "randfacts/randfacts.py" = ["T201"]
82
- "randfacts/__main__.py" = ["D100"]
94
+ "src/randfacts/__main__.py" = ["T201"]
83
95
 
84
96
  [tool.ruff.lint.pydocstyle]
85
97
  convention = "google"
86
98
 
87
99
  [tool.ruff.format]
88
- quote-style = "double"
89
- indent-style = "tab"
90
100
  line-ending = "lf"
91
101
 
92
102
  [tool.ruff.lint.isort]
@@ -94,40 +104,15 @@ combine-as-imports = true
94
104
  force-wrap-aliases = true
95
105
  order-by-type = true
96
106
 
97
- [tool.poetry.dependencies]
98
- python = "^3.6"
99
- importlib-metadata = { version = "^1.4", python = "<3.8" }
100
-
101
- [tool.poetry.group.dev.dependencies]
102
- ruff = [
103
- { version = "^0.14.11", python = "^3.9" },
104
- { version = "^0.7.4", python = ">=3.7,<3.9" },
105
- ]
106
- pytest = [
107
- { version = "^9.0.2", python = "^3.10" },
108
- { version = "^8.3.3", python = ">=3.9,<3.10" },
109
- { version = "^6.2.0", python = ">=3.6,<3.8" },
110
- ]
111
- pytest-cov = [
112
- { version = "^7.0.0", python = "^3.9" },
113
- { version = "^5.0.0", python = ">=3.8,<3.9" },
114
- { version = "^4.0.0", python = ">=3.6,<3.8" },
115
- ]
116
- mypy = [
117
- { version = "^1.19.1", python = "^3.9" },
118
- { version = "~1.14.0", python = ">=3.8,<3.9" },
119
- { version = "~1.4.0", python = ">=3.7,<3.8" },
120
- ]
121
-
122
107
  [tool.coverage.run]
123
108
  omit = ["randfacts/__main__.py"]
124
109
 
125
- # legacy import: ingore types
110
+ # legacy import: ignore types
126
111
  [tool.mypy]
127
112
  [[tool.mypy.overrides]]
128
113
  module = "importlib_metadata.*"
129
114
  ignore_missing_imports = true
130
115
 
131
116
  [build-system]
132
- requires = ["poetry-core"]
133
- build-backend = "poetry.core.masonry.api"
117
+ requires = ["uv_build>=0.9.26,<0.10.0"]
118
+ build-backend = "uv_build"
@@ -0,0 +1,48 @@
1
+ """Module to generate random facts.
2
+
3
+ randfacts provides an interface to a list of facts installed with the module.
4
+ You can retrieve facts via the `get_fact` method. randfacts also allows for
5
+ execution via the command line. See the examples section for more details.
6
+
7
+ # Examples:
8
+ To use randfacts in your Python code:
9
+
10
+ ```py
11
+ >>> import randfacts
12
+
13
+ # Generate a random SFW (safe for work) fact:
14
+ >>> randfacts.get_fact()
15
+
16
+ # Generate a random NSFW (not safe for work) fact.
17
+ >>> randfacts.get_fact(only_unsafe=True)
18
+
19
+ # Generate a random mixed fact (possibility of both SFW and NSFW facts)
20
+ >>> randfacts.get_fact(filter_enabled=False)
21
+ ```
22
+
23
+ # CLI Examples:
24
+ randfacts can be executed via the command line with the following options:
25
+
26
+ ```sh
27
+ $ python3 -m randfacts # normal execution; only safe facts
28
+ $ python3 -m randfacts --unsafe # only unsafe facts
29
+ $ python3 -m randfacts --mixed # possibility of both SFW and NSFW facts
30
+ $ python3 -m randfacts --help # show CLI help
31
+ ```
32
+ """
33
+
34
+ from randfacts.randfacts import (
35
+ __version__,
36
+ all_facts,
37
+ get_fact,
38
+ safe_facts,
39
+ unsafe_facts,
40
+ )
41
+
42
+ __all__ = [
43
+ "__version__",
44
+ "all_facts",
45
+ "get_fact",
46
+ "safe_facts",
47
+ "unsafe_facts",
48
+ ]
@@ -0,0 +1,66 @@
1
+ """Main CLI entrypoint for randfacts."""
2
+
3
+ import argparse
4
+ from dataclasses import dataclass
5
+
6
+ from randfacts import __version__, get_fact
7
+
8
+
9
+ @dataclass
10
+ class RandfactsNamespace(argparse.Namespace):
11
+ """Dataclass representing randfacts CLI options.
12
+
13
+ Attributes:
14
+ version (bool): whether or not to display the version
15
+ mixed (bool): whether or not to include both safe and unsafe facts
16
+ unsafe (bool): whether or not to only show unsafe facts
17
+ """
18
+
19
+ version: bool
20
+ mixed: bool
21
+ unsafe: bool
22
+
23
+
24
+ def cli_entrypoint() -> None:
25
+ """Entrypoint for execution via command-line."""
26
+ parser = argparse.ArgumentParser(
27
+ description="Generate random facts from the command-line",
28
+ )
29
+
30
+ _ = parser.add_argument(
31
+ "-V",
32
+ "--version",
33
+ action="store_true",
34
+ help="Print the package version and exit",
35
+ )
36
+
37
+ group = parser.add_mutually_exclusive_group()
38
+ _ = group.add_argument(
39
+ "-m",
40
+ "--mixed",
41
+ action="store_true",
42
+ help="Include safe and unsafe facts",
43
+ )
44
+
45
+ _ = group.add_argument(
46
+ "-u",
47
+ "--unsafe",
48
+ action="store_true",
49
+ help="Only include unsafe facts",
50
+ )
51
+
52
+ args = parser.parse_args(namespace=RandfactsNamespace)
53
+
54
+ if args.version:
55
+ print(__version__)
56
+ return
57
+ if args.mixed:
58
+ print(get_fact(filter_enabled=False))
59
+ elif args.unsafe:
60
+ print(get_fact(only_unsafe=True))
61
+ else:
62
+ print(get_fact())
63
+
64
+
65
+ if __name__ == "__main__":
66
+ cli_entrypoint()
@@ -0,0 +1,42 @@
1
+ """Contains the core functionality of randfacts."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+ from random import choice
6
+
7
+ if sys.version_info >= (3, 8):
8
+ from importlib import metadata
9
+ else: # pragma: no cover
10
+ import importlib_metadata as metadata # pyright: ignore[reportUnreachable]
11
+
12
+ __version__: str = metadata.version("randfacts")
13
+
14
+ dir_path = Path(__file__).resolve().parent
15
+
16
+ with (dir_path / "safe.txt").open(encoding="utf-8") as f:
17
+ safe_facts = [fact.rstrip("\r\n ") for fact in f if fact.rstrip("\r\n ")]
18
+
19
+ with (dir_path / "unsafe.txt").open(encoding="utf-8") as f:
20
+ unsafe_facts = [fact.rstrip("\r\n ") for fact in f if fact.rstrip("\r\n ")]
21
+
22
+ all_facts = safe_facts + unsafe_facts
23
+
24
+
25
+ def get_fact(filter_enabled: bool = True, only_unsafe: bool = False) -> str:
26
+ """This function returns a random fact.
27
+
28
+ Args:
29
+ filter_enabled (bool): The `filter_enabled` parameter determines if the function
30
+ will filter out potentially inappropriate facts. Defaults to True.
31
+ only_unsafe (bool): The `only_unsafe` parameter determines if the function will
32
+ only give unsafe (NSFW) facts. Takes precedence over the
33
+ `filter_enabled` argument.
34
+
35
+ Returns:
36
+ str: A random fact.
37
+ """
38
+ if only_unsafe:
39
+ return choice(unsafe_facts)
40
+ if not filter_enabled:
41
+ return choice(all_facts)
42
+ return choice(safe_facts)