Skip to content

FEAT: improve package layout #2056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
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
17 changes: 16 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ on:
- master
pull_request:


env:
LIBRARY_NAME: 'ansys-pythonnet'

jobs:

build-test:
name: Build and Test
runs-on: ${{ matrix.os }}-latest
Expand Down Expand Up @@ -93,4 +98,14 @@ jobs:
pip install --force --no-deps --target src/perf_tests/baseline/ pythonnet==2.5.2
dotnet test --configuration Release --runtime any-${{ matrix.platform }} --logger "console;verbosity=detailed" src/perf_tests/

# TODO: Run mono tests on Windows?
- name: "Build library source and wheel artifacts"
run: |
python -m pip install build twine wheel
python -m build && python -m twine check dist/*

- name: "Upload distribution artifact"
uses: actions/upload-artifact@v3.1.0
with:
name: ${{ env.LIBRARY_NAME }}-py${{ matrix.python}}-${{ matrix.os }}-artifacts
path: dist/
retention-days: 7
164 changes: 164 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,167 @@ cov-int/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json


# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

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

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.cov
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
doc/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Visual Studio
.vs/

# End of https://www.toptal.com/developers/gitignore/api/python
160 changes: 4 additions & 156 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,158 +1,6 @@
pythonnet - Python.NET
===========================
Ansys fork of [pythonnet](https://github.com/pythonnet/pythonnet)

|Join the chat at https://gitter.im/pythonnet/pythonnet| |stackexchange shield|
We will try to keep this up-to-date with pythonnet and upstream changes that might benefit the pythonnet community

|gh shield|

|license shield|

|pypi package version| |conda-forge version| |python supported shield|

|nuget preview shield| |nuget release shield|

Python.NET is a package that gives Python programmers nearly
seamless integration with the .NET Common Language Runtime (CLR) and
provides a powerful application scripting tool for .NET developers. It
allows Python code to interact with the CLR, and may also be used to
embed Python into a .NET application.

Calling .NET code from Python
-----------------------------

Python.NET allows CLR namespaces to be treated essentially as Python packages.

.. code-block:: python

import clr
from System import String
from System.Collections import *

To load an assembly, use the ``AddReference`` function in the ``clr``
module:

.. code-block:: python

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form

By default, Mono will be used on Linux and macOS, .NET Framework on Windows. For
details on the loading of different runtimes, please refer to the documentation.

.NET Core
~~~~~~~~~

If .NET Core is installed in a default location or the ``dotnet`` CLI tool is on
the ``PATH``, loading it instead of the default (Mono/.NET Framework) runtime
just requires setting either the environment variable
``PYTHONNET_RUNTIME=coreclr`` or calling ``pythonnet.load`` explicitly:

.. code-block:: python

from pythonnet import load
load("coreclr")

import clr


Embedding Python in .NET
------------------------

- You must set ``Runtime.PythonDLL`` property or ``PYTHONNET_PYDLL`` environment variable
starting with version 3.0, otherwise you will receive ``BadPythonDllException``
(internal, derived from ``MissingMethodException``) upon calling ``Initialize``.
Typical values are ``python38.dll`` (Windows), ``libpython3.8.dylib`` (Mac),
``libpython3.8.so`` (most other Unix-like operating systems).
- Then call ``PythonEngine.Initialize()``. If you plan to use Python objects from
multiple threads, also call ``PythonEngine.BeginAllowThreads()``.
- All calls to python should be inside a
``using (Py.GIL()) {/* Your code here */}`` block.
- Import python modules using ``dynamic mod = Py.Import("mod")``, then
you can call functions as normal, eg ``mod.func(args)``.
- Use ``mod.func(args, Py.kw("keywordargname", keywordargvalue))`` or
``mod.func(args, keywordargname: keywordargvalue)`` to apply keyword
arguments.
- All python objects should be declared as ``dynamic`` type.
- Mathematical operations involving python and literal/managed types
must have the python object first, eg. ``np.pi * 2`` works,
``2 * np.pi`` doesn't.

Example
~~~~~~~

.. code-block:: csharp

static void Main(string[] args)
{
PythonEngine.Initialize();
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));

dynamic sin = np.sin;
Console.WriteLine(sin(5));

double c = (double)(np.cos(5) + sin(5));
Console.WriteLine(c);

dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);

dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);

Console.WriteLine(a * b);
Console.ReadKey();
}
}

Output:

.. code:: csharp

1.0
-0.958924274663
-0.6752620892
float64
int32
[ 6. 10. 12.]



Resources
---------

Information on installation, FAQ, troubleshooting, debugging, and
projects using pythonnet can be found in the Wiki:

https://github.com/pythonnet/pythonnet/wiki

Mailing list
https://mail.python.org/mailman/listinfo/pythondotnet
Chat
https://gitter.im/pythonnet/pythonnet

.NET Foundation
---------------
This project is supported by the `.NET Foundation <https://dotnetfoundation.org>`_.

.. |Join the chat at https://gitter.im/pythonnet/pythonnet| image:: https://badges.gitter.im/pythonnet/pythonnet.svg
:target: https://gitter.im/pythonnet/pythonnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
.. |license shield| image:: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=3600
:target: ./LICENSE
.. |pypi package version| image:: https://img.shields.io/pypi/v/pythonnet.svg
:target: https://pypi.python.org/pypi/pythonnet
.. |python supported shield| image:: https://img.shields.io/pypi/pyversions/pythonnet.svg
:target: https://pypi.python.org/pypi/pythonnet
.. |stackexchange shield| image:: https://img.shields.io/badge/StackOverflow-python.net-blue.svg
:target: http://stackoverflow.com/questions/tagged/python.net
.. |conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/pythonnet.svg
:target: https://anaconda.org/conda-forge/pythonnet
.. |nuget preview shield| image:: https://img.shields.io/nuget/vpre/pythonnet
:target: https://www.nuget.org/packages/pythonnet/
.. |nuget release shield| image:: https://img.shields.io/nuget/v/pythonnet
:target: https://www.nuget.org/packages/pythonnet/
.. |gh shield| image:: https://github.com/pythonnet/pythonnet/workflows/GitHub%20Actions/badge.svg
:target: https://github.com/pythonnet/pythonnet/actions?query=branch%3Amaster
Changes relative to pythonnet:
- Revert of [#1240](https://github.com/pythonnet/pythonnet/pull/1240)
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "pythonnet"
description = ".NET and Mono integration for Python"
name = "ansys-pythonnet"
description = ".NET and Mono integration for Python (Ansys, Inc. fork)"
license = {text = "MIT"}

readme = "README.rst"
Expand Down Expand Up @@ -34,12 +34,12 @@ classifiers = [
dynamic = ["version"]

[[project.authors]]
name = "The Contributors of the Python.NET Project"
email = "pythonnet@python.org"
name = "ANSYS, Inc."
email = "pyansys.maintainers@ansys.com"

[project.urls]
Homepage = "https://pythonnet.github.io/"
Sources = "https://github.com/pythonnet/pythonnet"
Homepage = "pythonnet.docs.pyansys.com"
Sources = "https://github.com/pyansys/ansys-pythonnet"

[tool.setuptools]
zip-safe = false
Expand Down
Loading