Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Aug 5, 2023
1 parent a44aa76 commit e35518e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 90 deletions.
62 changes: 2 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,68 +54,10 @@ tox:


lint-rust:
cargo fmt --version
cargo fmt --all -- --check
cargo clippy --version
cargo clippy --tests -- \
-D warnings \
-W clippy::pedantic \
-W clippy::dbg_macro \
-W clippy::print_stdout \
-A clippy::cast-possible-truncation \
-A clippy::cast-possible-wrap \
-A clippy::cast-precision-loss \
-A clippy::cast-sign-loss \
-A clippy::doc-markdown \
-A clippy::float-cmp \
-A clippy::fn-params-excessive-bools \
-A clippy::if-not-else \
-A clippy::manual-let-else \
-A clippy::match-bool \
-A clippy::match-same-arms \
-A clippy::missing-errors-doc \
-A clippy::missing-panics-doc \
-A clippy::module-name-repetitions \
-A clippy::must-use-candidate \
-A clippy::needless-pass-by-value \
-A clippy::similar-names \
-A clippy::single-match-else \
-A clippy::struct-excessive-bools \
-A clippy::too-many-lines \
-A clippy::unnecessary-wraps \
-A clippy::unused-self \
-A clippy::used-underscore-binding
cargo clippy --tests -- -D warnings


format-rust:
cargo fmt --version
cargo fmt --all
cargo clippy --version
cargo clippy --tests --fix --allow-dirty -- \
-D warnings \
-W clippy::pedantic \
-W clippy::dbg_macro \
-W clippy::print_stdout \
-A clippy::cast-possible-truncation \
-A clippy::cast-possible-wrap \
-A clippy::cast-precision-loss \
-A clippy::cast-sign-loss \
-A clippy::doc-markdown \
-A clippy::float-cmp \
-A clippy::fn-params-excessive-bools \
-A clippy::if-not-else \
-A clippy::manual-let-else \
-A clippy::match-bool \
-A clippy::match-same-arms \
-A clippy::missing-errors-doc \
-A clippy::missing-panics-doc \
-A clippy::module-name-repetitions \
-A clippy::must-use-candidate \
-A clippy::needless-pass-by-value \
-A clippy::similar-names \
-A clippy::single-match-else \
-A clippy::struct-excessive-bools \
-A clippy::too-many-lines \
-A clippy::unnecessary-wraps \
-A clippy::unused-self \
-A clippy::used-underscore-binding
cargo clippy --tests --fix --allow-dirty -- -D warnings
1 change: 0 additions & 1 deletion _pendulum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ def local_time(
unix_time: int, utc_offset: int, microseconds: int
) -> tuple[int, int, int, int, int, int, int]: ...
def precise_diff(d1: datetime | date, d2: datetime | date) -> PreciseDiff: ...
def timestamp(dt: datetime) -> int: ...
def week_day(year: int, month: int, day: int) -> int: ...
3 changes: 3 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def _build():

maturin("build", "-r", *cargo_args)

# We won't use the wheel built by maturin directly since
# we want Poetry to build it but we need to retrieve the
# compiled extensions from the maturin wheel.
wheel = list(wheels_dir.glob("*.whl"))[0]
with zipfile.ZipFile(wheel.as_posix()) as whl:
whl.extractall(wheels_dir.as_posix())
Expand Down
22 changes: 0 additions & 22 deletions pendulum/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,6 @@ def days_in_year(year: int) -> int:
return DAYS_PER_N_YEAR


def timestamp(dt: datetime.datetime) -> int:
year = dt.year

result = (year - 1970) * 365 + MONTHS_OFFSETS[0][dt.month]
result += (year - 1968) // 4
result -= (year - 1900) // 100
result += (year - 1600) // 400

if is_leap(year) and dt.month < 3:
result -= 1

result += dt.day - 1
result *= 24
result += dt.hour
result *= 60
result += dt.minute
result *= 60
result += dt.second

return result


def local_time(
unix_time: int, utc_offset: int, microseconds: int
) -> tuple[int, int, int, int, int, int, int]:
Expand Down
6 changes: 3 additions & 3 deletions pendulum/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from pendulum.time import Time

try:
from _pendulum import Duration as CDuration
from _pendulum import Duration as RustDuration
except ImportError:
CDuration = None # type: ignore[assignment,misc]
RustDuration = None # type: ignore[assignment,misc]


def parse(text: str, **options: t.Any) -> Date | Time | DateTime | Duration:
Expand Down Expand Up @@ -113,7 +113,7 @@ def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | I
if isinstance(parsed, Duration):
return parsed

if CDuration and isinstance(parsed, CDuration): # type: ignore[truthy-function]
if RustDuration is not None and isinstance(parsed, RustDuration):
return pendulum.duration(
years=parsed.years,
months=parsed.months,
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ packages = [
include = [
{ path = "meson.build", format = "sdist" },
{ path = "pendulum/py.typed" },
# C extensions must be included in the wheel distributions
{ path = "pendulum/_extensions/*.so", format = "wheel" },
{ path = "pendulum/_extensions/*.pyd", format = "wheel" },
# Typing stubs
{ path = "*.pyi"},
# Rust source
Expand Down Expand Up @@ -224,5 +221,5 @@ omit = [
]

[build-system]
requires = ["poetry-core>=1.1.0a6", "maturin>=1,<2"]
requires = ["poetry-core>=1.6.1", "maturin>=1,<2"]
build-backend = "poetry.core.masonry.api"

0 comments on commit e35518e

Please sign in to comment.