iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🈲

[Not Recommended] Manual Installation and Import of Rubicon-ObjC

に公開
2026/11/16

🚸️ Usage Notes ⛔️

Obtaining Rubicon-ObjC

Get it using whichever method is easiest for you.

GitHub

Repository top

Along with the release pages below, you can download it as a .zip file from the browser.

(In my case, I clone it using WorkingCopy)

v0.4.8 release version

(Thanks to this version, I can easily develop on Pythonista3)

pip

pip install rubicon-objc

Adjustments on i(Pad)OS

Extracting the necessary data

Since I will be rewriting the folder name and file contents just a bit, I will extract a specific folder.

rubicon-objc/src/rubicon

The rubicon folder is the one that is needed.

Reference

Current directory listing
rubicon-objc
├── .git
├── .git-blame-ignore-revs
├── .github
├── .gitignore
├── .pre-commit-config.yaml
├── .readthedocs.yml
├── CHANGELOG.rst
├── CONTRIBUTING.md
├── LICENSE
├── README.rst
├── changes
├── docs
├── pyproject.toml
├── src       👈 The folder inside here
├── tests
└── tox.ini

Depending on the environment you check in, dotfiles may not appear (this is not a problem)

Rewriting

I will make it into the following state.

Final form
pyrubicon             👈 Rewrite `rubicon` to `pyrubicon`
├── .gitkeep          👈 Added (optional)
└── objc
    ├── __init__.py   👈 Change 1 place within the file
    ├── api.py
    ├── collections.py
    ├── ctypes_patch.py
    ├── eventloop.py
    ├── runtime.py
    └── types.py

Folder name

Rewrite rubicon to pyrubicon. Note that anything other than py is also fine.
This is a measure to avoid conflicts with the rubicon module that is pre-installed (especially) in Pyto.

rubicon○○ or ○○Rubicon would also have worked, but considering the hassle of rewriting pyrubicon <-> rubicon in the code, I adopted this because it's at the beginning and can simply be deleted.

Changes within the file

Rewrite the contents of __init__.py. The file location is:

rubicon/objc/__init__.py

The changes are as follows.

Displayed from the first line
try:
    # Read version from SCM metadata
    # This will only exist in a development environment
    from setuptools_scm import get_version

    # Excluded from coverage because a pure test environment (such as the one
    # used by tox in CI) won't have setuptools_scm
    __version__ = get_version("../../..", relative_to=__file__)  # pragma: no cover
except (ModuleNotFoundError, LookupError):
    # If setuptools_scm isn't in the environment, the call to import will fail.
    # If it *is* in the environment, but the code isn't a git checkout (e.g.,
    # it's been pip installed non-editable) the call to get_version() will fail.
    # If either of these occurs, read version from the installer metadata.

    # importlib.metadata.version was added in Python 3.8
    try:
        from importlib.metadata import version
    except ModuleNotFoundError:
        from importlib_metadata import version

+   __version__ = None #version("rubicon-objc")
-   __version__ = version("rubicon-objc")

The variable __version__ holds the version of rubicon-ObjC. However, since there is no version information at the reference destination due to the manual installation, I set it to None.

I do it this way because handling just one line is easier.

If you feel that the try/except itself is unnecessary, you can also just comment out everything from the first line up to just before the __version__ definition. In that case, don't forget to reduce the indentation.

(Additional: optional)

Directly under the current directory, I add an empty file as .gitkeep. I use this as a countermeasure for handling empty folders when using WorkingCopy.

Where to place the module

Hierarchy and execution

Basically, place the pyrubicon folder at the same level as the executable file.

Project folder
├── main.py     👈 The file to execute
├── util.py     👈 Custom modules using `pyrubicon(rubicon)`, etc.
└── pyrubicon
    ├── .gitkeep
    └── objc
        ├── __init__.py
        ├── api.py
        ├── collections.py
        ├── ctypes_patch.py
        ├── eventloop.py
        ├── runtime.py
        └── types.py

By arranging it this way, the sample code for rubicon can also be run by just changing the import statement slightly.

Your first bridge - Rubicon 0.4.8

Tutorial sample code
#from rubicon.objc import ObjCClass
from pyrubicon.objc import ObjCClass    # 👈 Just add `py`

NSURL = ObjCClass("NSURL")

Regarding import loading, the following might be easy to understand.

There is also a brute-force module import method using sys.path.append('..'), but that's up to your preference...

Portable environment

Once you finish setting up the Project folder, you can build an easy-to-handle environment where you can reference the folder from whichever application you want to use.
This kind of environment is possible because Rubicon-ObjC itself has very low dependency on external modules.

On PC environments, this is an installation/import/environment setup that cannot be called preferable, so I will close by presenting again the content I showed at the beginning.

Thank you very much.

🚸️ Usage Notes ⛔️

GitHubで編集を提案

Discussion