Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,74 @@
# Build Package
name: GitHub CI

on: [push, pull_request, workflow_dispatch]
# run only on main branch. This avoids duplicated actions on PRs
on:
pull_request:
push:
tags:
- "*"
branches:
- main

jobs:
build:
name: Build package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7 # must be 3.7 due to grpcio-tools==1.21.1

python-version: "3.7"
- name: Install build requirements
run: |
pip install -r requirements.txt

- name: Build package
run: python -m ansys.tools.protos_generator ansys/api/mapdl/v0/

- name: Upload package artifact to github actions
uses: actions/[email protected]
pip install -U pip
pip install build
- name: Build
run: python -m build
- name: Install
run: pip install dist/*.whl
- name: Test import
run: |
mkdir tmp
cd tmp
python -c "import ansys.api.mapdl.v0; print('Sucessfully imported ansys.api.mapdl.v0')"
python -c "from ansys.api.mapdl import __version__; print(__version__)"
- name: Upload packages
uses: actions/upload-artifact@v2
with:
name: proto package
path: dist/*.tar.gz
name: ansys-api-mapdl-packages
path: dist/
retention-days: 7

- name: Upload package to PyPi
if: startsWith(github.ref, 'refs/tags/')
Release:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10

- uses: actions/download-artifact@v2

- name: Display structure of downloaded files
run: ls -R

- name: Upload to Public PyPi
run: |
pip install twine
twine upload --skip-existing dist/*.tar.gz
twine upload --skip-existing ./**/*.whl
twine upload --skip-existing ./**/*.tar.gz
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
TWINE_REPOSITORY_URL: "https://upload.pypi.org/legacy/"
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}

- name: Release to GitHub
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
generate_release_notes: true
files: |
./**/*.whl
./**/*.tar.gz
./**/*.pdf
39 changes: 35 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Virtual environment
venv

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# emacs temp files
*~
#*

# build files
build/
dist/*
# VSCode settings
.vscode

# autogenerated Python code
*pb2*.py
*pb2*.pyi
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 ANSYS, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 54 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@
### Protocol Files for PyMAPDL Interface
This repository includes gRPC protocol files to interface with MAPDL's
gRPC interface.
### ansys-api-mapdl gRPC Interface Package

### Build
To build the `ansys-grpc-mapdl` package locally, clone this
repository, install build requirements, and build the mapdl protos
package with
This Python package contains the auto-generated gRPC Python interface files for
mapdl.


#### Installation

Provided that these wheels have been published to public PyPI, they can be
installed with:

```
pip install ansys-api-mapdl
```

Otherwise, see the


#### Build

To build the gRPC packages, run:

```
git clone https://github.com/pyansys/protos-mapdl
cd protos-mapdl
pip install -r requirements_build.txt
python package_grpc.py mapdl
pip install build
python -m build
```

These protobuf interface files can be used to develop a custom python
module to interface to MAPDL via gRPC. Packages like `ansys-mapdl-core`
require the gRPC source and stub files to be pre-packaged as a Python
package for distribution.
This will create both the source distribution containing just the protofiles
along with the wheel containing the protofiles and build Python interface
files.

Note that the interface files are identical regardless of the version of Python
used to generate them, but the last pre-built wheel for ``grpcio~=1.17`` was
Python 3.7, so to improve your build time, use Python 3.7 when building the
wheel.

### CI/CD

Packages are automatically generated from GitHub Actions for each commit and PR. To download the automatically generated package, visit the actions tab at [Actions](https://github.com/pyansys/protos-mapdl/actions).
#### Manual Deployment

To create a release, bump the version tag in `mapdl/VERSION`, and tag a release with `git tag <version>` (e.g. `0.4.0`).
After building the packages, manually deploy them with:

```
pip install twine
twine upload dist/*
```

Note that this is automatically done through CI/CD.


#### Automatic Deployment

This repository contains GitHub CI/CD that enables the automatic building of
source and wheel packages for these gRPC Python interface files. By default,
these are built on PRs, the main branch, and on tags when pushing. Artifacts
are uploaded for each PR.

To publicly release wheels to PyPI, ensure your branch is up-to-date and then
push tags. For example, for the version ``v0.5.0``.

```bash
git tag v0.5.0
git push --tags
```
1 change: 1 addition & 0 deletions ansys/api/mapdl/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.5.dev0
8 changes: 8 additions & 0 deletions ansys/api/mapdl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Autogenerated Python gRPC interface package for ansys-api-mapdl."""

import pathlib

__all__ = ["__version__"]

with open(pathlib.Path(__file__).parent / "VERSION", encoding="utf-8") as f:
__version__ = f.read().strip()
Empty file added ansys/api/mapdl/py.typed
Empty file.
2 changes: 1 addition & 1 deletion ansys/api/mapdl/v0/C_StreamGrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ansys.api.grpcstream.v0;
option csharp_namespace = "Ansys.Api.GrpcStream.V0";

// import "google/protobuf/empty.proto";
import "ansys_kernel.proto";
import "ansys/api/mapdl/v0/ansys_kernel.proto";

// ================================================================================
// =====
Expand Down
1 change: 0 additions & 1 deletion ansys/api/mapdl/v0/VERSION

This file was deleted.

2 changes: 1 addition & 1 deletion ansys/api/mapdl/v0/mapdl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";
package ansys.api.mapdl.v0;
option csharp_namespace = "Ansys.Api.Mapdl.V0";

import "ansys_kernel.proto";
import "ansys/api/mapdl/v0/ansys_kernel.proto";

// ============================================================
// For the cmd and inp Method
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools >= 42.0.0", "wheel", "ansys_tools_protoc_helper"]
build-backend = "setuptools.build_meta:__legacy__"
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

49 changes: 49 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Installation file for the ansys-api-mapdl package"""

import os
from datetime import datetime

import setuptools

from ansys.tools.protoc_helper import CMDCLASS_OVERRIDE

# Get the long description from the README file
HERE = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(HERE, "README.md"), encoding="utf-8") as f:
long_description = f.read()

product = "mapdl"
library = ""
package_info = ["ansys", "api", product, library, "v0"]
with open(os.path.join(HERE, "ansys", "api", product, library, "VERSION"), encoding="utf-8") as f:
version = f.read().strip()

package_name = "ansys-api-mapdl"
dot_package_name = '.'.join(filter(None, package_info))

description = f"Autogenerated python gRPC interface package for {package_name}, built on {datetime.now().strftime('%H:%M:%S on %d %B %Y')}"

if __name__ == "__main__":
setuptools.setup(
name=package_name,
version=version,
author="ANSYS, Inc.",
author_email='[email protected]',
description=description,
long_description=long_description,
long_description_content_type='text/markdown',
url=f"https://github.com/ansys/{package_name}",
license="MIT",
python_requires=">=3.7",
install_requires=["grpcio~=1.17", "protobuf~=3.19"],
packages=setuptools.find_namespace_packages(".", include=("ansys.*",)),
package_data={
"": ["*.proto", "*.pyi", "py.typed", "VERSION"],
},
entry_points={
"ansys.tools.protoc_helper.proto_provider": [
f"{dot_package_name}={dot_package_name}"
],
},
cmdclass=CMDCLASS_OVERRIDE
)