openschemas / schemaorg

python functions for applied use of schema.org
https://openschemas.github.io/schemaorg/
Mozilla Public License 2.0
34 stars 3 forks source link

Issue following tutorial code #24

Closed jhned closed 5 years ago

jhned commented 5 years ago

Hey there, thanks for making this, this will really help me out! I'm not familiar with Python, but I'm trying to follow along with the tutorial. So far, I downloaded the repo, ran python3 setup.py and then put this code into a file titled SoftwareSourceCode.py:

from schemaorg.main.parse import RecipeParser
from schemaorg.main import Schema

spec = Schema("SoftwareSourceCode")
recipe = RecipeParser("recipe.yml")
print(recipe.loaded)

from spython.main.parse import DockerRecipe
parser = DockerRecipe("Dockerfile")

spec.add_property('environment', parser.environ) # currently a list
spec.add_property('entrypoint', parser.entrypoint)
spec.add_property('description', 'A Dockerfile build recipe')

spec.add_property('name', "vanessa/sregistry")
spec.add_property('ContainerImage', parser.fromHeader)

recipe.validate(spec)

from schemaorg.templates.google import make_dataset
dataset = make_dataset(spec, "index.html")
print(dataset)

I ran python3 SoftwareSourceCode.py and got this output:

Specification base set to http://www.schema.org
Using Version 3.5
Found http://www.schema.org/SoftwareSourceCode
SoftwareSourceCode: found 104 properties
/Users/jhned/Downloads/schemaorg-master 2/schemaorg/utils.py:237: YAMLLoadWarning: calling yaml.load_all() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  for doc in docs:
{'version': 1, 'schemas': {'SoftwareSourceCode': {'recommended': [{'softwareVersion': 'version'}, 'citation', 'identifier', 'keywords', 'license', 'url', 'sameAs', 'spatialCoverage', 'temporalCoverage', 'variableMeasured'], 'required': ['description', 'name']}, 'Person|Organization': {'required': ['description', 'name']}, 'Person': {'required': ['description', 'name']}, 'Organization': {'required': ['description', 'name']}}}
Traceback (most recent call last):
  File "SoftwareSourceCode.py", line 8, in <module>
    from spython.main.parse import DockerRecipe
ImportError: cannot import name 'DockerRecipe' from 'spython.main.parse' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spython/main/parse/__init__.py)

Any idea what I'm missing off the top of your head?

vsoch commented 5 years ago

hey @jhned ! Sorry for the trouble here - it's entirely a version issue for Singularity Python - we refactored the recipe parser (and I need to update the tutorial here). Can you point me to where you are reading and I'll do this asap?

vsoch commented 5 years ago

okay, so the fix is very simple, just these two lines here:

from spython.main.parse.parsers import DockerParser
parser = DockerParser("Dockerfile").parse()

I just opened a pull request to update all the examples, #25, if you want to take a look! Give that a go, and when you've confirmed it's good, I'll merge.

jhned commented 5 years ago

Hey @vsoch, thanks for the reply! I was reading about it here: https://openschemas.github.io/schemaorg/. I'll try the update now.

jhned commented 5 years ago

Ok, now I'm getting this message:

ERROR Cannot find Dockerfile, is the path correct?

Was I supposed to download a Dockerfile as well as part of this?

vsoch commented 5 years ago

Oh, you'd need to have a Dockerfile in your present working directory to work with! If you want a complete, packaged example, see this repo -> https://github.com/openbases/extract-dockerfile I've provided a Dockerfile in each folder.

vsoch commented 5 years ago

That repo is currently linked in the examples README: https://github.com/openschemas/schemaorg/tree/master/examples

And the google example folder does have a Dockerfile: https://github.com/openschemas/schemaorg/tree/master/examples/google

I think I mostly never expected someone to copy paste into a script from the getting started page and have it associated with a folder in the repo, sorry about that! Hopefully I've provided enough examples and files in other places so it's not a hassle.

jhned commented 5 years ago

No worries! Thanks for the help!