baldwin 0.0.7__py3-none-any.whl → 0.0.9__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 baldwin might be problematic. Click here for more details.

baldwin/__init__.py CHANGED
@@ -1,2 +1,4 @@
1
- """Manage a home directory with Git."""
2
- __version__ = '0.0.7'
1
+ """baldwin module."""
2
+ from __future__ import annotations
3
+
4
+ __version__ = '0.0.9'
baldwin/__main__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Main entry point for the Baldwin CLI."""
2
+ from __future__ import annotations
3
+
4
+ from .main import baldwin as main
5
+
6
+ main()
baldwin/lib.py CHANGED
@@ -1,13 +1,14 @@
1
1
  """Baldwin library."""
2
- from collections.abc import Iterable
2
+ from __future__ import annotations
3
+
3
4
  from dataclasses import dataclass
4
- from datetime import UTC, datetime
5
+ from datetime import datetime, timezone
5
6
  from importlib import resources
6
7
  from itertools import chain
7
8
  from pathlib import Path
8
9
  from shlex import quote
9
10
  from shutil import which
10
- from typing import Literal
11
+ from typing import TYPE_CHECKING, Any, Literal
11
12
  import logging
12
13
  import os
13
14
  import subprocess as sp
@@ -15,6 +16,10 @@ import subprocess as sp
15
16
  from binaryornot.check import is_binary
16
17
  from git import Actor, Repo
17
18
  import platformdirs
19
+ import tomlkit
20
+
21
+ if TYPE_CHECKING:
22
+ from collections.abc import Iterable
18
23
 
19
24
  log = logging.getLogger(__name__)
20
25
 
@@ -60,23 +65,31 @@ def init() -> None:
60
65
 
61
66
  def auto_commit() -> None:
62
67
  """Automated commit of changed and untracked files."""
68
+ def can_open(file: Path) -> bool:
69
+ """Check if a file can be opened."""
70
+ try:
71
+ with file.open('rb'):
72
+ pass
73
+ except OSError:
74
+ return False
75
+ return True
76
+
63
77
  repo = get_repo()
64
- diff_items = [Path.home() / e.a_path for e in repo.index.diff(None)
65
- if e.a_path is not None] # pragma: no cover
78
+ diff_items = [Path.home() / e.a_path for e in repo.index.diff(None) if e.a_path is not None]
66
79
  items_to_add = [
67
80
  *[p for p in diff_items if p.exists()], *[
68
- x for x in (Path.home() / y
69
- for y in repo.untracked_files) if x.is_file() and not is_binary(str(x))
81
+ x for x in (Path.home() / y for y in repo.untracked_files)
82
+ if can_open(x) and x.is_file() and not is_binary(str(x))
70
83
  ]
71
84
  ]
72
- items_to_remove = [p for p in diff_items if not p.exists()] # pragma: no cover
85
+ items_to_remove = [p for p in diff_items if not p.exists()]
73
86
  if items_to_add:
74
87
  format_(items_to_add)
75
88
  repo.index.add(items_to_add)
76
89
  if items_to_remove:
77
90
  repo.index.remove(items_to_remove)
78
91
  if items_to_add or items_to_remove or len(repo.index.diff('HEAD')) > 0:
79
- repo.index.commit(f'Automatic commit @ {datetime.now(tz=UTC).isoformat()}',
92
+ repo.index.commit(f'Automatic commit @ {datetime.now(tz=timezone.utc).isoformat()}',
80
93
  committer=Actor('Auto-commiter', 'hgit@tat.sh'))
81
94
 
82
95
 
@@ -95,7 +108,13 @@ def repo_info() -> RepoInfo:
95
108
 
96
109
 
97
110
  def install_units() -> None:
98
- """Install systemd units for automatic committing."""
111
+ """
112
+ Install systemd units for automatic committing.
113
+
114
+ Raises
115
+ ------
116
+ FileNotFoundError
117
+ """
99
118
  bw = which('bw')
100
119
  if not bw:
101
120
  raise FileNotFoundError
@@ -104,8 +123,9 @@ def install_units() -> None:
104
123
  Description=Home directory VCS commit
105
124
 
106
125
  [Service]
107
- Type=oneshot
126
+ Environment=NO_COLOR=1
108
127
  ExecStart={bw} auto-commit
128
+ Type=oneshot
109
129
  """)
110
130
  log.debug('Wrote to `%s`.', service_file)
111
131
  timer_file = Path('~/.config/systemd/user/home-vcs.timer').expanduser()
@@ -136,6 +156,14 @@ def get_git_path() -> Path:
136
156
  return platformdirs.user_data_path('home-git', roaming=True)
137
157
 
138
158
 
159
+ def get_config() -> tomlkit.TOMLDocument | dict[str, Any]:
160
+ """Get the configuration (TOML file)."""
161
+ config_file = platformdirs.user_config_path('baldwin', roaming=True) / 'config.toml'
162
+ if not config_file.exists():
163
+ return {}
164
+ return tomlkit.loads(config_file.read_text())
165
+
166
+
139
167
  def get_repo() -> Repo:
140
168
  """
141
169
  Get a :py:class:`git.Repo` object.
@@ -168,13 +196,18 @@ def format_(filenames: Iterable[Path | str] | None = None,
168
196
  *(x for x in (Path.home() / y for y in repo.untracked_files)
169
197
  if x.is_file() and not is_binary(str(x))))
170
198
  if not (filenames := list(filenames)):
199
+ log.debug('No files to format.')
171
200
  return
172
- with resources.path('baldwin.resources', 'prettier.config.json') as config_file:
173
- if not (prettier := which('prettier')):
174
- return
201
+ if not (prettier := which('prettier')):
202
+ log.debug('Prettier not found in PATH.')
203
+ return
204
+ with resources.path('baldwin.resources', 'prettier.config.json') as default_config_file:
205
+ config_file = get_config().get('baldwin', {
206
+ 'prettier_config': str(default_config_file)
207
+ }).get('prettier_config')
175
208
  # Detect plugins
176
- node_modules_path = (Path(prettier).resolve(strict=True).parent / '..' /
177
- '..').resolve(strict=True)
209
+ node_modules_path = (Path(prettier).resolve(strict=True).parent /
210
+ '../..').resolve(strict=True)
178
211
  cmd_prefix = (prettier, '--config', str(config_file), '--write',
179
212
  '--no-error-on-unmatched-pattern', '--ignore-unknown', '--log-level',
180
213
  log_level, *chain(*(('--plugin', str(fp))
baldwin/main.py CHANGED
@@ -1,28 +1,32 @@
1
+ """Commands."""
2
+ from __future__ import annotations
3
+
1
4
  import logging
2
5
 
3
6
  import click
4
7
 
5
8
  from .lib import (
6
- auto_commit,
9
+ auto_commit as auto_commit_,
7
10
  format_,
8
- git,
9
- init,
10
- install_units,
11
+ git as git_,
12
+ init as init_,
13
+ install_units as install_units_,
11
14
  repo_info,
12
15
  set_git_env_vars,
13
16
  )
17
+ from .utils import setup_logging
14
18
 
15
19
  log = logging.getLogger(__name__)
16
20
 
17
- __all__ = ('baldwin_main', 'git_main')
21
+ __all__ = ('baldwin', 'git')
18
22
 
19
23
 
20
24
  @click.group(context_settings={'help_option_names': ('-h', '--help')})
21
25
  @click.option('-d', '--debug', help='Enable debug logging.', is_flag=True)
22
- def baldwin_main(*, debug: bool = False) -> None:
26
+ def baldwin(*, debug: bool = False) -> None:
23
27
  """Manage a home directory with Git."""
24
28
  set_git_env_vars()
25
- logging.basicConfig(level=logging.DEBUG if debug else logging.ERROR)
29
+ setup_logging(debug=debug)
26
30
 
27
31
 
28
32
  @click.command(context_settings={
@@ -30,31 +34,31 @@ def baldwin_main(*, debug: bool = False) -> None:
30
34
  'ignore_unknown_options': True
31
35
  })
32
36
  @click.argument('args', nargs=-1, type=click.UNPROCESSED)
33
- def git_main(args: tuple[str, ...]) -> None:
37
+ def git(args: tuple[str, ...]) -> None:
34
38
  """Wrap git with git-dir and work-tree passed."""
35
- git(args)
39
+ git_(args)
36
40
 
37
41
 
38
42
  @click.command(context_settings={'help_option_names': ('-h', '--help')})
39
- def init_main() -> None:
43
+ def init() -> None:
40
44
  """Start tracking a home directory."""
41
- init()
45
+ init_()
42
46
 
43
47
 
44
48
  @click.command(context_settings={'help_option_names': ('-h', '--help')})
45
- def auto_commit_main() -> None:
49
+ def auto_commit() -> None:
46
50
  """Automated commit of changed and untracked files."""
47
- auto_commit()
51
+ auto_commit_()
48
52
 
49
53
 
50
54
  @click.command(context_settings={'help_option_names': ('-h', '--help')})
51
- def format_main() -> None:
55
+ def format() -> None: # noqa: A001
52
56
  """Format changed and untracked files."""
53
57
  format_()
54
58
 
55
59
 
56
60
  @click.command(context_settings={'help_option_names': ('-h', '--help')})
57
- def info_main() -> None:
61
+ def info() -> None:
58
62
  """Get basic information about the repository."""
59
63
  data = repo_info()
60
64
  click.echo(f'git-dir path: {data.git_dir_path}')
@@ -62,14 +66,14 @@ def info_main() -> None:
62
66
 
63
67
 
64
68
  @click.command(context_settings={'help_option_names': ('-h', '--help')})
65
- def install_units_main() -> None:
69
+ def install_units() -> None:
66
70
  """Install systemd units for automatic committing."""
67
- install_units()
71
+ install_units_()
68
72
 
69
73
 
70
- baldwin_main.add_command(auto_commit_main, 'auto-commit')
71
- baldwin_main.add_command(format_main, 'format')
72
- baldwin_main.add_command(git_main, 'git')
73
- baldwin_main.add_command(info_main, 'info')
74
- baldwin_main.add_command(init_main, 'init')
75
- baldwin_main.add_command(install_units_main, 'install-units')
74
+ baldwin.add_command(auto_commit)
75
+ baldwin.add_command(format)
76
+ baldwin.add_command(git)
77
+ baldwin.add_command(info)
78
+ baldwin.add_command(init)
79
+ baldwin.add_command(install_units)
baldwin/py.typed ADDED
File without changes
baldwin/utils.py ADDED
@@ -0,0 +1,46 @@
1
+ """Utilities."""
2
+ from __future__ import annotations
3
+
4
+ import logging
5
+ import logging.config
6
+
7
+ log = logging.getLogger(__name__)
8
+
9
+
10
+ def setup_logging(*,
11
+ debug: bool = False,
12
+ force_color: bool = False,
13
+ no_color: bool = False) -> None: # pragma: no cover
14
+ """Set up logging configuration."""
15
+ logging.config.dictConfig({
16
+ 'disable_existing_loggers': True,
17
+ 'root': {
18
+ 'level': 'DEBUG' if debug else 'INFO',
19
+ 'handlers': ['console'],
20
+ },
21
+ 'formatters': {
22
+ 'default': {
23
+ '()': 'colorlog.ColoredFormatter',
24
+ 'force_color': force_color,
25
+ 'format': (
26
+ '%(light_cyan)s%(asctime)s%(reset)s | %(log_color)s%(levelname)-8s%(reset)s | '
27
+ '%(light_green)s%(name)s%(reset)s:%(light_red)s%(funcName)s%(reset)s:'
28
+ '%(blue)s%(lineno)d%(reset)s - %(message)s'),
29
+ 'no_color': no_color,
30
+ }
31
+ },
32
+ 'handlers': {
33
+ 'console': {
34
+ 'class': 'colorlog.StreamHandler',
35
+ 'formatter': 'default',
36
+ }
37
+ },
38
+ 'loggers': {
39
+ 'baldwin': {
40
+ 'level': 'DEBUG' if debug else 'INFO',
41
+ 'handlers': ['console'],
42
+ 'propagate': False,
43
+ }
44
+ },
45
+ 'version': 1
46
+ })
@@ -0,0 +1,18 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 baldwin authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18
+ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,30 +1,37 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: baldwin
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: Simple tracking of your home directory with easy-to-read diffs.
5
5
  License: MIT
6
6
  Keywords: command line,file management,git,version control
7
7
  Author: Andrew Udvare
8
8
  Author-email: audvare@gmail.com
9
- Requires-Python: >=3.12,<4
9
+ Requires-Python: >=3.10,<3.14
10
10
  Classifier: Development Status :: 2 - Pre-Alpha
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: MIT License
13
13
  Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
14
16
  Classifier: Programming Language :: Python :: 3.12
15
17
  Classifier: Programming Language :: Python :: 3.13
16
18
  Classifier: Typing :: Typed
17
19
  Requires-Dist: binaryornot (>=0.4.4,<0.5.0)
18
20
  Requires-Dist: click (>=8.1.8,<9.0.0)
21
+ Requires-Dist: colorlog (>=6.9.0,<7.0.0)
19
22
  Requires-Dist: gitpython (>=3.1.44,<4.0.0)
20
23
  Requires-Dist: platformdirs (>=4.3.6,<5.0.0)
24
+ Requires-Dist: tomlkit (>=0.13.2,<0.14.0)
25
+ Requires-Dist: typing-extensions (>=4.13.2,<5.0.0)
21
26
  Project-URL: Documentation, https://baldwin.readthedocs.org
27
+ Project-URL: Homepage, https://tatsh.github.io/baldwin/
28
+ Project-URL: Issues, https://github.com/Tatsh/baldwin/issues
22
29
  Project-URL: Repository, https://github.com/Tatsh/baldwin
23
- Project-URL: issues, https://github.com/Tatsh/baldwin/issues
24
30
  Description-Content-Type: text/markdown
25
31
 
26
32
  # Simple home directory versioning
27
33
 
34
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
28
35
  [![QA](https://github.com/Tatsh/baldwin/actions/workflows/qa.yml/badge.svg)](https://github.com/Tatsh/baldwin/actions/workflows/qa.yml)
29
36
  [![Tests](https://github.com/Tatsh/baldwin/actions/workflows/tests.yml/badge.svg)](https://github.com/Tatsh/baldwin/actions/workflows/tests.yml)
30
37
  [![Coverage Status](https://coveralls.io/repos/github/Tatsh/baldwin/badge.svg?branch=master)](https://coveralls.io/github/Tatsh/baldwin?branch=master)
@@ -32,7 +39,9 @@ Description-Content-Type: text/markdown
32
39
  ![PyPI - Version](https://img.shields.io/pypi/v/baldwin)
33
40
  ![GitHub tag (with filter)](https://img.shields.io/github/v/tag/Tatsh/baldwin)
34
41
  ![GitHub](https://img.shields.io/github/license/Tatsh/baldwin)
35
- ![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/baldwin/v0.0.7/master)
42
+ ![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/baldwin/v0.0.9/master)
43
+
44
+ [![@Tatsh](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpublic.api.bsky.app%2Fxrpc%2Fapp.bsky.actor.getProfile%2F%3Factor%3Ddid%3Aplc%3Auq42idtvuccnmtl57nsucz72%26query%3D%24.followersCount%26style%3Dsocial%26logo%3Dbluesky%26label%3DFollow%2520%40Tatsh&query=%24.followersCount&style=social&logo=bluesky&label=Follow%20%40Tatsh)](https://bsky.app/profile/tatsh.bsky.social)
36
45
 
37
46
  This is a conversion of my simple scripts to version my home directory with very specific excludes
38
47
  and formatting every file upon commit so that readable diffs can be generated.
@@ -0,0 +1,14 @@
1
+ baldwin/__init__.py,sha256=pPCFLb4adFkSqhONgCTDYBp-kFFmxVzic80FQZzio4o,80
2
+ baldwin/__main__.py,sha256=vLM990SXfS71YjwD7vs3TN8UMe03UrgzA2tvKwjV9bk,122
3
+ baldwin/lib.py,sha256=nGWjtmbk8CkCevQ0qDv4UxM_vjYqGE1hCClp9cAfZQ0,8371
4
+ baldwin/main.py,sha256=JGbHj6ZRas-acoNHFH1Lmbp4-d96d9X5SWpN8fqz1qA,2073
5
+ baldwin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ baldwin/resources/default_gitattributes.txt,sha256=uGoWTSVgPmdGB2EUIROkTz3FikGpNGhdS95SuuvoCRo,984
7
+ baldwin/resources/default_gitignore.txt,sha256=oyxukNyK6F778C2jc7oIwosP7ou1WTdbuWwkpgGZtJA,3022
8
+ baldwin/resources/prettier.config.json,sha256=-Hher3B02YflULYn0IYOG_a-rDxpaaaQ0QXD30-5IgQ,387
9
+ baldwin/utils.py,sha256=4lcYY7DErJS5GWh3utf1d697ZIMw6Q1GEEf6NCeSdak,1420
10
+ baldwin-0.0.9.dist-info/LICENSE.txt,sha256=Y6e04wkVzxa82z5bhkF3-38WGKbISh0E28Eo0IxiOBU,1082
11
+ baldwin-0.0.9.dist-info/METADATA,sha256=c0AB0Cnq_8sQC4tjxsehdgJJ-pQAJTyOp7P5bC4nCU8,5309
12
+ baldwin-0.0.9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
+ baldwin-0.0.9.dist-info/entry_points.txt,sha256=16CO-Z2MW3o6hkxwJplFgnyJuHuTngwrPqCNdSQAOcc,65
14
+ baldwin-0.0.9.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.0.1
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ bw=baldwin.main:baldwin
3
+ hgit=baldwin.main:git
4
+
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 baldwin authors
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
13
- all 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
21
- THE SOFTWARE.
@@ -1,11 +0,0 @@
1
- baldwin/__init__.py,sha256=XBpZev4nqfkkKQd5YUoqlcJK0kO9lxPH48gypaHnU7c,62
2
- baldwin/lib.py,sha256=_-lFY5lXRDRMYpUgWvAuC-3ljYwMDSLaUvWjOX1QIWE,7494
3
- baldwin/main.py,sha256=08a70OZLyRBamntbCdhhBNKSk9mywu_2M085I_mDa-s,2131
4
- baldwin/resources/default_gitattributes.txt,sha256=uGoWTSVgPmdGB2EUIROkTz3FikGpNGhdS95SuuvoCRo,984
5
- baldwin/resources/default_gitignore.txt,sha256=oyxukNyK6F778C2jc7oIwosP7ou1WTdbuWwkpgGZtJA,3022
6
- baldwin/resources/prettier.config.json,sha256=-Hher3B02YflULYn0IYOG_a-rDxpaaaQ0QXD30-5IgQ,387
7
- baldwin-0.0.7.dist-info/LICENSE.txt,sha256=TDfksi5bdmmL5cu6tAiN1iL7k38hWR2KbUg0JkASPO4,1082
8
- baldwin-0.0.7.dist-info/METADATA,sha256=thCF46_lMihnW2-ONI3bOjyJgY2qCgcw0Qmw3c1EGbU,4487
9
- baldwin-0.0.7.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
10
- baldwin-0.0.7.dist-info/entry_points.txt,sha256=1PNIgkO4Pmvb8BFPHPNzNHJtfRMqkbzaUWpBWPPmEhs,75
11
- baldwin-0.0.7.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- [console_scripts]
2
- bw=baldwin.main:baldwin_main
3
- hgit=baldwin.main:git_main
4
-