Skip to content

Commit

Permalink
Migrate poetry -> uv
Browse files Browse the repository at this point in the history
Fix a few minor code things while we're at it.
  • Loading branch information
brndnmtthws committed Jan 15, 2025
1 parent 3371691 commit 1732a20
Show file tree
Hide file tree
Showing 18 changed files with 1,012 additions and 1,661 deletions.
61 changes: 14 additions & 47 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,25 @@ jobs:
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
poetry-version: ["1.4.0"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
- name: Install uv and set the python version with caching
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- name: Install the project
run: uv sync --all-extras --dev

- name: Cache ~/.cache/pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ steps.setup-python.outputs.python-version }}
- name: Cache ~/.cache/pypoetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: python-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install poetry
uses: abatilo/actions-poetry@v4
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
poetry install
- name: Test with pytest
run: |
poetry run py.test
run: uv run py.test

build-and-push:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v4
Expand All @@ -82,33 +65,17 @@ jobs:
if: steps.cache-tws.outputs.cache-hit != 'true'
run: ./extract-installer.sh

- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
- name: Install uv and set the python version with caching
uses: astral-sh/setup-uv@v5
with:
python-version: "3.11"
python-version: 3.11
enable-cache: true

- name: Cache ~/.cache/pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ steps.setup-python.outputs.python-version }}
- name: Cache ~/.cache/pypoetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: python-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install the project
run: uv sync --all-extras

- name: Install poetry
uses: abatilo/actions-poetry@v4
with:
poetry-version: "1.4.0"
- name: Install dependencies
run: |
poetry install --only main --no-root
- name: Build package
run: |
poetry build
run: uv build

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
Expand Down
57 changes: 20 additions & 37 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,40 @@ jobs:
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
poetry-version: ["1.4.0"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5

- name: Install uv and set the python version with caching
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache ~/.cache/pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ steps.setup-python.outputs.python-version }}
- name: Cache ~/.cache/pypoetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: python-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Run image
uses: abatilo/actions-poetry@v4
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
poetry install
enable-cache: true

- name: Install the project
run: uv sync --all-extras --dev

- name: Test with pytest
run: |
poetry run py.test
run: uv run py.test

build-and-publish:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Run image
uses: abatilo/actions-poetry@v4

- name: Install uv and set the python version with caching
uses: astral-sh/setup-uv@v5
with:
poetry-version: "1.4.0"
- name: Install dependencies
run: |
poetry install
python-version: 3.11

- name: Install the project
run: uv sync --all-extras

- name: Build
run: |
poetry build
run: uv build

- name: Publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: |
poetry publish
run: uv publish
41 changes: 15 additions & 26 deletions .github/workflows/python-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,23 @@ jobs:
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
poetry-version: ["1.4.0"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
id: setup-python

- name: Install uv and set the python version with caching
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache ~/.cache/pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ steps.setup-python.outputs.python-version }}
- name: Cache ~/.cache/pypoetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: python-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install poetry
uses: abatilo/actions-poetry@v4
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: |
poetry install
enable-cache: true

- name: Install the project
run: uv sync --all-extras --dev

- name: Test with pytest
run: |
poetry run py.test
- name: Check formatting with black
run: |
poetry run black thetagang --check --diff --color
run: uv run py.test

- name: Check lints with ruff
run: uv run ruff check --diff

- name: Check formatting with ruff
run: uv run ruff format --check --diff
17 changes: 0 additions & 17 deletions .github/workflows/ruff.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.18
hooks:
- id: uv-sync
args: ["--locked", "--all-packages"]
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.18
hooks:
# Update the uv lockfile
- id: uv-lock
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ gateway.

To use the bot, you'll need an Interactive Brokers account with a working
installation of IBC. If you want to modify the bot, you'll need an
installation of Python 3.8 or newer with the
[`poetry`](https://python-poetry.org/) package manager.
installation of Python 3.10 or newer with the
[`uv`](https://docs.astral.sh/uv/) package manager.

One more thing: to run this on a live account, you'll require enough capital
to purchase at least 100 shares of the stocks or ETFs you choose. For
Expand Down Expand Up @@ -292,9 +292,10 @@ recommendations and resources:
Check out the code to your local machine and install the Python dependencies:

```console
poetry install
poetry run autohooks activate
poetry run thetagang -h
# Install the pre-commit hooks
uv run pre-commit instal
# Run thetagang
uv run thetagang -h
```

You are now ready to make a splash! 🐳
Expand Down
12 changes: 6 additions & 6 deletions ibc-config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ SecondFactorDevice=
# and you fail to complete the process before the time limit imposed
# by IBKR, this setting tells IBC whether to automatically restart
# the login sequence, giving you another opportunity to complete
# second factor authentication.
# second factor authentication.
#
# Permitted values are 'yes' and 'no'.
#
Expand Down Expand Up @@ -218,7 +218,7 @@ AcceptNonBrokerageAccountWarning=yes
# This setting controls how long (in seconds) IBC waits for the login
# dialog to appear before restarting TWS.
#
# Note that in normal circumstances with a reasonably specified
# Note that in normal circumstances with a reasonably specified
# computer the time to displaying the login dialog is typically less
# than 20 seconds, and frequently much less. However many factors can
# influence this, and it is unwise to set this value too low.
Expand Down Expand Up @@ -347,7 +347,7 @@ OverrideTwsApiPort=7497
# account security programme, the user will not be asked to perform
# the second factor authentication action, and login to TWS will
# occur automatically in read-only mode: in this mode, placing or
# managing orders is not allowed.
# managing orders is not allowed.
#
# If set to 'no', and the user is enrolled in IB's account security
# programme, the second factor authentication process is handled
Expand Down Expand Up @@ -386,7 +386,7 @@ ReadOnlyApi=no
# accessed. The user can request that the dialog not be shown again.
#
# It is recommended that the user should handle this dialog manually
# rather than using these settings, which are provided for situations
# rather than using these settings, which are provided for situations
# where the user interface is not easily accessible, or where user
# settings are not preserved between sessions (eg some Docker images).
#
Expand Down Expand Up @@ -434,7 +434,7 @@ SendMarketDataInLotsForUSstocks=
# =============================================================================
#
# TWS and Gateway insist on being restarted every day. Two alternative
# automatic options are offered:
# automatic options are offered:
#
# - Auto-Logoff: at a specified time, TWS shuts down tidily, without
# restarting.
Expand Down Expand Up @@ -723,7 +723,7 @@ SuppressInfoMessages=yes
#
# IBC can log information about the structure of windows
# displayed by TWS. This information is useful when adding
# new features to IBC or when behaviour is not as expected.
# new features to IBC or when behaviour is not as expected.
#
# The logged information shows the hierarchical organisation
# of all the components of the window, and includes the
Expand Down
Loading

0 comments on commit 1732a20

Please sign in to comment.