Skip to content

Commit

Permalink
add openseespywin-pip
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuminjie committed Jan 28, 2021
1 parent 66130c7 commit f99bcc1
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ Sub-folders:
- `openseespywin-pip`

The OpenSeesPy Windows package.

[OpenSeesPy Windows Pip](https://pypi.org/project/openseespywin/)

- `openseespylinux-pip`

The OpenSeesPy Linux package.

[OpenSeesPy Linux Pip](https://pypi.org/project/openseespylinux/)

- `openseespymac-pip`

The OpenSeesPy Mac package.

[OpenSeesPy Mac Pip](https://pypi.org/project/openseespymac/)

- `openseespy-docs`
Expand Down
2 changes: 1 addition & 1 deletion openseespylinux-pip/openseespylinux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

else:

raise RuntimeError(sys.platform+' is not supported yet')
raise RuntimeError('This package is for Linux only.')
14 changes: 14 additions & 0 deletions openseespywin-pip/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*~
__pycache__
*.egg-info
build
dist
*.so
*.pyd
*.dll
*.so.*
.idea
*.dylib
.vscode
test_ODB/
*.pyc
16 changes: 16 additions & 0 deletions openseespywin-pip/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
os:
- linux
language: python
python:
- "3.6"
# command to install dependencies
install:
- pip install -r requirements.txt
- pip install coveralls
- pip install codecov
- pip install pytest-cov
# command to run tests
script:
- py.test --cov=./
after_success:
- coveralls # uploads reports to coveralls.io
30 changes: 30 additions & 0 deletions openseespywin-pip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# OpenSeesPy Windows

Pip Package for OpenSeesPy Windows

## Installation

```bash
pip install openseespywin
```

## Import

```python
import openseespywin as ops
```

## Documentation

[OpenSeesPy Documentation](https://openseespydoc.readthedocs.io/en/latest/index.html)

[OpenSeesPy Source Code](github.com/OpenSees/OpenSees)

## Issues

Any issues for installation and running the pip package, please
report to
[OpenSeesPy Github Page](https://github.com/zhuminjie/OpenSeesPy).

Any issues and bugs in `OpenSees` should be
reported on the [OpenSees GitHub Page](https://github.com/OpenSees/OpenSees).
141 changes: 141 additions & 0 deletions openseespywin-pip/build_pip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import subprocess
import shutil
import os
import os.path
import sys
import glob


def copy_win_library(pyd):

# change to script's folder
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# replace new libraries
win = './openseespywin/'

if os.path.exists(pyd):
if os.path.exists(win+'opensees.pyd'):
os.remove(win+'opensees.pyd')
shutil.copy(pyd, win)


def build_pip(pyexe='python', use_zip=False):

# clean folders
subprocess.run(['rm', '-fr', 'build', 'dist', 'openseespywin.egg-info'])

# update tools
subprocess.run([pyexe, '-m', 'pip', 'install', '--upgrade',
'setuptools', 'wheel', 'twine', 'pytest'])

# compile wheel
if use_zip:
subprocess.run([pyexe, 'setup.py', 'bdist', '--format=zip'])
else:
subprocess.run([pyexe, 'setup.py', 'bdist_wheel'])


def upload_pip(pyexe='python'):
# upload
subprocess.run([pyexe, '-m', 'twine', 'upload', 'dist/*'])


def clean_pip():
subprocess.run(['rm', '-fr', 'build', 'dist', 'openseespywin.egg-info'])


def upload_pip_test(pyexe='python'):
# upload
subprocess.run([pyexe, '-m', 'twine', 'upload',
'--repository', 'testpypi', 'dist/*'])


def install_pip_test(pyexe='python'):
subprocess.run([pyexe, '-m', 'pip', 'uninstall', '-y', 'openseespywin'])
subprocess.run([pyexe, '-m', 'pip', 'install', '--pre', '--no-cache-dir', '--index-url',
'https://test.pypi.org/simple/', 'openseespywin'])


def install_pip(pyexe='python'):
subprocess.run([pyexe, '-m', 'pip', 'uninstall', '-y', 'openseespywin'])
subprocess.run([pyexe, '-m', 'pip', 'install',
'--pre', '--no-cache-dir', 'openseespywin'])


# commands:
#
# pyexe - python excutable
#
# build pip
# build_pip pyexe build pyd use_zip/no_zip
# pyd - path to opensees.pyd
# use_zip - build the package to a zip file
# no_zip - build the package to a wheel file
#
# upload to testpypi
# build_pip pyexe upload-test
#
# upload to pypi
# build_pip pyexe upload
#
# test package from testpypi
# build_pip pyexe test-test
#
# test package from pypi
# build_pip pyexe test
#
if __name__ == "__main__":

if len(sys.argv) < 2:
print('build_pip pyexe cmd')
exit()

pyexe = sys.argv[1]

if sys.argv[2] == 'build':
if len(sys.argv) < 5:
print('buld_pip pyexe build pyd use_zip/no_zip')
exit()

pyd = sys.argv[3]
use_zip = False
if sys.argv[4] == 'use_zip':
use_zip = True

clean_pip()
copy_win_library(pyd)
build_pip(pyexe, use_zip=use_zip)

elif sys.argv[2] == 'upload-test':

if len(sys.argv) < 3:
print('buld_pip pyexe upload-test')
exit()
upload_pip_test(pyexe)

elif sys.argv[2] == 'upload':

if len(sys.argv) < 3:
print('buld_pip pyexe upload')
exit()

upload_pip(pyexe)

elif sys.argv[2] == 'test-test':

if len(sys.argv) < 3:
print('buld_pip pyexe test-test')
exit()

install_pip_test(pyexe)
subprocess.run(['pytest', '--pyargs', 'openseespywin.test'])

elif sys.argv[2] == 'test':

if len(sys.argv) < 3:
print('buld_pip pyexe test')
exit()

install_pip(pyexe)
subprocess.run(['pytest', '--pyargs', 'openseespywin.test'])
4 changes: 4 additions & 0 deletions openseespywin-pip/deploy-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage
codecov
pylint
twine
21 changes: 21 additions & 0 deletions openseespywin-pip/openseespywin/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 - 2020 Minjie Zhu

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.
30 changes: 30 additions & 0 deletions openseespywin-pip/openseespywin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ctypes
import sys

# only work for 64 bit system
if sys.maxsize < 2**31:
raise RuntimeError('64 bit system is required')

# platform dependent
if sys.platform.startswith('win'):

if sys.version_info[0] == 3 and sys.version_info[1] == 8:
dll_path = ''
for path in sys.path:
if 'DLLs' in path:
dll_path = path
break
ctypes.cdll.LoadLibrary(dll_path + '\\tcl86t.dll')

try:
from openseespywin.opensees import *
from openseespywin.version import *
except:
raise RuntimeError('Failed to import openseespy on Linux.')
else:
raise RuntimeError(
'Python version 3.8 is needed for Windows')

else:

raise RuntimeError('This package is for Windows only')
Empty file.
6 changes: 6 additions & 0 deletions openseespywin-pip/openseespywin/test_openseespywin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import openseespylinux as ops

ops.wipe()
ops.model('basic', '-ndm', 2, '-ndf', 3)

ops.node(1, 0.0, 0.0)
1 change: 1 addition & 0 deletions openseespywin-pip/openseespywin/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "3.2.2.9"
3 changes: 3 additions & 0 deletions openseespywin-pip/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
matplotlib
numpy
33 changes: 33 additions & 0 deletions openseespywin-pip/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import setuptools

about = {}
with open('openseespywin/version.py') as fp:
exec(fp.read(), about)

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="openseespywin",
version=about['version'],
author="Minjie Zhu",
author_email="zhum@oregonstate.edu",
description="A OpenSeesPy Windows package",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/openseespy/openseespy",
packages=setuptools.find_packages(),
package_data={
'': [
'opensees.pyd',
'LICENSE.md',
'*.dat',
'*.at2',],
},
license='LICENSE.md',
classifiers=[
"Programming Language :: Python :: 3.8",
'Operating System :: Microsoft :: Windows'],
platforms=["Windows"],
python_requires='>=3.6',
zip_safe=False)

0 comments on commit f99bcc1

Please sign in to comment.