Skip to content

Commit

Permalink
improve comments
Browse files Browse the repository at this point in the history
Signed-off-by: technillogue <technillogue@gmail.com>
  • Loading branch information
technillogue committed Feb 19, 2024
1 parent a2f0f54 commit a6f43a4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
10 changes: 5 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ type Example struct {
}

type Config struct {
Build *Build `json:"build" yaml:"build"`
Image string `json:"image,omitempty" yaml:"image"`
Predict string `json:"predict,omitempty" yaml:"predict"`
Train string `json:"train,omitempty" yaml:"train"`
Concurrency int `json:"concurrency,omitempty" yaml:"concurrency"`
Build *Build `json:"build" yaml:"build"`
Image string `json:"image,omitempty" yaml:"image"`
Predict string `json:"predict,omitempty" yaml:"predict"`
Train string `json:"train,omitempty" yaml:"train"`
Concurrency int `json:"concurrency,omitempty" yaml:"concurrency"`
}

func DefaultConfig() *Config {
Expand Down
1 change: 0 additions & 1 deletion pkg/config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func getDescription(err validationError) string {
}
return err.child.Description()
}
fmt.Printf("err.parent.Description(): %s\n", err.parent.Description())
return err.parent.Description()
}

Expand Down
13 changes: 9 additions & 4 deletions python/cog/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def get_weights_argument(predictor: BasePredictor) -> Union[CogFile, CogPath, st
# up a little bit.
# TODO: CogFile/CogPath should have subclasses for each of the subtypes


# trt has Path... so it's like expecting it to be downloaded...?
# this is a breaking change
# previously, CogPath wouldn't be converted; now it is
# essentially everyone needs to switch from Path to str (or a new URL type)
if weights_url:
if weights_type == CogFile:
return cast(CogFile, CogFile.validate(weights_url))
Expand Down Expand Up @@ -217,17 +218,21 @@ def cleanup(self) -> None:
# # Handle URLPath objects specially for cleanup.
# if isinstance(value, URLPath):
# value.unlink()
# Note this is pathlib.Path, which cog.Path is a subclass of. A pathlib.Path object shouldn't make its way here,
# Note this is pathlib.Path, of which cog.Path is a subclass of.
# A pathlib.Path object shouldn't make its way here,
# but both have an unlink() method, so may as well be safe.
#
# URLThatCanBeConvertedToPath, DataURLTempFilePath, pathlib.Path, doesn't matter
# URLTempFile, DataURLTempFilePath, pathlib.Path, doesn't matter
# everyone can be unlinked
if isinstance(value, Path):
try:
value.unlink()
except FileNotFoundError:
pass

# if we had a separate method to traverse the input and apply some function to each value
# we could use something like these functions here

# def cleanup():
# if isinstance(value, Path):
# value.unlink()
Expand Down
5 changes: 3 additions & 2 deletions python/cog/server/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ def httpx_file_client() -> httpx.AsyncClient:
# requests has no write timeout, keep that
# httpx default for pool is 5, use that
timeout = httpx.Timeout(connect=10, read=15, write=None, pool=5)
# verify: Union[str, bool, ssl.SSLContext] = True,
return httpx.AsyncClient(
transport=transport,
follow_redirects=True,
timeout=timeout,
verify=os.environ.get("CURL_CA_BUNDLE"),
verify=os.environ.get("CURL_CA_BUNDLE", True),
)


Expand Down Expand Up @@ -197,13 +198,13 @@ async def chunk_file_reader() -> AsyncIterator[bytes]:
async def upload_files(self, obj: Any, url: Optional[str]) -> Any:
"""
Iterates through an object from make_encodeable and uploads any files.
When a file is encountered, it will be passed to upload_file. Any paths will be opened and converted to files.
"""
# # it would be kind of cleaner to make the default file_url
# # instead of skipping entirely, we need to convert to datauri
# if url is None:
# return obj
# TODO: upload concurrently
if isinstance(obj, dict):
return {
key: await self.upload_files(value, url) for key, value in obj.items()
Expand Down
1 change: 1 addition & 0 deletions python/cog/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __str__(self) -> str:
# FastAPI's jsonable_encoder will encode subclasses of pathlib.Path by
# calling str() on them
return self.filename
# honestly maybe returning self.url would be safer

def unlink(self, missing_ok: bool = False) -> None:
if self._path:
Expand Down
9 changes: 0 additions & 9 deletions python/tests/server/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,6 @@ def test_train_openapi_specification(client):
}


@uses_predictor("async_yield")
def test_yielding_strings_from_async_generator_predictors(client, match):
resp = client.post("/predictions")
assert resp.status_code == 200
assert resp.json() == match(
{"status": "succeeded", "output": ["foo", "bar", "baz"]}
)


@uses_predictor("yield_strings")
def test_yielding_strings_from_generator_predictors(client, match):
resp = client.post("/predictions")
Expand Down

0 comments on commit a6f43a4

Please sign in to comment.