Skip to content

Commit

Permalink
feat: adapt to mojo v24.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Prodesire committed Aug 2, 2024
1 parent 2539098 commit 4572186
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 40 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Build and Release
env:
PACKAGE_NAME: morrow.mojopkg
MORROW_SRC: morrow
MOJO_HOME: /home/runner/.modular/pkg/packages.modular.com_mojo/bin

on: workflow_dispatch

Expand All @@ -18,10 +17,23 @@ jobs:
run: |
curl https://get.modular.com | MODULAR_AUTH=${{ secrets.MODULAR_AUTH }} sh -
modular auth ${{ secrets.MODULAR_AUTH }}
modular install mojo
python3 -m venv ~/max-venv && source ~/max-venv/bin/activate
modular install max
MAX_PATH=$(modular config max.path) \
&& python3 -m pip install --find-links $MAX_PATH/wheels max-engine
MAX_PATH=$(modular config max.path) \
&& BASHRC=$( [ -f "$HOME/.bash_profile" ] && echo "$HOME/.bash_profile" || echo "$HOME/.bashrc" ) \
&& echo 'export MODULAR_HOME="'$HOME'/.modular"' >> "$BASHRC" \
&& echo 'export PATH="'$MAX_PATH'/bin:$PATH"' >> "$BASHRC" \
&& source "$BASHRC"
- name: Build
run: |
${{ env.MOJO_HOME }}/mojo package ${{ env.MORROW_SRC }} -o ${{ github.workspace }}/${{ env.PACKAGE_NAME }}
MAX_PATH=$(modular config max.path) \
&& BASHRC=$( [ -f "$HOME/.bash_profile" ] && echo "$HOME/.bash_profile" || echo "$HOME/.bashrc" ) \
&& echo 'export MODULAR_HOME="'$HOME'/.modular"' >> "$BASHRC" \
&& echo 'export PATH="'$MAX_PATH'/bin:$PATH"' >> "$BASHRC" \
&& source "$BASHRC"
mojo package ${{ env.MORROW_SRC }} -o ${{ github.workspace }}/${{ env.PACKAGE_NAME }}
- name: Upload package
uses: actions/upload-artifact@v3
with:
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on: [pull_request, push]
env:
PACKAGE_NAME: morrow.mojopkg
MORROW_SRC: morrow
MOJO_HOME: /home/runner/.modular/pkg/packages.modular.com_mojo/bin

jobs:
test:
Expand All @@ -18,7 +17,15 @@ jobs:
run: |
curl https://get.modular.com | MODULAR_AUTH=${{ secrets.MODULAR_AUTH }} sh -
modular auth ${{ secrets.MODULAR_AUTH }}
modular install mojo
python3 -m venv ~/max-venv && source ~/max-venv/bin/activate
modular install max
MAX_PATH=$(modular config max.path) \
&& python3 -m pip install --find-links $MAX_PATH/wheels max-engine
- name: Test
run: |
${{ env.MOJO_HOME }}/mojo run test.mojo
MAX_PATH=$(modular config max.path) \
&& BASHRC=$( [ -f "$HOME/.bash_profile" ] && echo "$HOME/.bash_profile" || echo "$HOME/.bashrc" ) \
&& echo 'export MODULAR_HOME="'$HOME'/.modular"' >> "$BASHRC" \
&& echo 'export PATH="'$MAX_PATH'/bin:$PATH"' >> "$BASHRC" \
&& source "$BASHRC"
mojo run test.mojo
2 changes: 1 addition & 1 deletion morrow/__init__.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ from .morrow import Morrow
from .timezone import TimeZone
from .timedelta import TimeDelta

alias __version__ = "0.3.1"
alias __version__ = "0.4.0"
3 changes: 3 additions & 0 deletions morrow/constants.mojo
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from utils import StaticTuple


# todo: hardcode for tmp
alias _MAX_TIMESTAMP: Int = 32503737600
alias MAX_TIMESTAMP = _MAX_TIMESTAMP
Expand Down
2 changes: 1 addition & 1 deletion morrow/formatter.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct _Formatter:
ret += self.replace_token(m, match_chr_ord, match_count)
return ret

fn replace_token(self, m: Morrow, token: String, token_count: Int) raises -> String:
fn replace_token(self, m: Morrow, token: Int, token_count: Int) raises -> String:
if token == _Y:
if token_count == 1:
return "Y"
Expand Down
52 changes: 26 additions & 26 deletions morrow/morrow.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ struct Morrow(StringableRaising):
tz = TimeZone(0, "UTC")
else:
tm = c_localtime(t.tv_sec)
tz = TimeZone(tm.tm_gmtoff.to_int(), "local")
tz = TimeZone(int(tm.tm_gmtoff), "local")

var result = Self(
tm.tm_year.to_int() + 1900,
tm.tm_mon.to_int() + 1,
tm.tm_mday.to_int(),
tm.tm_hour.to_int(),
tm.tm_min.to_int(),
tm.tm_sec.to_int(),
int(tm.tm_year) + 1900,
int(tm.tm_mon) + 1,
int(tm.tm_mday),
int(tm.tm_hour),
int(tm.tm_min),
int(tm.tm_sec),
t.tv_usec,
tz,
)
Expand All @@ -82,13 +82,13 @@ struct Morrow(StringableRaising):
@staticmethod
fn fromtimestamp(timestamp: Float64) raises -> Self:
var timestamp_ = normalize_timestamp(timestamp)
var t = CTimeval(timestamp_.to_int())
var t = CTimeval(int(timestamp_))
return Self._fromtimestamp(t, False)

@staticmethod
fn utcfromtimestamp(timestamp: Float64) raises -> Self:
var timestamp_ = normalize_timestamp(timestamp)
var t = CTimeval(timestamp_.to_int())
var t = CTimeval(int(timestamp_))
return Self._fromtimestamp(t, True)

@staticmethod
Expand All @@ -105,14 +105,14 @@ struct Morrow(StringableRaising):
<Morrow [2019-01-20T15:49:10+00:00]>
"""
var tm = c_strptime(date_str, fmt)
var tz = TimeZone(tm.tm_gmtoff.to_int()) if tzinfo.is_none() else tzinfo
var tz = TimeZone(int(tm.tm_gmtoff)) if tzinfo.is_none() else tzinfo
return Self(
tm.tm_year.to_int() + 1900,
tm.tm_mon.to_int() + 1,
tm.tm_mday.to_int(),
tm.tm_hour.to_int(),
tm.tm_min.to_int(),
tm.tm_sec.to_int(),
int(tm.tm_year) + 1900,
int(tm.tm_mon) + 1,
int(tm.tm_mday),
int(tm.tm_hour),
int(tm.tm_min),
int(tm.tm_sec),
0,
tz,
)
Expand Down Expand Up @@ -333,19 +333,19 @@ struct Morrow(StringableRaising):
# Python.is_type not working, use __class__.__name__ instead
if py_datetime.__class__.__name__ == "datetime":
return Morrow(
py_datetime.year.to_float64().to_int(),
py_datetime.month.to_float64().to_int(),
py_datetime.day.to_float64().to_int(),
py_datetime.hour.to_float64().to_int(),
py_datetime.minute.to_float64().to_int(),
py_datetime.second.to_float64().to_int(),
py_datetime.second.to_float64().to_int(),
int(py_datetime.year),
int(py_datetime.month),
int(py_datetime.day),
int(py_datetime.hour),
int(py_datetime.minute),
int(py_datetime.second),
int(py_datetime.second),
)
elif py_datetime.__class__.__name__ == "date":
return Morrow(
py_datetime.year.to_float64().to_int(),
py_datetime.month.to_float64().to_int(),
py_datetime.day.to_float64().to_int(),
int(py_datetime.year),
int(py_datetime.month),
int(py_datetime.day),
)
else:
raise Error(
Expand Down
1 change: 0 additions & 1 deletion morrow/timedelta.mojo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from math import abs
from .util import rjust

alias SECONDS_OF_DAY = 24 * 3600
Expand Down
10 changes: 5 additions & 5 deletions test.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ from morrow import TimeDelta

def assert_datetime_equal(dt: Morrow, py_dt: PythonObject):
assert_true(
dt.year == py_dt.year.to_float64().to_int()
and dt.month == py_dt.month.to_float64().to_int()
and dt.hour == py_dt.hour.to_float64().to_int()
and dt.minute == py_dt.minute.to_float64().to_int()
and dt.second == py_dt.second.to_float64().to_int(),
dt.year == int(py_dt.year)
and dt.month == int(py_dt.month)
and dt.hour == int(py_dt.hour)
and dt.minute == int(py_dt.minute)
and dt.second == int(py_dt.second),
"dt: " + str(dt) + " is not equal to py_dt: " + str(py_dt),
)

Expand Down

0 comments on commit 4572186

Please sign in to comment.