# ``crm1`` Python package
This package is a Python implementation of the CRM-1 specification.
You can find the specification [here](https://github.com/CRModders/CRM-1/).
## Installation
You can install the package using pip:
```bash
pip install crm1
```
## Usage
```python
"""Usage example for the crm1 module."""
from crm1 import Repository, RepositoryPool, autorepo, make_pool
# You can get a repository from a URL
repo1 = Repository("https://crm-repo.jojojux.de/repo.json")
repo2 = "https://repo.crmodders.dev/repository.hjson"
# Now we create a pool and add the repositories to it
pool = RepositoryPool()
pool.add_repository(repo1)
# The RepositoryPool class can also take a string, a RRepository or a dict as a repository, it will automatically create a Repository object
# A RRRepository is a dataclass that holds the raw data of a repository
pool.add_repository(repo2)
# You could also use the autorepo module to get all repositories known to the Autorepo at https://crm-repo.jojojux.de/repo_mapping.json
repos = autorepo.get_all_repos()
# You can also use the make_pool function to create a pool from a list of repositories
pool2 = make_pool(repos)
# Now we can get a mod from the pool
mod = pool.get_mod("dev.crmodders.flux")
print(mod.meta.name) # This will print "Flux API", the mods name
print(mod.meta.ext.changelog) # The mod.meta.ext attribute holds the CommonModExt object, which add typing and docs to commonly used fileds the mod.ext dict.
# The unknown fields are stored in the mod.meta.ext.others attribute, which is a dict.
# If you want to get the original mod.ext dict, you can use mod.original_ext.
# Now we load a different mod
mod2 = pool.get_mod("com.nikrasoff.seamlessportals")
# We can now iterate over the dependencies of the mod
for dep in mod2.depends:
dep.id = "dev.crmodders.flux" # Ignore this line, this is required because the de.jojojux.crm-repo repository has a bug, see https://github.com/J0J0HA/CRM-1-Autorepo/issues/6
print(dep.mod) # This will print None, because the dependency was not yet resolved
# We can resolve the dependency by calling the resolve method and providing a repository or a pool to search in
print(
dep.resolve(pool)
) # This will print the mod object, as it is returned by the resolve method, but is also stored in the dependency object at dep.mod
# We can now access the mod object from the dependency object
print(
dep.mod.meta.name
) # This will print the name of the mod, in this case "Flux API". If the dependency could not be resolved, the dep.mod attribute will still be None
```
Everything is typed and documented, so you can use your IDE's autocomplete and documentation features to explore the functionality of the package.
## Helpers
### Versions
The ```helpers.versions``` module provides classes to work with versions and version ranges.
```python
from crm1.helpers.versions import Version, VersionRange, range_from_maven_string
range1 = VersionRange.from_string("[1.0,2.0.1)")
print(range1.lower, range1.lower_mode)
# 1.0.0 VersionEndMode.INCLUSIVE
print(range1.upper, range1.upper_mode)
# 2.0.1 VersionEndMode.EXCLUSIVE
range2 = VersionRange.from_string("(1.0,]")
print(range2.lower, range2.lower_mode)
# 1.0.0 VersionEndMode.EXCLUSIVE
print(range2.upper, range2.upper_mode)
# None VersionEndMode.INCLUSIVE
vers1 = Version.from_string("1.0")
vers2 = Version.from_string("2.0.1")
vers3 = Version.from_string("20.1")
print(vers1 in range1)
# True
print(vers2 in range1)
# False
print(vers3 in range1)
# False
print(vers1 in range2)
# False
print(vers2 in range2)
# True
print(vers3 in range2)
# True
print(str(range_from_maven_string(">=1.0")))
# [1.0.0,)
print(str(range_from_maven_string(">1.0")))
# (1.0.0,)
print(str(range_from_maven_string("<1.0")))
# (,1.0.0)
print(str(range_from_maven_string("<=1.0")))
# (,1.0.0]
print(str(range_from_maven_string("1.0")))
# 1.0.0
print(str(range_from_maven_string("*")))
# (,)
```
## License
This package is licensed under the MIT license. You can find the full license text in the [LICENSE](LICENSE) file.
Raw data
{
"_id": null,
"home_page": "https://github.com/J0J0HA/py-crm1",
"name": "crm1",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "crm1, repository, exploration, python",
"author": "JoJoJux",
"author_email": "johannes@jojojux.de",
"download_url": "https://files.pythonhosted.org/packages/f1/8a/b2af9c22c362ef4d3a13b84286cb3f3690986add2d7fbba10c955637e515/crm1-0.1.1.tar.gz",
"platform": null,
"description": "# ``crm1`` Python package\n\nThis package is a Python implementation of the CRM-1 specification.\n\nYou can find the specification [here](https://github.com/CRModders/CRM-1/).\n\n## Installation\n\nYou can install the package using pip:\n\n```bash\npip install crm1\n```\n\n## Usage\n\n```python\n\"\"\"Usage example for the crm1 module.\"\"\"\n\nfrom crm1 import Repository, RepositoryPool, autorepo, make_pool\n\n# You can get a repository from a URL\nrepo1 = Repository(\"https://crm-repo.jojojux.de/repo.json\")\nrepo2 = \"https://repo.crmodders.dev/repository.hjson\"\n\n# Now we create a pool and add the repositories to it\npool = RepositoryPool()\npool.add_repository(repo1)\n# The RepositoryPool class can also take a string, a RRepository or a dict as a repository, it will automatically create a Repository object\n# A RRRepository is a dataclass that holds the raw data of a repository\npool.add_repository(repo2)\n\n# You could also use the autorepo module to get all repositories known to the Autorepo at https://crm-repo.jojojux.de/repo_mapping.json\nrepos = autorepo.get_all_repos()\n# You can also use the make_pool function to create a pool from a list of repositories\npool2 = make_pool(repos)\n\n# Now we can get a mod from the pool\nmod = pool.get_mod(\"dev.crmodders.flux\")\nprint(mod.meta.name) # This will print \"Flux API\", the mods name\n\nprint(mod.meta.ext.changelog) # The mod.meta.ext attribute holds the CommonModExt object, which add typing and docs to commonly used fileds the mod.ext dict.\n# The unknown fields are stored in the mod.meta.ext.others attribute, which is a dict.\n# If you want to get the original mod.ext dict, you can use mod.original_ext.\n\n# Now we load a different mod\nmod2 = pool.get_mod(\"com.nikrasoff.seamlessportals\")\n\n# We can now iterate over the dependencies of the mod\nfor dep in mod2.depends:\n dep.id = \"dev.crmodders.flux\" # Ignore this line, this is required because the de.jojojux.crm-repo repository has a bug, see https://github.com/J0J0HA/CRM-1-Autorepo/issues/6\n print(dep.mod) # This will print None, because the dependency was not yet resolved\n # We can resolve the dependency by calling the resolve method and providing a repository or a pool to search in\n print(\n dep.resolve(pool)\n ) # This will print the mod object, as it is returned by the resolve method, but is also stored in the dependency object at dep.mod\n # We can now access the mod object from the dependency object\n print(\n dep.mod.meta.name\n ) # This will print the name of the mod, in this case \"Flux API\". If the dependency could not be resolved, the dep.mod attribute will still be None\n\n```\n\nEverything is typed and documented, so you can use your IDE's autocomplete and documentation features to explore the functionality of the package.\n\n## Helpers\n\n### Versions\n\nThe ```helpers.versions``` module provides classes to work with versions and version ranges.\n\n```python\nfrom crm1.helpers.versions import Version, VersionRange, range_from_maven_string\n\n\nrange1 = VersionRange.from_string(\"[1.0,2.0.1)\")\nprint(range1.lower, range1.lower_mode)\n# 1.0.0 VersionEndMode.INCLUSIVE\nprint(range1.upper, range1.upper_mode)\n# 2.0.1 VersionEndMode.EXCLUSIVE\n\nrange2 = VersionRange.from_string(\"(1.0,]\")\nprint(range2.lower, range2.lower_mode)\n# 1.0.0 VersionEndMode.EXCLUSIVE\nprint(range2.upper, range2.upper_mode)\n# None VersionEndMode.INCLUSIVE\n\nvers1 = Version.from_string(\"1.0\")\nvers2 = Version.from_string(\"2.0.1\")\nvers3 = Version.from_string(\"20.1\")\n\nprint(vers1 in range1)\n# True\nprint(vers2 in range1)\n# False\nprint(vers3 in range1)\n# False\nprint(vers1 in range2)\n# False\nprint(vers2 in range2)\n# True\nprint(vers3 in range2)\n# True\n\n\nprint(str(range_from_maven_string(\">=1.0\")))\n# [1.0.0,)\nprint(str(range_from_maven_string(\">1.0\")))\n# (1.0.0,)\nprint(str(range_from_maven_string(\"<1.0\")))\n# (,1.0.0)\nprint(str(range_from_maven_string(\"<=1.0\")))\n# (,1.0.0]\nprint(str(range_from_maven_string(\"1.0\")))\n# 1.0.0\nprint(str(range_from_maven_string(\"*\")))\n# (,)\n```\n\n## License\n\nThis package is licensed under the MIT license. You can find the full license text in the [LICENSE](LICENSE) file.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A CRM-1 repository exploration package",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/J0J0HA/py-crm1",
"Repository": "https://github.com/J0J0HA/py-crm1"
},
"split_keywords": [
"crm1",
" repository",
" exploration",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b5473af89ca741ee4e497e666f1235653156f1659a35908da629d853cd4a8e45",
"md5": "f2bc7e819c3f5bde25a3953c82f28447",
"sha256": "384299c7d2b046ee8a26f7f9a0e1a457811083872fcb049382d4c68a4268b843"
},
"downloads": -1,
"filename": "crm1-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f2bc7e819c3f5bde25a3953c82f28447",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 16018,
"upload_time": "2024-04-17T18:32:51",
"upload_time_iso_8601": "2024-04-17T18:32:51.135396Z",
"url": "https://files.pythonhosted.org/packages/b5/47/3af89ca741ee4e497e666f1235653156f1659a35908da629d853cd4a8e45/crm1-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f18ab2af9c22c362ef4d3a13b84286cb3f3690986add2d7fbba10c955637e515",
"md5": "c51328a124ea7fe9033b04d6f1d39359",
"sha256": "db662d9ffdd7c7c7fbdf6affd57fa2617018c12edf1703b4281f3b48bafb138a"
},
"downloads": -1,
"filename": "crm1-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "c51328a124ea7fe9033b04d6f1d39359",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 10452,
"upload_time": "2024-04-17T18:32:52",
"upload_time_iso_8601": "2024-04-17T18:32:52.958745Z",
"url": "https://files.pythonhosted.org/packages/f1/8a/b2af9c22c362ef4d3a13b84286cb3f3690986add2d7fbba10c955637e515/crm1-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-17 18:32:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "J0J0HA",
"github_project": "py-crm1",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "crm1"
}