Skip to content

Commit 66035ab

Browse files
Merge pull request #1605 from bug-or-feature/feature-1603-improve-path-resolution
2 parents d2c03c0 + d0dff89 commit 66035ab

27 files changed

+1195
-238
lines changed

.github/workflows/os-test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ jobs:
2525
- name: Install dependencies
2626
run: |
2727
python -m pip install --upgrade pip setuptools
28-
python -m pip install .
28+
python -m pip install '.[dev]'
29+
30+
- name: Test with pytest
31+
run: |
32+
pytest syscore/tests/test_fileutils.py

docs/backtesting.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,6 @@ resolve_path_and_filename_for_package("\\home/rob.file.csv")
31233123

31243124
```
31253125

3126-
31273126
These functions are used internally whenever a file name is passed in, so feel free to use any of these file formats when specifying eg a configuration filename.
31283127
```
31293128
### Absolute: Windows (note use of double backslash in str)
@@ -3136,6 +3135,31 @@ These functions are used internally whenever a file name is passed in, so feel f
31363135
"syscore.tests.pricedata.csv"
31373136
```
31383137

3138+
Obviously, using 'dots' as a separator brings limitations, like supporting directories or files with 'dots' in their names. This won't work:
3139+
```
3140+
>>> resolve_path_and_filename_for_package("syscore/tests/price.test.data.csv")
3141+
'/home/user/pysystemtrade/syscore/tests/price/test/data.csv'
3142+
```
3143+
3144+
do this instead:
3145+
```
3146+
>>> resolve_path_and_filename_for_package("syscore/tests", "price.test.data.csv")
3147+
'/home/user/pysystemtrade/syscore/tests/price.test.data.csv'
3148+
```
3149+
3150+
This will also not work:
3151+
```
3152+
>>> get_resolved_pathname("data/dir.with.dots")
3153+
'/home/user/pysystemtrade/data/dir/with/dots'
3154+
```
3155+
3156+
do this instead:
3157+
```
3158+
>>> from pathlib import Path
3159+
>>> get_resolved_pathname(Path("data/dir.with.dots"))
3160+
'/home/user/pysystemtrade/data/dir.with.dots'
3161+
```
3162+
31393163
## Logging
31403164

31413165
### Basic logging

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[build-system]
2-
requires = ["setuptools >= 61.0"]
2+
requires = [
3+
"setuptools >= 61.0",
4+
"setuptools-scm >= 8.0"
5+
]
36
build-backend = "setuptools.build_meta"
47

58
[project]
@@ -47,8 +50,11 @@ find = {}
4750

4851
[tool.setuptools.package-data]
4952
"data" = ["*.csv"]
53+
"data.futures" = ["*.csv"]
5054
"private" = ["*.yaml"]
51-
"sysbrokers" = ["*.csv", "*.yaml"]
55+
"sysbrokers" = ["*.csv"]
56+
"sysbrokers.IB" = ["*.yaml"]
57+
"sysbrokers.IB.config" = ["*.csv"]
5258
"syscontrol" = ["*.yaml"]
5359
"sysdata" = ["*.csv"]
5460
"sysdata.config" = ["*.yaml"]

sysbrokers/IB/ib_trading_hours.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
import datetime
22
from ib_insync import ContractDetails as ibContractDetails
33

4-
from sysdata.config.private_directory import get_full_path_for_private_config
4+
from sysdata.config.private_config import (
5+
get_private_config_dir,
6+
)
57
from sysobjects.production.trading_hours.trading_hours import (
68
tradingHours,
79
listOfTradingHours,
810
)
9-
from syscore.fileutils import does_filename_exist
11+
from syscore.fileutils import (
12+
does_resolved_filename_exist,
13+
resolve_path_and_filename_for_package,
14+
)
1015
from sysdata.config.production_config import get_production_config
1116
from sysdata.production.trading_hours import read_trading_hours
1217

1318
IB_CONFIG_TRADING_HOURS_FILE = "sysbrokers.IB.ib_config_trading_hours.yaml"
14-
PRIVATE_CONFIG_TRADING_HOURS_FILE = get_full_path_for_private_config(
15-
"private_config_trading_hours.yaml"
16-
)
19+
PRIVATE_CONFIG_TRADING_HOURS_FILE = "private_config_trading_hours.yaml"
1720

1821

1922
def get_saved_trading_hours():
20-
if does_filename_exist(PRIVATE_CONFIG_TRADING_HOURS_FILE):
21-
return read_trading_hours(PRIVATE_CONFIG_TRADING_HOURS_FILE)
23+
private_path = resolve_path_and_filename_for_package(
24+
get_private_config_dir(), PRIVATE_CONFIG_TRADING_HOURS_FILE
25+
)
26+
if does_resolved_filename_exist(private_path):
27+
return read_trading_hours(private_path)
2228
else:
23-
return read_trading_hours(IB_CONFIG_TRADING_HOURS_FILE)
29+
default_path = resolve_path_and_filename_for_package(
30+
IB_CONFIG_TRADING_HOURS_FILE
31+
)
32+
return read_trading_hours(default_path)
2433

2534

2635
def get_trading_hours_from_contract_details(

syscore/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from importlib.util import find_spec
2+
from pathlib import Path
3+
4+
module_spec = find_spec(__name__)
5+
path = Path(module_spec.origin)
6+
7+
PYSYS_PROJECT_DIR = path.parent.parent

0 commit comments

Comments
 (0)