diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c12733..a50873f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -18,9 +17,22 @@ 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: | + 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" ${{ env.MOJO_HOME }}/mojo package ${{ env.MORROW_SRC }} -o ${{ github.workspace }}/${{ env.PACKAGE_NAME }} - name: Upload package uses: actions/upload-artifact@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 786a64c..d4b6c12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 diff --git a/morrow/__init__.mojo b/morrow/__init__.mojo index f3f9f09..63bde0c 100644 --- a/morrow/__init__.mojo +++ b/morrow/__init__.mojo @@ -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" diff --git a/morrow/constants.mojo b/morrow/constants.mojo index f1b806f..e8b2833 100644 --- a/morrow/constants.mojo +++ b/morrow/constants.mojo @@ -1,3 +1,6 @@ +from utils import StaticTuple + + # todo: hardcode for tmp alias _MAX_TIMESTAMP: Int = 32503737600 alias MAX_TIMESTAMP = _MAX_TIMESTAMP diff --git a/morrow/formatter.mojo b/morrow/formatter.mojo index a7541e5..4a35054 100644 --- a/morrow/formatter.mojo +++ b/morrow/formatter.mojo @@ -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" diff --git a/morrow/morrow.mojo b/morrow/morrow.mojo index f6b66d5..cda506a 100644 --- a/morrow/morrow.mojo +++ b/morrow/morrow.mojo @@ -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, ) @@ -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 @@ -105,14 +105,14 @@ struct Morrow(StringableRaising): """ 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, ) @@ -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( diff --git a/morrow/timedelta.mojo b/morrow/timedelta.mojo index 0ddaa2c..ddd41b1 100644 --- a/morrow/timedelta.mojo +++ b/morrow/timedelta.mojo @@ -1,4 +1,3 @@ -from math import abs from .util import rjust alias SECONDS_OF_DAY = 24 * 3600 diff --git a/test.mojo b/test.mojo index d829c8e..fc27f63 100644 --- a/test.mojo +++ b/test.mojo @@ -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), )