Skip to content

Commit

Permalink
Rearrange for pypi packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
xnx committed Jul 29, 2022
1 parent 3dad114 commit 612bda9
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 67 deletions.
File renamed without changes.
27 changes: 0 additions & 27 deletions README.md

This file was deleted.

68 changes: 68 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
********************
Introduction to PyQn
********************



PyQn is a Python package for parsing, validating, manipulating and
transforming physical quantities and their units.

Units are specified as strings using a simple and flexible syntax,
and may be compared, output in different formats and manipulated using a
variety of predefined Python methods.



Installation:
=============

The PyQn package can be installed either from PyPI_ using pip

.. code-block:: bash
python3 -m pip install pyqn
or from the source by running (one of the two) from the project source directory.

.. code-block:: bash
# either
python setup.py install
# or
python3 -m pip install .
Examples:
=========

Units
-----
The units of physical quantities are represented by the ``Units`` class. A
``Units`` object is instantiated from a valid units string and supports ions,
isotopologues, as well as a few special species. This object contains
attributes including the dimensions, HTML and LaTeX representations, and
methods for conversion to different compatible units.

.. code-block:: pycon
>>> from pyqn.units import Units
>>> u1 = Units('km')
>>> u2 = Units('hr')
>>> u3 = u1/u2
>>> print(u3)
km.hr-1
>>> u4 = Units('m/s')
>>> u3.conversion(u4) # OK: can convert from km/hr to m/s
Out[7]: 0.2777777777777778
>>> u3.conversion(u2) # Oops: can't convert from km/hr to m!
...
UnitsError: Failure in units conversion: units km.hr-1[L.T-1] and hr[T] have
different dimensions
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>=43", "wheel"]
build-backend = "setuptools.build_meta"
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[metadata]
# This includes the license file(s) in the wheel (requires setuptools>=42)
license_files = LICENSE
55 changes: 44 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
from setuptools import setup, find_packages
setup(
name = 'pyqn',
version = '1.2.2',
packages = find_packages(),
author = 'Christian Hill',
url = 'https://github.com/xnx/pyqn',
license = 'GPL',
author_email = '[email protected]',

from pathlib import Path

description = 'A package for managing physical units and quantities',
)
root = Path(__file__).parent.resolve()

# Get the long description from the README file
long_description = (root / "README.rst").read_text(encoding="utf-8")

setup(
name="pyqn",
version="1.3",
description="A package for managing physical units and quantities",
long_description=long_description,
long_description_content_type="text/x-rst",
url="https://github.com/xnx/pyqn",
author="Christian Hill",
author_email="[email protected]",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Chemistry",
"Topic :: Scientific/Engineering :: Physics",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
"Operating System :: OS Independent",
],
keywords="chemistry, units, physical quantities, unit conversion",
package_dir={"": "src"},
packages=find_packages(where="src"),
python_requires=">=3.6",
install_requires=[
"pyparsing>=2.3",
'importlib-resources>=1.0; python_version < "3.7.0"',
],
extras_require={"dev": ["black", "pytest-cov", "tox", "ipython"]},
# package_data will include all the resolved globs into both the wheel and sdist
#package_data={},
# no need for MANIFEST.in, which should be reserved only for build-time files
project_urls={
"Bug Reports": "https://github.com/xnx/pyqn/issues",
},
)
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions pyqn/base_unit.py → src/pyqn/base_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __str__(self):
BaseUnit('k', 'kayser', 'wavenumber', 100., '', 'k', d_length**-1),
BaseUnit('D', 'debye', 'electric dipole moment', 1.e-21/299792458., '', 'D',
d_charge * d_length),
BaseUnit('hbar', 'hbar', 'angular momentum', 1.05457148e-34, '', '\hbar',
BaseUnit('hbar', 'hbar', 'angular momentum', 1.05457148e-34, '', r'\hbar',
Dimensions(L=2, M=1, T=-1)),
BaseUnit('e', 'electron charge', 'charge', 1.602176565e-19, '', 'e', d_charge),
]),
Expand Down Expand Up @@ -144,7 +144,7 @@ def __str__(self):

('Non-SI units of length, area and volume', [
# Non-SI length units
BaseUnit('Å', 'angstrom', 'length', 1.e-10, '', '\AA', d_length),
BaseUnit('Å', 'angstrom', 'length', 1.e-10, '', r'\AA', d_length),
BaseUnit('a0', 'bohr', 'length', 5.2917721092e-11, '', 'a_0', d_length),
# Non-SI area units
BaseUnit('b', 'barn', 'area', 1.e-28, '', 'b', d_area),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 17 additions & 17 deletions pyqn/quantity.py → src/pyqn/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import re
import math
import numpy as np
#import numpy as np
from .symbol import Symbol
from .units import Units, UnitsError

Expand Down Expand Up @@ -167,21 +167,21 @@ def convert_units_to(self, new_units, force=None):
else:
return Quantity(value = self.value*fac, units = new_units)

def draw_from_dist(self, shape=None):
"""
Return a value or number array of values drawn from the normal
distribution described by this Quantity's mean and standard
deviation. shape is the shape of the NumPy array to return, or
None (the default) to return a single scalar value from the
distribution.
"""

if self.sd is None:
raise ValueError('Quantity instance {} has no defined standard'
' deviation.'.format(self.name))

return np.random.normal(loc=self.value, scale=self.sd, size=shape)
# def draw_from_dist(self, shape=None):
# """
# Return a value or number array of values drawn from the normal
# distribution described by this Quantity's mean and standard
# deviation. shape is the shape of the NumPy array to return, or
# None (the default) to return a single scalar value from the
# distribution.
#
# """
#
# if self.sd is None:
# raise ValueError('Quantity instance {} has no defined standard'
# ' deviation.'.format(self.name))
#
# return np.random.normal(loc=self.value, scale=self.sd, size=shape)

def __add__(self, other):
"""
Expand Down Expand Up @@ -311,7 +311,7 @@ def parse(self, s_quantity, name=None, units=None, sd=None,
else:
s_mantsd = s_valsd
exp = 0
patt = '([+-]?\d*\.?\d*)\(?(\d+)?\)?'
patt = r'([+-]?\d*\.?\d*)\(?(\d+)?\)?'
m = re.match(patt, s_mantsd)
if not m:
raise QuantityError('Failed to parse string into quantity:\n'\
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Unit tests for unit conversions within the Units class.

import unittest
from ..units import Units, UnitsError
from pyqn.units import Units, UnitsError

class UnitsConversionCheck(unittest.TestCase):
"""Unit tests for unit conversions within the Units class."""
Expand Down
8 changes: 4 additions & 4 deletions pyqn/tests/test_quantity.py → tests/test_quantity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from ..quantity import Quantity, QuantityError
from ..dimensions import Dimensions, d_energy
from ..units import UnitsError
from pyqn.quantity import Quantity, QuantityError
from pyqn.dimensions import Dimensions, d_energy
from pyqn.units import UnitsError

class QuantityManipulations(unittest.TestCase):
def test_quantity_init(self):
Expand Down Expand Up @@ -77,4 +77,4 @@ def test_quantity_conversion(self):
pass

if __name__ == '__main__':
unittest.main()
unittest.main()
4 changes: 2 additions & 2 deletions pyqn/tests/test_units.py → tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# Unit tests for the Units class.

import unittest
from ..units import Units
from ..dimensions import Dimensions,d_energy
from pyqn.units import Units
from pyqn.dimensions import Dimensions,d_energy

class UnitsCheck(unittest.TestCase):
"""Unit tests for the Units class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# of "min" for minutes.

import unittest
from ..units import Units
from ..base_unit import base_units
from ..si import si_prefixes
from pyqn.units import Units
from pyqn.base_unit import base_units
from pyqn.si import si_prefixes

class ConflictsCheck(unittest.TestCase):
"""
Expand Down

0 comments on commit 612bda9

Please sign in to comment.