Skip to content

Commit b25c9de

Browse files
authored
Merge pull request #65 from MC-kit/devel
Devel
2 parents 910fb15 + 8856b12 commit b25c9de

File tree

4 files changed

+73
-29
lines changed

4 files changed

+73
-29
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mapstp"
3-
version = "0.3.5"
3+
version = "0.3.6"
44
description = "Transfers meta information from STP to MCNP"
55
authors = ["dvp <[email protected]>"]
66
homepage = "https://github.com/MC-kit/map-stp"

src/mapstp/cli/runner.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ def mapstp(
172172
joined_paths = join_paths(paths, separator)
173173
merge_paths(_output, joined_paths, path_info, _mcnp, used_materials_text)
174174
if excel:
175-
start_cell_number = start_cell_number or (
176-
find_first_cell_number(mcnp) if mcnp else 1
177-
)
175+
if not start_cell_number:
176+
start_cell_number = find_first_cell_number(mcnp) if mcnp else 1
178177
_excel = Path(excel)
179178
can_override(_excel, override)
180179
create_excel(_excel, paths, path_info, separator, start_cell_number)

src/mapstp/materials_index.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def load_materials_index(materials_index: str = None) -> pd.DataFrame:
4040
sheet_name=0, # Use the first sheet, regardless of its name.
4141
usecols=["mnemonic", "number", "eff.density, g/cm3"],
4242
converters={"number": int, "eff.density, g/cm3": float},
43+
engine="openpyxl",
4344
)
4445
materials = materials.loc[materials["mnemonic"].notnull()]
4546
materials.rename(columns={"eff.density, g/cm3": "density"}, inplace=True)

tools/clear-prev-dist-info.py

+69-25
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,84 @@
33
44
This fixes https://github.com/python-poetry/poetry/issues/4526.
55
Should be fixed in poetry 1.2, but it's not available yet.
6-
Run this if test_package() fails on pytest run.
7-
6+
Run this if test_package() fails on pytest run
7+
(mckit of wrong version is found on python site).
88
"""
9-
import platform
9+
10+
from typing import Optional, TypeVar
11+
1012
import shutil
11-
import sys
13+
import site
14+
import subprocess
1215

1316
from pathlib import Path
1417

18+
import tomli
1519

16-
def get_packages_dir() -> Path:
17-
"""Define packages location depending on system."""
18-
system = platform.system()
19-
if system == "Windows":
20-
site_packages = Path("Lib", "site-packages")
21-
else:
22-
python = f"python{sys.version_info.major}.{sys.version_info.minor}"
23-
site_packages = Path("lib", python, "site-packages")
24-
result = Path(sys.prefix, site_packages)
25-
if not result.is_dir():
26-
raise ValueError(
27-
f"Cannot find site package for system {system} in folder {result}"
20+
PathLike = TypeVar("PathLike", str, Path)
21+
22+
23+
def search_upwards_for_file(filename: PathLike) -> Optional[Path]:
24+
"""Search upward from the current directory for a `filename`.
25+
26+
Args:
27+
filename: the file name to look for if available.
28+
29+
Returns:
30+
Path: the location of the first file found or None, if none was found
31+
"""
32+
d = Path.cwd()
33+
root = Path(d.root)
34+
35+
while d != root:
36+
attempt = d / filename
37+
if attempt.exists():
38+
return attempt
39+
d = d.parent
40+
41+
return None
42+
43+
44+
def get_project_name() -> str:
45+
"""Find project name, which is prefix for info distributions.
46+
47+
Returns:
48+
str: the name of package specified in pyproject.toml
49+
50+
Raises:
51+
EnvironmentError: if file pyproject.toml is not found.
52+
"""
53+
pyproject_path = search_upwards_for_file("pyproject.toml")
54+
if pyproject_path is None:
55+
raise EnvironmentError(
56+
"Illegal directory: cannot find file pyproject.toml "
57+
f"from current directory: {Path.cwd()}"
2858
)
29-
return result
59+
pyproject = tomli.loads(pyproject_path.read_text())
60+
name = pyproject["tool"]["poetry"]["name"].replace("-", "_")
61+
print(f"Package {name} is found in {pyproject_path.absolute()}")
62+
return name
63+
64+
65+
def clear_previous_distributions_info() -> None:
66+
"""Remove all dist-info folders from previous installations."""
67+
packages_dir = Path(site.getsitepackages()[0])
68+
name = get_project_name()
69+
dists = list(packages_dir.glob(f"{name}-*.dist-info"))
70+
if dists:
71+
for dist in dists:
72+
print("Removing distribution", dist)
73+
shutil.rmtree(dist)
74+
else:
75+
print("Nothing to remove for package", name)
3076

3177

32-
def clear_mapstp_info_dists() -> None:
33-
"""Remove all mapstp dist-info folders."""
34-
packages_dir = get_packages_dir()
35-
dists = list(packages_dir.glob("mapstp-*.dist-info"))
36-
for dist in dists:
37-
shutil.rmtree(dist)
38-
print("Run `poetry install` after running this script.")
78+
def run_poetry_install() -> None:
79+
"""Refresh installation of the package."""
80+
print("Running `poetry install`.")
81+
subprocess.run(["poetry", "install"])
3982

4083

4184
if __name__ == "__main__":
42-
clear_mapstp_info_dists()
85+
clear_previous_distributions_info()
86+
run_poetry_install()

0 commit comments

Comments
 (0)