Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kickstart the schemas revamp (WIP) #26

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
165 changes: 165 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.ruff_cache

# vscode
.vscode/
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: pretty-format-json
exclude: archive|examples
- id: check-json
- id: check-docstring-first
- id: trailing-whitespace
exclude: archive|examples
- id: end-of-file-fixer
exclude: archive|examples
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
pass_filenames: true
exclude: _vendor|vendored|examples|archive
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
hooks:
- id: ruff
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.0
hooks:
- id: check-github-workflows
- repo: https://github.com/econchick/interrogate
rev: 1.5.0
hooks:
- id: interrogate
types: [python]
# exclude: ^(docs/conf.py|setup.py|tests/functional/sample)
args: [--config=pyproject.toml]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions generate-index.py → archive/generate-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@

"""

files=sorted(p for p in os.listdir(".") if p.endswith(".schema.json"))
files = sorted(p for p in os.listdir(".") if p.endswith(".schema.json"))
rendered = Template(_TEMPLATE).render(files=files)

print(rendered, file=sys.stderr)

with open(join(dirname(__file__), "index.html"), "w") as fh:
fh.write(rendered)
fh.write(rendered)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added conda_models/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions conda_models/_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from functools import lru_cache
from typing import Optional, Type

from pydantic import BaseModel, Extra, create_model


class ExtrasForbiddenModel(BaseModel):
class Config:
extra = Extra.forbid


@lru_cache(maxsize=None)
def make_optional(baseclass: Type[BaseModel]) -> Type[BaseModel]:
"""Extracts the fields and validators from the baseclass and make fields optional"""
fields = baseclass.__fields__
validators = {"__validators__": baseclass.__validators__}
optional_fields = {key: (Optional[item.type_], None) for key, item in fields.items()}
return create_model(
f"Optional{baseclass.__name__}",
**optional_fields,
__validators__=validators,
)


def export_to_json(model, path):
with open(path, "w") as f:
f.write(model.json(indent=2))
67 changes: 67 additions & 0 deletions conda_models/channeldata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from typing import Iterable, Optional

from pydantic import AnyUrl, Field

from ._base import ExtrasForbiddenModel
from .run_exports import RunExports
from .types import PackageNameStr, VersionStr


class ChannelDataPackage(ExtrasForbiddenModel):
has_activate_scripts: bool = Field(..., alias="activate.d")
"Whether the package contains activation scripts"
has_deactivate_scripts: bool = Field(..., alias="deactivate.d")
"Whether the package contains deactivation scripts"
binary_prefix: bool
"Whether the package contains binary files that hardcode the installation prefix"
description: Optional[str] = None
"The description of the package"
dev_url: Optional[Iterable[AnyUrl]] = None
"The URL to the development page of the package"
doc_url: Optional[Iterable[AnyUrl]] = None
"The URL to the documentation page of the package"
home: Optional[Iterable[AnyUrl]] = None
"The URL to the homepage of the package"
source_url: Optional[Iterable[AnyUrl]] = None
"The URL to the latest source code of the package"
license: Optional[str] = None
"The license of the package"
has_post_link_scripts: bool
"Whether the package contains post-link scripts"
has_pre_link_scripts: bool
"Whether the package contains pre-link scripts"
has_pre_unlink_scripts: bool
"Whether the package contains pre-unlink scripts"
run_exports: dict[VersionStr, RunExports]
"The run exports of the package, per package version (not build!)"
subdirs: Iterable[str]
"Which subdirs the package is available in"
summary: Optional[str] = None
"The summary of the package. Shorter than description."
text_prefix: bool
"Whether the package contains text files that hardcode the installation prefix"
timestamp: Optional[int] = None
"Last update time for artifacts of this package"
version: Optional[VersionStr] = None
"The latest version of the package"


class ChannelData(ExtrasForbiddenModel):
"""
Data structures that are present in a `channeldata.json` file. Some channels on anaconda.org
contain a `channeldata.json` file which describes the subdirs the channel contains, the
packages stored in the channel and additional data about them like their latest version.

The `ChannelData` struct represents the data found within the `channeldata.json` file. The
`ChannelDataPackage` contains information about a package.

Note that certain aspects of `ChannelData` are broken (e.g. run_exports is only available for a
single package variant) and therefore the `ChannelData` struct is not really used much more.
"""

channeldata_version: int
"The version of the channeldata format"
packages: dict[PackageNameStr, ChannelDataPackage]
"The packages available in the channel, grouped by name"
subdirs: Iterable[str]
"The subdirs available in the channel"
3 changes: 3 additions & 0 deletions conda_models/conda_build_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
WIP
"""
3 changes: 3 additions & 0 deletions conda_models/conda_lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
WIP
"""
Loading