Skip to content

Commit

Permalink
Modernize project
Browse files Browse the repository at this point in the history
This patch adds static typing, and it switches to the Hatch package
manager and its Hatchling build backend.
  • Loading branch information
anishathalye committed Dec 28, 2024
1 parent 256babe commit abecc97
Show file tree
Hide file tree
Showing 55 changed files with 874 additions and 823 deletions.
6 changes: 0 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ trim_trailing_whitespace = true

[*.py]
indent_size = 4

[*.bash]
indent_size = 4

[*.yml]
indent_size = 2
36 changes: 20 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
matrix:
os: ["ubuntu-20.04", "macos-latest"]
python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
Expand All @@ -37,8 +36,6 @@ jobs:
- os: "windows-latest"
python: "3.13"
exclude:
- os: "macos-latest"
python: "3.6"
- os: "macos-latest"
python: "3.7"
runs-on: ${{ matrix.os }}
Expand All @@ -50,23 +47,30 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
- name: "Install dependencies"
run: |
python -m pip install --upgrade pip setuptools
python -m pip install tox tox-gh-actions
- name: "Run tests"
run: |
python -m tox
python -m tox -e coverage_report
- uses: pypa/hatch@install
- run: hatch test -v --cover --include python=$(echo ${{ matrix.python }} | tr -d '-') tests
- run: hatch run coverage:xml
- uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
typecheck:
name: Type check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: pypa/hatch@install
- run: hatch run types:check
fmt:
name: Format
runs-on: ubuntu-22.04
name: Format and lint
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
- uses: isort/isort-action@v1
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: pypa/hatch@install
- run: hatch fmt --check
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
*.egg-info
*.pyc
.coverage*
.eggs/
.idea/
.tox/
.venv/
build/
coverage.xml
dist/
htmlcov/
.coverage*
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Note: this changelog only lists feature additions, not bugfixes. For details on
those, see the Git history.

- v1.21
- Drop support for Python 3.6: the minimum version supported is now Python
3.7
- v1.20
- Drop support for Python 2 and old versions of Python 3: the minimum
version supported is now Python 3.6
Expand Down
63 changes: 31 additions & 32 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Contributing
============
# Contributing

All kinds of contributions to Dotbot are greatly appreciated. For someone
unfamiliar with the code base, the most efficient way to contribute is usually
to submit a [feature request](#feature-requests) or [bug report](#bug-reports).
If you want to dive into the source code, you can submit a [patch](#patches) as
well, either working on your own ideas or [existing issues][issues].

Feature Requests
----------------
## Feature Requests

Do you have an idea for an awesome new feature for Dotbot? Please [submit a
feature request][issue]. It's great to hear about new ideas.
Expand All @@ -20,8 +18,7 @@ enhancement to get early feedback on the new feature that you are implementing.
This will help avoid wasted efforts and ensure that your work is incorporated
into the code base.

Bug Reports
-----------
## Bug Reports

Did something go wrong with Dotbot? Sorry about that! Bug reports are greatly
appreciated!
Expand All @@ -31,8 +28,7 @@ as Dotbot version, operating system, configuration file, error messages, and
steps to reproduce the bug. The more details you can include, the easier it is
to find and fix the bug.

Patches
-------
## Patches

Want to hack on Dotbot? Awesome!

Expand All @@ -50,40 +46,41 @@ used in the rest of the project. The version history should be clean, and
commit messages should be descriptive and [properly
formatted][commit-messages].

When preparing a patch, it's recommended that you add unit tests
that demonstrate the bug is fixed (or that the feature works).
You can run the tests on your local machine by installing the `dev` extras.
The steps below do this using a virtual environment:

```shell
# Create a local virtual environment
$ python -m venv .venv

# Activate the virtual environment
# Cygwin, Linux, and MacOS:
$ . .venv/bin/activate
# Windows Powershell:
$ & .venv\Scripts\Activate.ps1
### Testing

# Update pip and setuptools
(.venv) $ python -m pip install -U pip setuptools

# Install dotbot and its development dependencies
(.venv) $ python -m pip install -e .[dev]
When preparing a patch, it's recommended that you add unit tests
that demonstrate the bug is fixed (or that the feature works). You
can run tests on your local machine using [Hatch][hatch]:

# Run the unit tests
(.venv) $ tox
```bash
hatch test
```

If you prefer to run the tests in an isolated container using Docker, you can
do so with the following:

```bash
docker run -it --rm -v "${PWD}:/dotbot" -w /dotbot python:3.13-bookworm /bin/bash
```
docker run -it --rm -v "${PWD}:/dotbot" -w /dotbot python:3.10-alpine /bin/sh

After spawning the container, install Hatch with `pip install hatch`, and then
run the tests.

### Type checking

You can run type checking with:

```bash
hatch run types:check
```

After spawning the container, follow the same instructions as above (create a
virtualenv, ..., run the tests).
### Formatting and linting

You can run the [Ruff][ruff] formatter and linter with:

```bash
hatch fmt
```

---

Expand All @@ -94,3 +91,5 @@ If you have any questions about anything, feel free to [ask][email]!
[fork]: https://github.com/anishathalye/dotbot/fork
[email]: mailto:[email protected]
[commit-messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[hatch]: https://hatch.pypa.io/
[ruff]: https://github.com/astral-sh/ruff
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dotbot [![Build Status](https://github.com/anishathalye/dotbot/workflows/CI/badge.svg)](https://github.com/anishathalye/dotbot/actions?query=workflow%3ACI) [![Coverage](https://codecov.io/gh/anishathalye/dotbot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/anishathalye/dotbot) [![PyPI](https://img.shields.io/pypi/v/dotbot.svg)](https://pypi.org/pypi/dotbot/) [![Python 3.6+](https://img.shields.io/badge/python-3.6%2B-blue)](https://pypi.org/pypi/dotbot/)
# Dotbot [![Build Status](https://github.com/anishathalye/dotbot/workflows/CI/badge.svg)](https://github.com/anishathalye/dotbot/actions?query=workflow%3ACI) [![Coverage](https://codecov.io/gh/anishathalye/dotbot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/anishathalye/dotbot) [![PyPI](https://img.shields.io/pypi/v/dotbot.svg)](https://pypi.org/pypi/dotbot/) [![Python 3.7+](https://img.shields.io/badge/python-3.7%2B-blue)](https://pypi.org/pypi/dotbot/)

Dotbot makes installing your dotfiles as easy as `git clone $url && cd dotfiles
&& ./install`, even on a freshly installed system!
Expand Down
30 changes: 14 additions & 16 deletions bin/dotbot
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,32 @@ exit 1
# python code
import sys, os
import os
import sys
# this file is syntactically valid Python 2; bail out if the interpreter is Python 2
if sys.version_info[0] < 3:
print('error: this version of Dotbot is not compatible with Python 2:\nhttps://github.com/anishathalye/dotbot/wiki/Troubleshooting#python-2')
exit(1)
if sys.version_info < (3, 6):
print('error: this version of Dotbot requires Python 3.6+')
exit(1)
sys.exit(1)
if sys.version_info < (3, 7):
print('error: this version of Dotbot requires Python 3.7+')
sys.exit(1)
PROJECT_ROOT_DIRECTORY = os.path.dirname(
project_root_directory = os.path.dirname(
os.path.dirname(os.path.realpath(__file__)))
def inject(lib_path):
path = os.path.join(PROJECT_ROOT_DIRECTORY, 'lib', lib_path)
path = os.path.join(project_root_directory, 'lib', lib_path)
sys.path.insert(0, path)
inject('pyyaml/lib')
if os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'dotbot')):
if PROJECT_ROOT_DIRECTORY not in sys.path:
sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY)
if os.path.exists(os.path.join(project_root_directory, 'src', 'dotbot')):
src_directory = os.path.join(project_root_directory, 'src')
if src_directory not in sys.path:
sys.path.insert(0, src_directory)
os.putenv('PYTHONPATH', src_directory)
import dotbot
def main():
dotbot.cli.main()
if __name__ == '__main__':
main()
dotbot.cli.main()
4 changes: 0 additions & 4 deletions dotbot/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions dotbot/__main__.py

This file was deleted.

37 changes: 0 additions & 37 deletions dotbot/context.py

This file was deleted.

2 changes: 0 additions & 2 deletions dotbot/messenger/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions dotbot/messenger/level.py

This file was deleted.

62 changes: 0 additions & 62 deletions dotbot/messenger/messenger.py

This file was deleted.

4 changes: 0 additions & 4 deletions dotbot/plugins/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion dotbot/util/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions dotbot/util/string.py

This file was deleted.

Loading

0 comments on commit abecc97

Please sign in to comment.