Skip to content

Commit

Permalink
Merge pull request #66 from oemof/fixes/fix-paths-infer-metadata
Browse files Browse the repository at this point in the history
Fix paths to infer metadata correctly on Windows/Linux
  • Loading branch information
jnnr committed Nov 21, 2022
2 parents 6e9dc4a + d113d83 commit bbad23c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/oemof/tabular/datapackage/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urlparse
import errno
import os
import pathlib
import shutil
import sys
import tarfile
Expand Down Expand Up @@ -104,7 +105,8 @@ def infer_metadata(
)
else:
for f in os.listdir("data/elements"):
r = Resource({"path": os.path.join("data/elements", f)})
r = Resource({"path": str(pathlib.PurePosixPath(
"data", "elements", f))})
r.infer()
r.descriptor["schema"]["primaryKey"] = "name"

Expand Down Expand Up @@ -138,7 +140,8 @@ def infer_metadata(
)

r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
r.save(pathlib.PurePosixPath("resources", f.replace(
".csv", ".json")))
p.add_resource(r.descriptor)

# create meta data resources sequences
Expand All @@ -150,10 +153,12 @@ def infer_metadata(
)
else:
for f in os.listdir("data/sequences"):
r = Resource({"path": os.path.join("data/sequences", f)})
r = Resource({"path": str(pathlib.PurePosixPath(
"data", "sequences", f))})
r.infer()
r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
r.save(pathlib.PurePosixPath("resources", f.replace(
".csv", ".json")))
p.add_resource(r.descriptor)

if not os.path.exists("data/geometries"):
Expand All @@ -164,10 +169,12 @@ def infer_metadata(
)
else:
for f in os.listdir("data/geometries"):
r = Resource({"path": os.path.join("data/geometries", f)})
r = Resource({"path": str(pathlib.PurePosixPath(
"data", "geometries", f))})
r.infer()
r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
r.save(pathlib.PurePosixPath("resources", f.replace(
".csv", ".json")))
p.add_resource(r.descriptor)

p.commit()
Expand Down

0 comments on commit bbad23c

Please sign in to comment.