Skip to content

Commit

Permalink
pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
lan496 committed Mar 11, 2024
1 parent 0679b0d commit 94edadd
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 55 deletions.
57 changes: 29 additions & 28 deletions .github/workflows/ci-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path moyo_py/Cargo.toml
args: --release --out dist --manifest-path moyopy/Cargo.toml
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: linux-${{ matrix.target }}-wheels
name: pypi-linux-${{ matrix.target }}
path: dist
- name: pytest
if: ${{ startsWith(matrix.target, 'x86_64') }}
Expand All @@ -45,7 +45,7 @@ jobs:
set -e
pip install moyo --find-links dist --force-reinstall
pip install pytest
cd moyo_py && pytest -v
cd moyopy && pytest -v
- name: pytest
if: ${{ !startsWith(matrix.target, 'x86') && matrix.target != 'ppc64' }}
uses: uraimo/[email protected]
Expand All @@ -60,7 +60,7 @@ jobs:
run: |
set -e
pip3 install moyo --find-links dist --force-reinstall
cd moyo_py && pytest -v
cd moyopy && pytest -v
windows:
runs-on: windows-latest
Expand All @@ -77,12 +77,12 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path moyo_py/Cargo.toml
args: --release --out dist --manifest-path moyopy/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: windows-${{ matrix.target }}-wheels
name: pypi-windows-${{ matrix.target }}
path: dist
- name: pytest
if: ${{ !startsWith(matrix.target, 'aarch64') }}
Expand All @@ -91,7 +91,7 @@ jobs:
set -e
pip install moyo --find-links dist --force-reinstall
pip install pytest
cd moyo_py && pytest -v
cd moyopy && pytest -v
macos:
runs-on: macos-latest
Expand All @@ -107,12 +107,12 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path moyo_py/Cargo.toml
args: --release --out dist --manifest-path moyopy/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: macos-${{ matrix.target }}-wheels
name: pypi-macos-${{ matrix.target }}
path: dist
- name: pytest
if: ${{ !startsWith(matrix.target, 'aarch64') }}
Expand All @@ -121,7 +121,7 @@ jobs:
set -e
pip install moyo --find-links dist --force-reinstall
pip install pytest
cd moyo_py && pytest -v
cd moyopy && pytest -v
sdist:
runs-on: ubuntu-latest
Expand All @@ -131,26 +131,27 @@ jobs:
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path moyo_py/Cargo.toml
args: --out dist --manifest-path moyopy/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels
name: pypi-sdist
path: dist

# release:
# name: Release
# runs-on: ubuntu-latest
# if: "startsWith(github.ref, 'refs/tags/')"
# needs: [linux, windows, macos, sdist]
# steps:
# - uses: actions/download-artifact@v3
# with:
# name: wheels
# - name: Publish to PyPI
# uses: PyO3/maturin-action@v1
# env:
# MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
# with:
# command: upload
# args: --non-interactive --skip-existing *
release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
with:
pattern: pypi-*
merge-multiple: true
path: dist
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository_url: https://test.pypi.org/legacy/
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ repos:
rev: v0.1.13
hooks:
- id: ruff-format
args: ["--config", "moyo_py/pyproject.toml"]
args: ["--config", "moyopy/pyproject.toml"]
- id: ruff
args: [ "--fix", "--show-fixes", "--config", "moyo_py/pyproject.toml"]
args: [ "--fix", "--show-fixes", "--config", "moyopy/pyproject.toml"]
types_or: [python, pyi]
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

members = [
"moyo",
"moyo_py",
"moyopy",
]

resolver = "2"
Expand Down
10 changes: 5 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ default:
just --list

build-python:
maturin develop --release --manifest-path moyo_py/Cargo.toml
maturin develop --release --manifest-path moyopy/Cargo.toml

install-python:
maturin develop --release --manifest-path moyo_py/Cargo.toml
pip install -e "moyo_py[dev]"
maturin develop --release --manifest-path moyopy/Cargo.toml
pip install -e "moyopy[dev]"

test-python:
pytest -v moyo_py/python/tests
pytest -v moyopy/python/tests

pre-commit:
pre-commit run --all-files

clean:
rm moyo_py/python/moyo/*.so
rm moyopy/python/moyo/*.so
5 changes: 0 additions & 5 deletions moyo_py/python/moyo/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions moyo_py/python/tests/test_moyo_dataset.py

This file was deleted.

4 changes: 2 additions & 2 deletions moyo_py/Cargo.toml → moyopy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "moyo_py"
name = "moyopy"
authors.workspace = true
description.workspace = true
edition.workspace = true
Expand All @@ -9,7 +9,7 @@ version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "moyo_py"
name = "moyopy"
crate-type = ["cdylib"]

[dependencies]
Expand Down
7 changes: 5 additions & 2 deletions moyo_py/pyproject.toml → moyopy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ requires = ["maturin>=1,<2"]
build-backend = "maturin"

[project]
name = "moyo"
name = "moyopy"
requires-python = ">=3.8"
description = "Python binding of Moyo"
license-files = { paths = ["LICENSE-MIT", "LICENSE-APACHE"] }
dynamic = [
'version',
]

[project.optional-dependencies]
dev = [
Expand All @@ -15,7 +18,7 @@ dev = [

[tool.maturin]
python-source = "python"
module-name = "moyo._moyo"
module-name = "moyopy._moyo"
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
features = ["pyo3/extension-module"]

Expand Down
1 change: 1 addition & 0 deletions moyopy/python/moyopy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._moyo import * # noqa: F403
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import pytest

import moyo
import moyopy


@pytest.fixture
def wurtzite() -> moyo.Cell:
def wurtzite() -> moyopy.Cell:
# https://next-gen.materialsproject.org/materials/mp-560588
a = 3.81
c = 6.24
Expand All @@ -27,5 +27,5 @@ def wurtzite() -> moyo.Cell:
]
numbers = [0, 0, 1, 1]

cell = moyo.Cell(basis, positions, numbers)
cell = moyopy.Cell(basis, positions, numbers)
return cell
7 changes: 7 additions & 0 deletions moyopy/python/tests/test_moyo_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import moyopy


def test_moyo_dataset(wurtzite: moyopy.Cell):
dataset = moyopy.MoyoDataset(wurtzite)
assert dataset.number == 186
assert dataset.hall_number == 480
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions moyo_py/src/lib.rs → moyopy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use base::PyOperations;
use pyo3::prelude::*;
use std::sync::OnceLock;

mod base;
mod data;
Expand Down Expand Up @@ -118,9 +119,26 @@ impl PyMoyoDataset {
}
}

// https://github.com/pydantic/pydantic-core/blob/main/src/lib.rs
pub fn moyo_version() -> &'static str {
static MOYO_VERSION: OnceLock<String> = OnceLock::new();

MOYO_VERSION.get_or_init(|| {
let version = env!("CARGO_PKG_VERSION");
// cargo uses "1.0-alpha1" etc. while python uses "1.0.0a1", this is not full compatibility,
// but it's good enough for now
// see https://docs.rs/semver/1.0.9/semver/struct.Version.html#method.parse for rust spec
// see https://peps.python.org/pep-0440/ for python spec
// it seems the dot after "alpha/beta" e.g. "-alpha.1" is not necessary, hence why this works
version.replace("-alpha", "a").replace("-beta", "b")
})
}

/// A Python module implemented in Rust.
#[pymodule]
fn _moyo(_py: Python, m: &PyModule) -> PyResult<()> {
m.add("__version__", moyo_version())?;

// lib
m.add_class::<PyMoyoDataset>()?;

Expand Down

0 comments on commit 94edadd

Please sign in to comment.