Skip to content

Commit a0cfd7c

Browse files
committed
Created Packaging branch
Update test_1.py Update setup.py
1 parent 7acb976 commit a0cfd7c

12 files changed

+207
-49
lines changed

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1+
*.venv
2+
3+
*~
4+
*.pyc
5+
*.cpython*.so
16
__pycache__
2-
.venv
7+
../build
8+
dist
9+
*egg-info
10+
*.pyc

AUTHORS

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
W. Beck Andrews <[email protected]>
2+
Xander Mensah <[email protected]>
3+
Katsuyo Thornton <[email protected]>

BinaryTests.py

-46
This file was deleted.

LICENSE.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

BinarySystems.py ammber/BinarySystems.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from scipy.interpolate import CubicSpline
44
import numpy as np
55
from pycalphad import calculate
6-
import PRISMS_PF_fileGen
6+
from PRISMS_PF_fileGen import write_binary_isothermal_parabolic_parameters
77
class BinaryIsothermalDiscretePhase:
88
"Class representing a single phase at one temperature described by a set of points in composition-Gibbs free energy space"
99
def __init__(self, xdata, Gdata):

PRISMS_PF_fileGen.py ammber/PRISMS_PF_fileGen.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
def binary_isothermal_write_parabolic_parameters(binaryIsothermalSys, output_file, template_file, phases=None, component="comp_1"):
1+
def write_binary_isothermal_parabolic_parameters(binaryIsothermalSys, output_file, template_file, phases=None, component="comp_1"):
22
"""
33
Creates a parameters file from a BinaryIsothermal2ndOrderSystem
44
55
Parameters
66
----------
7+
binaryIsothermalSys : BinaryIsothermal2ndOrderSystem
8+
system to draw parameters from
79
output_file : string
810
path to file to create
911
template_file : string

ammber/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
ammber.
3+
4+
A Python package for parametrizing gibbs free energy curves for phase-field modeling.
5+
"""
6+
7+
__version__ = "0.1.0"
8+
__author__ = 'Xander or Beck or Katsuyo'
9+
__credits__ = 'University of Michigan'

maintenance/copyright.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
#
3+
4+
5+
import os
6+
import sys
7+
from collections import defaultdict
8+
from datetime import datetime
9+
from subprocess import Popen, PIPE
10+
11+
root = os.path.dirname(sys.argv[0])
12+
13+
14+
def read_authors(fn):
15+
return {email.strip('<>'): name for name, email in
16+
[line.rsplit(maxsplit=1) for line in open(fn, 'r')]}
17+
18+
19+
def parse_git_log(log, authors):
20+
committers = defaultdict(set)
21+
author = None
22+
date = None
23+
for line in log.decode('utf-8').split('\n'):
24+
if line.startswith('commit'):
25+
if date is not None and author is not None:
26+
committers[author].add(date.year)
27+
elif line.startswith('Author:'):
28+
email = line.rsplit('<', maxsplit=1)[1][:-1]
29+
elif line.startswith('Date:'):
30+
date = datetime.strptime(line[5:].rsplit(maxsplit=1)[0].strip(),
31+
'%a %b %d %H:%M:%S %Y')
32+
try:
33+
author = authors[email]
34+
except KeyError:
35+
author = email
36+
elif 'copyright' in line.lower() or 'license' in line.lower():
37+
date = None
38+
if date is not None:
39+
committers[author].add(date.year)
40+
return committers
41+
42+
43+
def pretty_years(years):
44+
years = sorted(years)
45+
prev_year = prev_out = years[0]
46+
s = '{}'.format(prev_year)
47+
for year in years[1:]:
48+
if year - prev_year > 1:
49+
if year - prev_out > 1:
50+
if prev_year == prev_out:
51+
s = '{}, {}'.format(s, year)
52+
else:
53+
s = '{}-{}, {}'.format(s, prev_year, year)
54+
else:
55+
s = '{}, {}'.format(s, prev_year)
56+
prev_out = year
57+
prev_year = year
58+
if prev_year - prev_out == 1:
59+
s = '{}-{}'.format(s, prev_year)
60+
elif prev_year - prev_out > 1:
61+
s = '{}, {}'.format(s, prev_year)
62+
return s
63+
64+
65+
authors = read_authors('{}/../AUTHORS'.format(root))
66+
67+
process = Popen(['git', 'log', '--follow', sys.argv[1]], stdout=PIPE,
68+
stderr=PIPE)
69+
stdout, stderr = process.communicate()
70+
committers = parse_git_log(stdout, authors)
71+
72+
prefix = 'Copyright'
73+
for name, years in committers.items():
74+
print('{} {} {}'.format(prefix, pretty_years(years), name))
75+
prefix = ' ' * len(prefix)
76+
print()

maintenance/replace_header.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
#
3+
4+
5+
import sys
6+
7+
file_lines = open(sys.argv[1], 'r').readlines()
8+
header_lines = sys.stdin.readlines()
9+
10+
while file_lines[0].startswith('#'):
11+
file_lines = file_lines[1:]
12+
13+
file_lines.insert(0, '#\n')
14+
for header_line in header_lines[::-1]:
15+
file_lines.insert(0, '# {}'.format(header_line).strip() + '\n')
16+
file_lines.insert(0, '#\n')
17+
18+
open(sys.argv[1], 'w').writelines(file_lines)

maintenance/update_license_headers.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /bin/sh
2+
# Updates all Python files with license taken from README.md and copyright information obtained from the git log.
3+
4+
for fn in setup.py `find ammber test -name "*.py"`; do
5+
echo $fn
6+
python3 maintenance/copyright.py $fn | cat - LICENSE.md | python3 maintenance/replace_header.py $fn
7+
done

setup.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Copyright 2024 William Beck Andrews
3+
#
4+
# MIT License
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
#
24+
25+
from setuptools import setup
26+
27+
setup(
28+
name='ammber',
29+
version='0.1.0',
30+
description='A Python package for parametrizing gibbs free energy curves for phase-field modeling',
31+
url='https://github.com/UMThorntongroup/',
32+
author='W. Beck Andrews',
33+
author_email='[email protected]',
34+
license='MIT',
35+
test_suite='tests',
36+
packages=['ammber'],
37+
install_requires=['numpy<2.0',
38+
'scipy',
39+
'pycalphad'
40+
],
41+
42+
classifiers=[
43+
'Development Status :: 1 - Planning',
44+
'Intended Audience :: Science/Research',
45+
'License :: OSI Approved :: MIT License',
46+
'Programming Language :: Python :: 2',
47+
'Programming Language :: Python :: 2.7',
48+
'Programming Language :: Python :: 3',
49+
'Programming Language :: Python :: 3.4',
50+
'Programming Language :: Python :: 3.5',
51+
],
52+
)

test/test_1.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Tests functions
3+
"""
4+
5+
import ammber.BinarySystems as BS
6+
7+
8+
def test_01():
9+
phase1 = BS.BinaryIsothermal2ndOrderPhase(fmin = 0, kwell= 1, cmin= 0.5)
10+
assert (phase1.free_energy(0.5) == 0)

0 commit comments

Comments
 (0)