Skip to content

Commit

Permalink
remove black as a dependency (#1343)
Browse files Browse the repository at this point in the history
* this change breaks API by removing
  the "asblack" functionality from
  all types
  • Loading branch information
molpopgen authored Nov 27, 2024
1 parent 0527741 commit 368d6da
Show file tree
Hide file tree
Showing 18 changed files with 10 additions and 83 deletions.
8 changes: 4 additions & 4 deletions doc/pages/genetic_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ For some background, see {ref}`definitions`.

```{eval-rst}
.. autoclass:: fwdpy11.Additive
:members: asdict, fromdict, asblack, shape, genetic_values, maps_to_fitness, maps_to_trait_value
:members: asdict, fromdict, shape, genetic_values, maps_to_fitness, maps_to_trait_value
```

```{eval-rst}
.. autoclass:: fwdpy11.Multiplicative
:members: asdict, fromdict, asblack, shape, genetic_values, maps_to_fitness, maps_to_trait_value
:members: asdict, fromdict, shape, genetic_values, maps_to_fitness, maps_to_trait_value
```

```{eval-rst}
.. autoclass:: fwdpy11.GBR
:members: asdict, fromdict, asblack, shape, genetic_values, maps_to_fitness, maps_to_trait_value
:members: asdict, fromdict, shape, genetic_values, maps_to_fitness, maps_to_trait_value
```

```{eval-rst}
.. autoclass:: fwdpy11.AdditivePleiotropy
:members: asdict, fromdict, asblack, shape, genetic_values, maps_to_fitness, maps_to_trait_value
:members: asdict, fromdict, shape, genetic_values, maps_to_fitness, maps_to_trait_value
```
4 changes: 2 additions & 2 deletions doc/pages/gvalue_to_fitness.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

```{eval-rst}
.. autoclass:: fwdpy11.Optimum
:members: asdict, fromdict, asblack
:members: asdict, fromdict
```

```{eval-rst}
.. autoclass:: fwdpy11.PleiotropicOptima
:members: asdict, fromdict, asblack
:members: asdict, fromdict
```


Expand Down
2 changes: 1 addition & 1 deletion doc/pages/gvaluenoise.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

```{eval-rst}
.. autoclass:: fwdpy11.GaussianNoise
:members: asdict, fromdict, asblack
:members: asdict, fromdict
```


2 changes: 1 addition & 1 deletion doc/short_vignettes/mutationdominance_vignette.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ for s in np.arange(0.1, 1, 0.1):

```{code-cell}
des = fwdpy11.DiscreteDESD(beg=0, end=1, weight=1, joint_dist=joint_dist)
print(des.asblack())
print(des)
```

The result is that mutations with smaller effect sizes are more common (larger weights) and more dominant.
2 changes: 1 addition & 1 deletion doc/short_vignettes/workingexample_fitness.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ params = fwdpy11.ModelParams(**p)
Let's take a look at what he have:

```{code-cell}
print(params.asblack())
print(params)
```

Let's explain a few new things:
Expand Down
2 changes: 1 addition & 1 deletion doc/short_vignettes/workingexample_trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ params = fwdpy11.ModelParams(**p)
```

```{code-cell}
print(params.asblack())
print(params)
```

## Modifying model parameters
Expand Down
2 changes: 0 additions & 2 deletions fwdpy11/_types/demographic_model_citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
from deprecated import deprecated

from fwdpy11.class_decorators import (
attr_add_asblack,
attr_class_pickle,
attr_class_to_from_dict,
)


@attr_add_asblack
@attr_class_pickle
@attr_class_to_from_dict
@attr.s(kw_only=True, frozen=True, auto_attribs=True, repr_ns="fwdpy11")
Expand Down
2 changes: 0 additions & 2 deletions fwdpy11/_types/demographic_model_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from deprecated import deprecated

from ..class_decorators import (
attr_add_asblack,
attr_class_pickle,
attr_class_to_from_dict_no_recurse,
)
Expand All @@ -14,7 +13,6 @@
from .forward_demes_graph import ForwardDemesGraph


@attr_add_asblack
@attr_class_pickle
@attr_class_to_from_dict_no_recurse
@attr.s(kw_only=True, frozen=True, auto_attribs=True, repr_ns="fwdpy11")
Expand Down
3 changes: 0 additions & 3 deletions fwdpy11/_types/model_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
import fwdpy11
import numpy as np
from fwdpy11.class_decorators import (
attr_add_asblack,
attr_class_to_from_dict_no_recurse,
)

from fwdpy11._types.demographic_model_details import DemographicModelDetails
from fwdpy11._types.forward_demes_graph import ForwardDemesGraph


@attr_add_asblack
@attr_class_to_from_dict_no_recurse
@attr.s(kw_only=True, frozen=True, slots=True, repr_ns="fwdpy11")
class MutationAndRecombinationRates(object):
Expand Down Expand Up @@ -112,7 +110,6 @@ def validate_timings(
return gvalue.validate_timings(deme, demography)


@attr_add_asblack
@attr_class_to_from_dict_no_recurse
@attr.s(kw_only=True, frozen=True, slots=True, repr_ns="fwdpy11")
class ModelParams(object):
Expand Down
25 changes: 0 additions & 25 deletions fwdpy11/class_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,6 @@ def setstate(self, d):
return _add_getstate(cls)


def attr_add_asblack(cls):
"""
The default __repr__ from attrs isn't readable
for complex classes. This adds a method
for pretty-printing out the class using black's
formatting rules
"""

def _asblack(self):
"""
Return a string representation formatted with black
"""
import black

# The try/except is to handle black's changing API
try:
return black.format_str(str(self), mode=black.Mode())
except AttributeError:
return black.format_str(str(self), mode=black.FileMode())

cls.asblack = _asblack

return cls


def region_custom_repr(cls):
"""
Custom repr to correctly display weight for region instances
Expand Down
6 changes: 0 additions & 6 deletions fwdpy11/genetic_map_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import fwdpy11._fwdpy11

from .class_decorators import (
attr_add_asblack,
attr_class_pickle_with_super,
attr_class_to_from_dict,
)
Expand All @@ -35,7 +34,6 @@ def _is_integer_if_discrete(self, attribute, value):
attr.validators.instance_of(int)(self, attribute, value)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -90,7 +88,6 @@ def __attrs_post_init__(self):
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -203,7 +200,6 @@ def __attrs_post_init__(self):
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -257,7 +253,6 @@ def __attrs_post_init__(self):
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -315,7 +310,6 @@ def __attrs_post_init__(self):
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down
9 changes: 0 additions & 9 deletions fwdpy11/genetic_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
_PyDiploidGeneticValue,
)
from .class_decorators import (
attr_add_asblack,
attr_class_pickle_with_super,
attr_class_to_from_dict,
attr_class_to_from_dict_no_recurse,
Expand All @@ -56,7 +55,6 @@ class TimingError(Exception):
pass


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -96,7 +94,6 @@ def __attrs_post_init__(self):
super(Optimum, self).__init__(self.optimum, self.VS, self.when)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11", eq=False)
Expand Down Expand Up @@ -225,7 +222,6 @@ def validate_timings(self, deme: int, demography: ForwardDemesGraph) -> None:
raise TimingError(msg)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand All @@ -243,7 +239,6 @@ def __attrs_post_init__(self):
super(NoNoise, self).__init__()


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -272,7 +267,6 @@ def __attrs_post_init__(self):
super(GaussianNoise, self).__init__(self.sd, self.mean)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict_no_recurse
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -324,7 +318,6 @@ def validate_timings(self, deme: int, demography: ForwardDemesGraph) -> None:
self.gvalue_to_fitness.validate_timings(deme, demography)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict_no_recurse
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -376,7 +369,6 @@ def validate_timings(self, deme: int, demography: ForwardDemesGraph) -> None:
self.gvalue_to_fitness.validate_timings(deme, demography)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict_no_recurse
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down Expand Up @@ -417,7 +409,6 @@ def validate_timings(self, deme: int, demography: ForwardDemesGraph) -> None:
self.gvalue_to_fitness.validate_timings(deme, demography)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict_no_recurse
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down
5 changes: 0 additions & 5 deletions fwdpy11/mutation_dominance.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import fwdpy11._fwdpy11

from .class_decorators import (
attr_add_asblack,
attr_class_to_from_dict,
attr_class_pickle_with_super,
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand All @@ -48,7 +46,6 @@ def __attrs_post_init__(self):
super(FixedDominance, self).__init__(fwdpy11._fwdpy11._fixed_dominance(self.h))


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand All @@ -70,7 +67,6 @@ def __attrs_post_init__(self):
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand All @@ -95,7 +91,6 @@ def __attrs_post_init__(self):
)


@attr_add_asblack
@attr_class_pickle_with_super
@attr_class_to_from_dict
@attr.s(auto_attribs=True, frozen=True, repr_ns="fwdpy11")
Expand Down
Loading

0 comments on commit 368d6da

Please sign in to comment.