Python tools for interacting with Xcode project bundles
Перейти к файлу
Dale eec1b4bb9a
Merge pull request #29 from microsoft/dependabot/pip/idna-3.7
Bump idna from 3.4 to 3.7
2024-04-12 06:32:50 +01:00
.azure Bump Python version to 3.10 2023-11-24 16:28:03 +00:00
.vscode Update linter config for VS code 2023-11-24 16:18:23 +00:00
tests Fix paths for PBXReferenceProxy 2023-11-29 17:55:35 +00:00
xcodeproj Fix paths for PBXReferenceProxy 2023-11-29 17:55:35 +00:00
.gitignore Add .venv to gitignore 2023-11-24 16:12:19 +00:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2021-02-08 04:18:58 -08:00
LICENSE Initial LICENSE commit 2021-02-08 04:19:00 -08:00
README.md Add scheme support 2021-03-23 17:28:13 +00:00
SECURITY.md Initial SECURITY.md commit 2021-02-08 04:19:03 -08:00
SUPPORT.md Add README details 2021-02-08 13:48:46 +00:00
inlinecss.py Initial version 2021-02-08 17:42:52 +00:00
poetry.lock Bump idna from 3.4 to 3.7 2024-04-12 02:21:14 +00:00
pylintrc Fix linting issues 2023-04-24 10:43:09 +08:00
pyproject.toml Bump Python version to 3.10 2023-11-24 16:28:03 +00:00
stylecheck.sh Update linter config for VS code 2023-11-24 16:18:23 +00:00
test.sh Initial version 2021-02-08 17:42:52 +00:00

README.md

xcodeproj

xcodeproj is a utility for interacting with Xcode's xcodeproj bundle format.

It expects some level of understanding of the internals of the pbxproj format and schemes. Note that this tool only reads projects. It does not write out any changes. If you are looking for more advanced functionality like this, I recommend looking at the Ruby gem of the same name (which is unaffiliated in anyway).

To learn more about the format, you can look at any of these locations:

Getting Started

Loading a project is very simple:

project = xcodeproj.XcodeProject("/path/to/project.xcodeproj")

From here you can explore the project in different ways:


# Get all targets
for target in project.targets:
    print(target.name)

# Print from the root level, 2 levels deep (.project is a property on the root 
# project as other properties such as .schemes are also available)
for item1 in project.project.main_group.children:
    print(item1)
    if not isinstance(item1, xcodeproj.PBXGroup):
        continue

    for item2 in item1.children:
        print("\t", item2)

# Check that all files referenced in the project exist on disk
for item in project.fetch_type(xcodeproj.PBXFileReference).values():
    assert os.path.exists(item.absolute_path())

# You can access the raw objects map directly:
obj = project.objects["key here"]

# For any object you have, you can access its key/identifier via the 
# `.object_key` property
key = obj.object_key

Note: This library is "lazy". Many things aren't calculated until they are used. This time will be inconsequential on smaller projects, but on larger ones, it can save quite a bit of time due to not parsing the entire project on load. These properties are usually stored though so that subsequent accesses are instant.

Note on Scheme Support

There's no DTD for xcscheme files, so the implementation has been guessed. There will definitely be holes that still need to be patched in it though. Please open an issue if you find any, along with a sample xcscheme file.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.