ideas

Easy creation of custom import hooks to experiment on alternatives to Python's syntax; see https://aroberge.github.io/ideas/docs/html/

https://github.com/aroberge/ideas

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.6%) to scientific vocabulary

Keywords

hook import-hook import-hooks importlib python python-ideas
Last synced: 6 months ago · JSON representation

Repository

Easy creation of custom import hooks to experiment on alternatives to Python's syntax; see https://aroberge.github.io/ideas/docs/html/

Basic Info
  • Host: GitHub
  • Owner: aroberge
  • License: other
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 16.8 MB
Statistics
  • Stars: 83
  • Watchers: 4
  • Forks: 5
  • Open Issues: 26
  • Releases: 0
Topics
hook import-hook import-hooks importlib python python-ideas
Created about 6 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.md

ideas

Ideas: making it easier to extend Python’s syntax.

ideas logo

Documentation

Everything you need will eventually be found here.

Installation

python -m pip install ideas

Depending on your OS, you might need to write python3 or py instead of python in the above.

Dependencies

Some examples, using custom encoding, bytecode transformations or AST transformations do not work with Python 3.8 and/or later versions. However, they could be adapted to work with these later versions.

Usage

Suppose that you want to use function as a keyword in Python, to mean the same thing as lambda, enabling you to write

```python

my_program.py

square = function x: x**2 print(f"{square(4)} is the square of 4.")

if name == "main": print("This is run as the main module.") ```

You can do this using an import hook.

The simplest (but flawed) way to create such an import hook with ideas would be as follows:

```python from ideas import import_hook

def transform(source, **kwargs): return source.replace("function", "lambda")

importhook.createhook(transform_source=transform) ```

Then, you'd need to use it. Since there is already an example import hook that does this, we'll use it instead. All you have to do is instruct Python to add the import hook, and it will be used from that point on. There are two ways to do so.

The first method would be to create a second file which adds the required import hook and then imports your program.

```python

Let's call this 'loader.py'

from ideas.examples import functionkeyword functionkeyword.add_hook()

import my_program ```

You could then run this second file the normal way.

python loader.py

So, my_program.py , and any other module that could be loaded by it would recognize that function is a valid alternative to lambda. However, using this method, loader would be the __main__ script, and the code block defined by if __name__ == "__main__": in my_program would be ignored.

The second way is to skip the creation of a loader, and run my_program directly using ideas:

python -m ideas my_program -t function_keyword This method will ensure that my_program is the __main__ module.

Many more examples can be found in the documentation, including a better way to create such an import hook and information about a console (REPL) that supports code transformations.

Tools

This project uses black for formatting, pytest for running tests, and flake8 for linting with custom settings compatible with black.

Contact

You can either file an issue or email me at Andre.Roberge@gmail.com.

License

MIT

Infrequently asked questions, comments and answers

As I write (and occasionally update) this README file, nobody else knows about this project. So, it is impossible for there to be some Frequently Asked Questions. In their absence, the following imaginary dialogue has been written.

Why?

Because it is fun. If this is not enough of a justification for you, have a look at motivation which contains a longer, and possibly more serious answer.

Is it safe to use in production code?

Most probably not.

But your example works perfectly well in my code; can I use it in my project?

I don't think you should if your project is to be used by anyone else but yourself.

I found a bug.

Wonderful, please file an issue so that I can attempt to fix it. Note however that some examples are just proof of concepts and are not meant to be robust.

Can I contribute code for a new example?

Yes, please, by all means. But I suggest that you first create an issue that gives an overview of what you wish to accomplish.

I found a cool use of import hooks in another project, different from all of your examples. Could you include it?

Please, give me the details, and I will see if I can easily include a similar example and if I think it is worthwhile to do so.

I think that the explanation you have written for X could be improved upon.

Please tell me more by filing an issue first and possibly creating a pull-request afterwards.

I have an idea for a new example, but do not know how to write the code for it.

First, make sure you go through all the existing examples to confirm that none can easily be adapted to do what you want. If that is the case, file an issue ... but please don't be offended if I don't write code for it and end up closing the issue: I already have too many ideas of my own for this project, too many other projects, and not enough time to do all that I want.

That being said, I do like tinkering with import hooks ...

In file X.py, you do not respect convention Y from PEP-8. This is unacceptable in a Python project.

Seriously? This project is all about exploring potential changes to Python's syntax, some of which are downright crazy, and you complain about a PEP-8 violation? ...

Ok, perhaps you can tell me, and I will see if it makes sense to change what I wrote.

People from the Python-ideas mailing lists mentioned that I should look at this project for my idea, but I don't know where to start.

Please, have a look at the documentation. If you go through all the examples in the order that they are presented, you might learn how to implement your idea.

What about something like from __future__ import braces?

No. See Examples that will never be included.

You're no fun. Anyway, why this silly name for a project? The word "ideas" has nothing to do with import hooks in Python.

For this project, I was thinking of using importhook (singular) or importhooks (plural). However, there is already a project named importhook on Pypi and I thought that using the plural form would likely be just too confusing.

I settled on ideas as I am guessing that the main application would be for people to try out suggestions from or for python-ideas. A few days later, I came up with the above image and this cemented my highly subjective opinion that this choice of name might not such a bad idea.

Anyway, enough of this banter. If you want to know more about this project, please consult the documentation.

Owner

  • Name: André Roberge
  • Login: aroberge
  • Kind: user
  • Location: Halifax, Canada
  • Company: Programming for fun :-)

An eternal beginner who loves doing unusual stuff with Python, most often with a focus on education.

GitHub Events

Total
  • Issues event: 2
  • Watch event: 6
  • Fork event: 1
Last Year
  • Issues event: 2
  • Watch event: 6
  • Fork event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 230
  • Total Committers: 4
  • Avg Commits per committer: 57.5
  • Development Distribution Score (DDS): 0.052
Past Year
  • Commits: 12
  • Committers: 3
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.417
Top Committers
Name Email Commits
André Roberge a****e@g****m 218
Tom Cook t****k@l****m 7
Devin J. Pohly d****y@g****m 4
Stanislav Zmiev s****0@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 41
  • Total pull requests: 10
  • Average time to close issues: 4 days
  • Average time to close pull requests: 19 days
  • Total issue authors: 7
  • Total pull request authors: 5
  • Average comments per issue: 1.59
  • Average comments per pull request: 1.6
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • aroberge (27)
  • Ovsyanka83 (6)
  • skirpichev (4)
  • spapas (1)
  • jrmoserbaltimore (1)
  • Keyacom (1)
  • grigandal625 (1)
Pull Request Authors
  • djpohly (4)
  • tomkcook (3)
  • skirpichev (2)
  • Ovsyanka83 (1)
  • aroberge (1)
Top Labels
Issue Labels
Possible additional example (7) bug (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 329 last-month
  • Total dependent packages: 6
  • Total dependent repositories: 5
  • Total versions: 43
  • Total maintainers: 1
pypi.org: ideas

Easy creation of import hooks to test ideas.

  • Versions: 43
  • Dependent Packages: 6
  • Dependent Repositories: 5
  • Downloads: 329 Last month
Rankings
Dependent packages count: 1.6%
Dependent repos count: 6.6%
Stargazers count: 8.1%
Average: 9.4%
Forks count: 13.3%
Downloads: 17.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

poetry.lock pypi
  • atomicwrites 1.4.0 develop
  • attrs 21.4.0 develop
  • black 22.3.0 develop
  • cfgv 3.3.1 develop
  • click 8.1.3 develop
  • colorama 0.4.4 develop
  • distlib 0.3.4 develop
  • filelock 3.7.0 develop
  • flake8 4.0.1 develop
  • identify 2.5.1 develop
  • importlib-metadata 4.2.0 develop
  • iniconfig 1.1.1 develop
  • mccabe 0.6.1 develop
  • mypy-extensions 0.4.3 develop
  • nodeenv 1.6.0 develop
  • packaging 21.3 develop
  • pathspec 0.9.0 develop
  • platformdirs 2.5.2 develop
  • pluggy 1.0.0 develop
  • pre-commit 2.19.0 develop
  • py 1.11.0 develop
  • pycodestyle 2.8.0 develop
  • pyflakes 2.4.0 develop
  • pyparsing 3.0.9 develop
  • pytest 7.1.2 develop
  • pyyaml 6.0 develop
  • six 1.16.0 develop
  • toml 0.10.2 develop
  • tomli 2.0.1 develop
  • typed-ast 1.5.4 develop
  • typing-extensions 4.2.0 develop
  • virtualenv 20.14.1 develop
  • zipp 3.8.0 develop
  • token-utils 0.1.8
pyproject.toml pypi
  • black ^22.3.0 develop
  • flake8 ^4.0.1 develop
  • pre-commit ^2.19.0 develop
  • pytest ^7.1.2 develop
  • python ^3.7
  • token-utils ^0.1.8
requirements.txt pypi
  • token-utils *
setup.py pypi
  • token-utils *