diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-04-12 05:03:28 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-04-12 05:03:28 +0000 |
| commit | 4bfd559a8fd298cb21ab23fec07088af8af72cc2 (patch) | |
| tree | 16b25b6f1b71614493a4e91e8de9611e3a254462 /python-implicits.spec | |
| parent | 27428546930ccf476c51be0656c48c5666aa9d98 (diff) | |
automatic import of python-implicits
Diffstat (limited to 'python-implicits.spec')
| -rw-r--r-- | python-implicits.spec | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/python-implicits.spec b/python-implicits.spec new file mode 100644 index 0000000..b7263a5 --- /dev/null +++ b/python-implicits.spec @@ -0,0 +1,258 @@ +%global _empty_manifest_terminate_build 0 +Name: python-implicits +Version: 1.0.2 +Release: 1 +Summary: Implicit parameters in Python +License: MIT +URL: https://github.com/JadenGeller/Implicits +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/7b/76/0ea282a955c2893a49fc77e44f737f868855386089c3f1e3bed54752d448/implicits-1.0.2.tar.gz +BuildArch: noarch + + +%description +# Implicits +Global state can be hard to reason about, but piping dependencies from function to function is a pain. With implicits, you _explicitly_ which function parameters are _implicit_ dependencies. When you call the function, no need to explicilty provide these parameters; instead, the parameters will be implicitly passed! All that's required is that there exists local variables in scope that match the names of the parameters you're calling. +```python3 +@implicits("current_user") +def create_task(title, *, current_user): + print(f"{current_user} created a task titled '{title}'") + +current_user = "Jaden" +create_task("Hooray, a task!") # Jaden created a task titled 'Hooray, a task!' +create_task("Buy some trackpants") # Jaden created a task titled 'Buy some trackpants' +``` + +## Usage +1) Install via `pip install implicits`. +2) Import with `from implicits import implicits`. +3) Decorate using `@implicits("names", "of", "implicit", "parameters")`. + +## Example +```python3 +import logging +import boto3 + +from implicits import implicits + +class Giraffe: + @implicits("logger") + def __init__(self, name, *, logger): + self.name = name + logger.info(f"Creating a Giraffe named {name}") + + @property + @implicits("logger") + def full_name(self, *, logger): + logger.info(f"Getting {self.name}'s full name") + return f"{self.name} the Giraffe" + + @property + @implicits("food") + def is_hungry(self, *, food): + return "leaves" in food + +@implicits("logger") +def main(*, logger): + jeff = Giraffe("Jeff") # Creating a Giraffe named Jeff + name = jeff.full_name # Getting Jeff's full name + food = ["rocks", "dirt"] + logger.info(jeff.is_hungry) # False + food.append("leaves") + logger.info(jeff.is_hungry) # True + +logger = logging.getLogger() +logger.setLevel(logging.INFO) +logger.addHandler(logging.StreamHandler()) + +main() +``` + +## References + +I didn't invent this idea! Quite a few other languages support implicit parameters. The most mainstream of these languages is Scala. [Check out how implicits work in Scala!](https://docs.scala-lang.org/tour/implicit-parameters.html) + + + + +%package -n python3-implicits +Summary: Implicit parameters in Python +Provides: python-implicits +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-implicits +# Implicits +Global state can be hard to reason about, but piping dependencies from function to function is a pain. With implicits, you _explicitly_ which function parameters are _implicit_ dependencies. When you call the function, no need to explicilty provide these parameters; instead, the parameters will be implicitly passed! All that's required is that there exists local variables in scope that match the names of the parameters you're calling. +```python3 +@implicits("current_user") +def create_task(title, *, current_user): + print(f"{current_user} created a task titled '{title}'") + +current_user = "Jaden" +create_task("Hooray, a task!") # Jaden created a task titled 'Hooray, a task!' +create_task("Buy some trackpants") # Jaden created a task titled 'Buy some trackpants' +``` + +## Usage +1) Install via `pip install implicits`. +2) Import with `from implicits import implicits`. +3) Decorate using `@implicits("names", "of", "implicit", "parameters")`. + +## Example +```python3 +import logging +import boto3 + +from implicits import implicits + +class Giraffe: + @implicits("logger") + def __init__(self, name, *, logger): + self.name = name + logger.info(f"Creating a Giraffe named {name}") + + @property + @implicits("logger") + def full_name(self, *, logger): + logger.info(f"Getting {self.name}'s full name") + return f"{self.name} the Giraffe" + + @property + @implicits("food") + def is_hungry(self, *, food): + return "leaves" in food + +@implicits("logger") +def main(*, logger): + jeff = Giraffe("Jeff") # Creating a Giraffe named Jeff + name = jeff.full_name # Getting Jeff's full name + food = ["rocks", "dirt"] + logger.info(jeff.is_hungry) # False + food.append("leaves") + logger.info(jeff.is_hungry) # True + +logger = logging.getLogger() +logger.setLevel(logging.INFO) +logger.addHandler(logging.StreamHandler()) + +main() +``` + +## References + +I didn't invent this idea! Quite a few other languages support implicit parameters. The most mainstream of these languages is Scala. [Check out how implicits work in Scala!](https://docs.scala-lang.org/tour/implicit-parameters.html) + + + + +%package help +Summary: Development documents and examples for implicits +Provides: python3-implicits-doc +%description help +# Implicits +Global state can be hard to reason about, but piping dependencies from function to function is a pain. With implicits, you _explicitly_ which function parameters are _implicit_ dependencies. When you call the function, no need to explicilty provide these parameters; instead, the parameters will be implicitly passed! All that's required is that there exists local variables in scope that match the names of the parameters you're calling. +```python3 +@implicits("current_user") +def create_task(title, *, current_user): + print(f"{current_user} created a task titled '{title}'") + +current_user = "Jaden" +create_task("Hooray, a task!") # Jaden created a task titled 'Hooray, a task!' +create_task("Buy some trackpants") # Jaden created a task titled 'Buy some trackpants' +``` + +## Usage +1) Install via `pip install implicits`. +2) Import with `from implicits import implicits`. +3) Decorate using `@implicits("names", "of", "implicit", "parameters")`. + +## Example +```python3 +import logging +import boto3 + +from implicits import implicits + +class Giraffe: + @implicits("logger") + def __init__(self, name, *, logger): + self.name = name + logger.info(f"Creating a Giraffe named {name}") + + @property + @implicits("logger") + def full_name(self, *, logger): + logger.info(f"Getting {self.name}'s full name") + return f"{self.name} the Giraffe" + + @property + @implicits("food") + def is_hungry(self, *, food): + return "leaves" in food + +@implicits("logger") +def main(*, logger): + jeff = Giraffe("Jeff") # Creating a Giraffe named Jeff + name = jeff.full_name # Getting Jeff's full name + food = ["rocks", "dirt"] + logger.info(jeff.is_hungry) # False + food.append("leaves") + logger.info(jeff.is_hungry) # True + +logger = logging.getLogger() +logger.setLevel(logging.INFO) +logger.addHandler(logging.StreamHandler()) + +main() +``` + +## References + +I didn't invent this idea! Quite a few other languages support implicit parameters. The most mainstream of these languages is Scala. [Check out how implicits work in Scala!](https://docs.scala-lang.org/tour/implicit-parameters.html) + + + + +%prep +%autosetup -n implicits-1.0.2 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-implicits -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed Apr 12 2023 Python_Bot <Python_Bot@openeuler.org> - 1.0.2-1 +- Package Spec generated |
