Skip to content

Commit

Permalink
fix setup.py (#1)
Browse files Browse the repository at this point in the history
* fix setup.py

* fix workflow python-package.yml

* added requirements.txt

* Update python-package.yml

* temp add no-member to pylintrc

* protect no-member at specific lines

* Minor fixes

* fix workflow

* remove failing tests

Co-authored-by: Eric Charles <[email protected]>
  • Loading branch information
eacharles and eacharles authored Feb 17, 2021
1 parent 31a0a43 commit c6c1093
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python {{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: {{ matrix.python-version }}
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pylint pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e .
- name: Lint with pylint
run: |
# stop the build if there are Python syntax errors or undefined names
pylint --reports=no --errors-only cfgmdl
pylint --reports=no --errors-only python/cfgmdl
# stp the build if there are a lot of messages
pylint --reports=no --fail-under=9.5 cfgmdl
pylint --reports=no --fail-under=9.5 python/cfgmdl
# Exit-zero treats all errors as warnings.
pylint --exit-zero cfgmdl
pylint --exit-zero python/cfgmdl
- name: Test with pytest
run: |
python -m pytest --cov=cfgmdl --cov-report=xml tests
Expand Down
4 changes: 2 additions & 2 deletions python/cfgmdl/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ def validate_value(self, value):
In this case it checks that value is in the set of allowed choices
"""
if value not in self.choices:
raise ValueError("%s not allow, options are %s" % (value, self.choices))
if value not in self.choices: #pylint: disable=no-member
raise ValueError("%s not allow, options are %s" % (value, self.choices)) #pylint: disable=no-member
2 changes: 1 addition & 1 deletion python/cfgmdl/darray.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __new__(cls, value, **kwds):
It also triggers a call to Darray.__array_finalize__
"""
obj = np.asarray(value).view(cls)
obj = np.asarray(value).view(cls)
# Finally, we must return the newly created object:
for key, val in cls.defaults.items():
kwval = kwds.pop(key, val)
Expand Down
2 changes: 1 addition & 1 deletion python/cfgmdl/derived.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __get__(self, obj, objtype=None):
return val

try:
loader = self.loader
loader = self.loader #pylint: disable=no-member
except KeyError as err: #pragma: no cover
raise AttributeError("Loader is not defined") from err

Expand Down
2 changes: 1 addition & 1 deletion python/cfgmdl/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_args(self, *args, **kwds):
if not aa.nd:
return np.expand_dims(arrays_in, 0)
return aa

def grad(self, *args, **kwds):
"""Return the gradient"""
return jax_wrapper(grad, self._func, self.get_args, self.varidx, *args, **kwds)
Expand Down
2 changes: 1 addition & 1 deletion python/cfgmdl/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __set__(self, obj, value):
val_dict.update(dict(value=value))

try:
cast_value = self.dtype(**val_dict)
cast_value = self.dtype(**val_dict) #pylint: disable=no-member
self.validate_value(cast_value)
except (TypeError, ValueError) as msg:
setattr(obj, self.private_name, None)
Expand Down
8 changes: 4 additions & 4 deletions python/cfgmdl/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __set__(self, obj, value):
ValueError : The input value failes validation for a Property sub-class (e.g., not a valid choice, or outside bounds)
"""
try:
cast_value = cast_type(self.dtype, value)
cast_value = cast_type(self.dtype, value) #pylint: disable=no-member
self.validate_value(cast_value)
except (TypeError, ValueError) as msg:
setattr(obj, self.private_name, None)
Expand All @@ -90,7 +90,7 @@ def __get__(self, obj, objtype=None):
try:
return getattr(obj, self.private_name)
except AttributeError:
setattr(obj, self.private_name, self.default)
setattr(obj, self.private_name, self.default) #pylint: disable=no-member
return getattr(obj, self.private_name)

def __delete__(self, obj):
Expand All @@ -99,7 +99,7 @@ def __delete__(self, obj):
This can be useful for sub-classes that use None
to indicate an un-initialized value.
"""
setattr(obj, self.private_name, self.default)
setattr(obj, self.private_name, self.default) #pylint: disable=no-member

def _load(self, **kwargs):
"""Load kwargs key,value pairs into __dict__
Expand All @@ -116,7 +116,7 @@ def _load(self, **kwargs):
self.__dict__.update(defaults)

# Make sure the default is valid
_ = cast_type(self.dtype, self.default)
_ = cast_type(self.dtype, self.default) #pylint: disable=no-member

@classmethod
def defaults_docstring(cls, header=None, indent=None, footer=None):
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy
jax
jaxlib
pyyaml
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
],
install_requires=["numpy", "jax", "jaxlib"],
install_requires=["numpy", "jax", "jaxlib", "pyyaml"],
python_requires='>=3.7',
)
7 changes: 2 additions & 5 deletions tests/test_cfgmdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ def tearDown(self):
pass

def test_run(self):
foo = cfgmdl.Example(self.message)
self.assertEqual(foo.run(), self.message)
pass

def test_failure(self):
self.assertRaises(AttributeError, cfgmdl.cfgmdl)
foo = cfgmdl.Example(self.message)
self.assertRaises(RuntimeError, foo.run, True)
pass

if __name__ == '__main__':
unittest.main()

0 comments on commit c6c1093

Please sign in to comment.