Skip to content

Commit

Permalink
Update Python Packaging (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pusnow committed Jun 21, 2023
1 parent 197476f commit 575a4ff
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 62 deletions.
106 changes: 97 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
branches: [ "master" ]
jobs:
build:
name: Build binaries on ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -17,7 +18,7 @@ jobs:
- { name: windows, os: windows-latest, arch: x86}
- { name: macos, os: macos-latest, arch: x86_64}
- { name: macos, os: macos-latest, arch: arm64}
- { name: linux, os: ubuntu-latest, arch: x86_64}
- { name: linux, os: ubuntu-latest, arch: x86_64, dicbuild: true}
- { name: linux, os: ubuntu-latest, arch: aarch64, crossbuild: crossbuild-essential-arm64}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -65,35 +66,35 @@ jobs:
- name: 7z (dic)
run: 7z a mecab-ko-dic.zip mecab-ko-dic
working-directory: ${{ github.workspace }}/out/opt/mecab/share
if: matrix.name == 'linux' && matrix.arch == 'x86_64'
if: matrix.dicbuild
- name: tar (dic)
run: tar -cvzf mecab-ko-dic.tar.gz mecab-ko-dic
working-directory: ${{ github.workspace }}/out/opt/mecab/share
if: matrix.name == 'linux' && matrix.arch == 'x86_64'
if: matrix.dicbuild
- name: Upload a Dictionary Artifact
uses: actions/upload-artifact@v3
with:
path: out/opt/mecab/share/mecab-ko-dic.zip
if: matrix.name == 'linux' && matrix.arch == 'x86_64'
if: matrix.dicbuild
- name: Release Dictionary
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && matrix.name == 'linux' && matrix.arch == 'x86_64'
if: startsWith(github.ref, 'refs/tags/') && matrix.dicbuild
with:
files: out/opt/mecab/share/mecab-ko-dic.zip
- name: Upload a Dictionary Artifact
uses: actions/upload-artifact@v3
with:
path: out/opt/mecab/share/mecab-ko-dic.tar.gz
if: matrix.name != 'windows' && matrix.name == 'linux' && matrix.arch == 'x86_64'
if: matrix.dicbuild
- name: Release Dictionary
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && matrix.name == 'linux' && matrix.arch == 'x86_64'
if: startsWith(github.ref, 'refs/tags/') && matrix.dicbuild
with:
files: out/opt/mecab/share/mecab-ko-dic.tar.gz
- name: Remove Dictionary
run: rm -rf mecab-ko-dic mecab-ko-dic.zip mecab-ko-dic.tar.gz
working-directory: ${{ github.workspace }}/out/opt/mecab/share
if: matrix.name == 'linux' && matrix.arch == 'x86_64'
if: matrix.dicbuild
- name: 7z
run: 7z a mecab-ko-${{ matrix.name }}-${{ matrix.arch }}.zip mecab
working-directory: ${{ github.workspace }}/out
Expand Down Expand Up @@ -122,4 +123,91 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') && matrix.name != 'windows'
with:
files: out/opt/mecab-ko-${{ matrix.name }}-${{ matrix.arch }}.tar.gz

build_sdist:
name: Build sdist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Python Dependencies
run: pip install meson ninja build

- name: Build sdist
run: python -m build --sdist .

- uses: actions/upload-artifact@v3
with:
name: python-artifact
path: ./dist/*.tar.gz
build_wheels:
name: Build wheels on ${{ matrix.os }} - ${{ matrix.cibw_arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- { name: windows, os: windows-2019, msvc_arch: x64, cibw_arch: AMD64}
- { name: windows, os: windows-2019, msvc_arch: x86, cibw_arch: x86}
- { name: macos, os: macos-11, cibw_arch: auto}
- { name: linux, os: ubuntu-20.04, cibw_arch: auto}

steps:
- uses: actions/checkout@v3

- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.msvc_arch }}
if: matrix.name == 'windows'

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS: ${{ matrix.cibw_arch }}

- uses: actions/upload-artifact@v3
with:
name: python-artifact
path: ./wheelhouse/*.whl
build_dic_wheel:
name: Build dic wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Python Dependencies
run: pip install meson ninja build
- name: Configure
run: meson setup builddir -Dbuild_dic=true -Dbuilding_pip_dic=true
working-directory: ${{ github.workspace }}
- name: Build
run: meson compile -C builddir
working-directory: ${{ github.workspace }}
- name: Build Wheel
run: python -m build .
working-directory: ${{ github.workspace }}/builddir
- uses: actions/upload-artifact@v3
with:
name: python-artifact
path: ./builddir/dist/*.whl

upload_python_pkgs:
name: Upload Python Packages
needs: [build_sdist, build_wheels, build_dic_wheel]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v3
with:
name: python-artifact
path: dist

- uses: pypa/[email protected]
with:
user: ${{ secrets.pypi_user }}
password: ${{ secrets.pypi_password }}

42 changes: 0 additions & 42 deletions .github/workflows/python.yml

This file was deleted.

16 changes: 12 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('mecab-ko-msvc', 'cpp',
version: '0.997',
version: '0.998',
meson_version: '>=0.63.0',
)

Expand Down Expand Up @@ -257,6 +257,7 @@ endif

building_pip = get_option('building_pip')
install_lib = not building_pip
install_dic = not building_pip
thread_dep = dependency('threads')
deps += thread_dep
libmecab = both_libraries(libmecab_name, lib_sources, dependencies: deps, install : install_lib)
Expand All @@ -282,7 +283,7 @@ configure_file(input : 'mecabrc.in',
output : 'mecabrc',
configuration : mecabrc_conf,
install: true,
install_dir: building_pip ? get_option('datadir') : get_option('sysconfdir'))
install_dir: building_pip ? '{py_platlib}' : get_option('sysconfdir'))

if not building_pip
install_headers('src/mecab.h')
Expand Down Expand Up @@ -310,14 +311,21 @@ endif


py = import('python').find_installation()
if get_option('build_dic')
if get_option('build_dic') or get_option('building_pip_dic')
run_command(py, '-m', 'zipfile', '-e', meson.project_source_root() / 'mecab-ko-dic.zip', meson.project_build_root(), check:true)
mecab_ko_dic = custom_target('mecab_ko_dic',
output : 'mecab-ko-dic',
depends : [mecab_dict_index],
command : [mecab_dict_index, '-d', '@OUTPUT@', '-o', '@OUTPUT@', '-f', 'UTF-8', '-t', 'UTF-8'],
install : true,
install : install_dic,
install_dir : get_option('datadir'))

endif
if get_option('building_pip_dic')
dic_conf_data = configuration_data()
configure_file(input : 'pyproject-dic.toml',
output : 'pyproject.toml',
configuration : dic_conf_data)
endif

build_java = get_option('build_java')
Expand Down
3 changes: 2 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ option('build_python', type : 'boolean', value : false)
option('build_perl', type : 'boolean', value : false)
option('build_ruby', type : 'boolean', value : false)
option('build_csharp', type : 'boolean', value : false)
option('building_pip', type : 'boolean', value : false)
option('building_pip', type : 'boolean', value : false)
option('building_pip_dic', type : 'boolean', value : false)
25 changes: 25 additions & 0 deletions pyproject-dic.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "mecab-ko-dic-msvc"
version = "0.998"
description = "Mecab-ko-dic-msvc build"
readme = "../README.md"
maintainers = [
{ name = "Wonsup Yoon", email = "[email protected]" },
]
classifiers = [
"Topic :: Software Development :: Libraries",
]

[project.urls]
"Documentation" = "https://github.com/Pusnow/mecab-ko-msvc/"
"Source" = "https://github.com/Pusnow/mecab-ko-msvc/"
"Issue Tracker" = "https://github.com/Pusnow/mecab-ko-msvcissues"

[tool.hatch.build]
artifacts = [
"mecab-ko-dic/*",
]
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "mesonpy"

[project]
name = "mecab-ko-msvc"
version = "0.997"
version = "0.998"
description = "Mecab-ko-msvc build"
readme = "README.md"
maintainers = [
Expand All @@ -32,4 +32,4 @@ classifiers = [
"Issue Tracker" = "https://github.com/Pusnow/mecab-ko-msvcissues"

[tool.meson-python.args]
setup = ['-Dbuilding_pip=true']
setup = ['-Dbuilding_pip=true', '-Dbuild_dic=false']
8 changes: 4 additions & 4 deletions swig/MeCab.i
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
%}

%pythoncode %{
import sys
import sysconfig
import os

if "MECABRC" not in os.environ and os.path.exists(os.path.join(sys.prefix,"mecabrc")):
os.putenv("MECABRC", os.path.join(sys.prefix,"mecabrc"))
MECABRC_DEFAULT_PATH = os.path.join(sysconfig.get_paths()["platlib"],"mecabrc")
if "MECABRC" not in os.environ and os.path.exists(MECABRC_DEFAULT_PATH):
os.putenv("MECABRC", MECABRC_DEFAULT_PATH)
%}

%newobject surface;
Expand Down

0 comments on commit 575a4ff

Please sign in to comment.