Skip to content

Commit 3f0b5db

Browse files
authored
Add ruff rules to repository (#28)
* Refactor madp_strings.py and improve test readability - Simplified conditional checks in create_mad_string function in madp_strings.py. - Enhanced readability of test_communication.py by formatting long strings and improving spacing. - Updated test_debug.py to use Path for file handling and improved readability. - Refactored test_io_and_loading.py to utilize Path for file operations and improved code clarity. - Cleaned up test_misc_types.py by removing unnecessary imports and improving formatting. - Enhanced test_numeric_types.py for better readability and consistency in variable naming. - Updated test_object_wrapping.py to use new MadRef and MadLastRef classes for better clarity. * Refactor class names and update documentation for consistency * Update MAD binaries to version 1.1.6 and adjust tests to use py_name parameter in MAD context manager * Update GitHub Actions workflows to use latest actions versions and adjust Python versions * Update CHANGELOG for MAD-NG 1.1.6 release with new features and improvements * Remove Python 3.14 from test matrix in workflows * Bump version to 0.8.0 in __init__.py
1 parent 5cebb33 commit 3f0b5db

32 files changed

+701
-653
lines changed

.github/workflows/python-publish.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
id-token: write
2626

2727
steps:
28-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@v5
2929
- name: Set up Python
30-
uses: actions/setup-python@v5
30+
uses: actions/setup-python@v6
3131
with:
3232
python-version: '3.x'
3333
- name: Install dependencies
@@ -36,9 +36,9 @@ jobs:
3636
pip install build
3737
- name: Get MAD Binaries
3838
run: |
39-
mkdir src/pymadng/bin
40-
curl https://madx.web.cern.ch/releases/madng/1.1/mad-linux-1.1.5 -o src/pymadng/bin/mad_Linux
41-
curl https://madx.web.cern.ch/releases/madng/1.1/mad-macos-1.1.5 -o src/pymadng/bin/mad_Darwin
39+
mkdir src/pymadng/bin
40+
curl https://madx.web.cern.ch/releases/madng/1.1/mad-linux-1.1.6 -o src/pymadng/bin/mad_Linux
41+
curl https://madx.web.cern.ch/releases/madng/1.1/mad-macos-1.1.6 -o src/pymadng/bin/mad_Darwin
4242
chmod +x src/pymadng/bin/mad_Linux src/pymadng/bin/mad_Darwin
4343
- name: Build package
4444
run: python -m build

.github/workflows/test-publish.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os: [ubuntu-latest, macos-latest]
15-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
15+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1616

1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1919
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
20-
uses: actions/setup-python@v5
20+
uses: actions/setup-python@v6
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
2626
python -m pip install pymadng[tfs]
27-
27+
2828
- name: Test with python
2929
run: |
3030
python -m unittest tests/*.py

.github/workflows/test-pymadng.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
name: Test pymadng
55

6-
on:
6+
on:
77
push:
88
branches:
99
- main
@@ -22,19 +22,19 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest, macos-latest]
25-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
25+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2626

2727
steps:
28-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@v5
2929
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
30-
uses: actions/setup-python@v5
30+
uses: actions/setup-python@v6
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333
- name: Get MAD Binaries
3434
run: |
35-
mkdir ./src/pymadng/bin
36-
curl https://madx.web.cern.ch/releases/madng/1.1/mad-linux-1.1.5 -o ./src/pymadng/bin/mad_Linux
37-
curl https://madx.web.cern.ch/releases/madng/1.1/mad-macos-1.1.5 -o ./src/pymadng/bin/mad_Darwin
35+
mkdir ./src/pymadng/bin
36+
curl https://madx.web.cern.ch/releases/madng/1.1/mad-linux-1.1.6 -o ./src/pymadng/bin/mad_Linux
37+
curl https://madx.web.cern.ch/releases/madng/1.1/mad-macos-1.1.6 -o ./src/pymadng/bin/mad_Darwin
3838
chmod +x ./src/pymadng/bin/mad_Linux ./src/pymadng/bin/mad_Darwin
3939
- name: Install dependencies
4040
run: |

.readthedocs.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ sphinx:
1616
configuration: docs/source/conf.py
1717

1818

19-
# Specify dependancy
20-
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
19+
# Specify dependancy
20+
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
2121
python:
2222
install:
2323
- method: pip
2424
path: .
25-
- requirements: docs/requirements.txt
25+
- requirements: docs/requirements.txt

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
0.8.0 (2025/09/30)
2+
Update to MAD-NG 1.1.6 \
3+
Added comprehensive ruff configuration in pyproject.toml with various linting rules \
4+
Renamed classes and functions to follow PascalCase and snake_case conventions \
5+
Updated imports to use pathlib.Path instead of os.path \
6+
Improved code formatting and removed redundant constructs \
7+
BUG: Fixed used of `py` instead of `py_name`, resulting in py_name being unuable. \
8+
Removed compatibility for Python versions below 3.10, now only supporting Python 3.10 and above. \
9+
Updated GitHub Actions workflows to test against Python 3.10 to 3.14 \
10+
Updated documentation to reflect changes in code style and conventions. \
11+
112
0.7.1 (2025/08/04)
213
Update to MAD-NG 1.1.5
314

docs/source/advanced_features.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ In PyMAD-NG, accessing or calling any MAD-NG function or object returns a Python
4646
### Example:
4747
```python
4848
r = mad.math.exp(1)
49-
print(type(r)) # high_level_mad_ref
49+
print(type(r)) # MadRef
5050
print(r.eval()) # 2.718...
5151
```
5252

@@ -201,4 +201,3 @@ This ensures the MAD process is correctly shut down when finished.
201201
These tools are designed to give you complete control over your simulations while staying fast and maintainable.
202202

203203
Next: head over to **Debugging & Troubleshooting** to diagnose and resolve common issues in real-world workflows.
204-

docs/source/architecture.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# PyMAD-NG Architecture Overview
66

7-
This section explains the internal architecture of PyMAD-NG, outlining how Python interacts with MAD-NG.
7+
This section explains the internal architecture of PyMAD-NG, outlining how Python interacts with MAD-NG.
88

99
```{note}
1010
Understanding the architecture will help advanced users contribute to development, extend functionality, and debug issues more effectively.
@@ -62,7 +62,7 @@ This is implemented using `os.pipe()` and `select.select()` to manage reads and
6262
- Handles naming of Python process in MAD-NG via `py_name`
6363
- Configures subprocess behavior (debug mode, stdout redirection)
6464

65-
### {class}`madp_pymad.mad_process`
65+
### {class}`madp_pymad.MadProcess`
6666

6767
- Manages low-level pipe setup and subprocess launch
6868
- Provides `send`, `recv`, and `close` methods
@@ -111,7 +111,7 @@ Because MAD-NG entities are only known at runtime, PyMAD-NG uses dynamic attribu
111111

112112
- Tab completion (`dir(mad)`) only works for preloaded or cached attributes
113113
- Use {func}`MAD.globals()` to list current MAD-NG global variables
114-
- {class}`madp_classes.high_level_mad_ref` objects will not show introspectable properties until evaluated
114+
- {class}`madp_classes.high_level_MadRef` objects will not show introspectable properties until evaluated
115115

116116
---
117117

@@ -130,8 +130,8 @@ All sends are "protected" by default:
130130
| Component | Role |
131131
| ---------------------------------------------- | ---------------------------------------------------------- |
132132
| {class}`MAD` class | Main interface and environment for interacting with MAD-NG |
133-
| {class}`madp_pymad.mad_process` | Launches and communicates with MAD-NG subprocess |
134-
| {class}`madp_classes.high_level_mad_ref` | Wraps MAD objects for Pythonic access |
133+
| {class}`madp_pymad.MadProcess` | Launches and communicates with MAD-NG subprocess |
134+
| {class}`madp_classes.high_level_MadRef` | Wraps MAD objects for Pythonic access |
135135
| {class}`madp_last` | Tracks temporary intermediate results from MAD-NG |
136136
| Type dispatch | Maps Python objects to MAD-NG-compatible messages |
137137

docs/source/contributing.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This guide is for developers who want to contribute to PyMAD-NG or extend its ca
1010
|--------------------------------------|--------------------------------------------------------|
1111
| `src/pymadng/madp_object.py` | Contains the main {class}`pymadng.MAD` class and high-level interface |
1212
| `src/pymadng/madp_pymad.py` | Manages subprocess communication and type handling |
13-
| `src/pymadng/madp_classes.py` | Defines reference object wrappers (`mad_ref`, etc.) |
13+
| `src/pymadng/madp_classes.py` | Defines reference object wrappers (`MadRef`, etc.) |
1414
| `src/pymadng/madp_last.py` | Manages temporary variables like `_last[]` |
1515
| `src/pymadng/madp_strings.py` | Utility for quoting and formatting MAD-compatible text |
1616
| `examples/` | Contains working scripts and tutorials |
@@ -50,7 +50,7 @@ git checkout -b your-feature-name
5050
3. **Test Code**
5151
- All tests are located in the `tests/` directory, currently `unittests` are used.
5252

53-
4. **Run Tests**
53+
4. **Run Tests**
5454
```bash
5555
python -m unittest tests/*.py
5656
```
@@ -85,4 +85,3 @@ python -m unittest tests/*.py
8585
- See the [Debugging Guide] or [Architecture Overview] for internals
8686

8787
Thanks for contributing to PyMAD-NG!
88-

docs/source/reference.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ PyMAD-NG Module contents
1212
Useful functions for MAD References
1313
-----------------------------------
1414

15-
.. autofunction:: pymadng.madp_classes.high_level_mad_object.convert_to_dataframe
16-
:no-index:
15+
.. autofunction:: pymadng.madp_classes.MadObject.convert_to_dataframe
16+
:no-index:
1717

18-
.. autofunction:: pymadng.madp_classes.high_level_mad_object.to_df
18+
.. autofunction:: pymadng.madp_classes.MadObject.to_df
1919
:no-index:

examples/ex-LowLevel/ex-send-multypes.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,14 @@
1818
mad.send("cm1 = (MAD.cmatrix(10000, 1000) + 1i)")
1919

2020
# Create a string the manipulates the complex matrix in MAD and sends the result it to Python
21-
cmatrixString = """
21+
cmatrix_str = """
2222
{0} = cm1 {1} {2}
2323
py:send({0})"""
2424

25-
mad.send(
26-
cmatrixString.format("cm4", "*", 1)
27-
) ## Set cm4 to cm1 * 1 and send it to Python
28-
mad.send(
29-
cmatrixString.format("cm1", "*", 2)
30-
) ## Set cm1 to cm1 * 2 and send it to Python
31-
mad.send(
32-
cmatrixString.format("cm2", "*", 2)
33-
) ## Set cm2 to cm1 * 2 and send it to Python
34-
mad.send(
35-
cmatrixString.format("cm3", "/", 3)
36-
) ## Set cm3 to cm1 / 3 and send it to Python
25+
mad.send(cmatrix_str.format("cm4", "*", 1)) ## Set cm4 to cm1 * 1 and send it to Python
26+
mad.send(cmatrix_str.format("cm1", "*", 2)) ## Set cm1 to cm1 * 2 and send it to Python
27+
mad.send(cmatrix_str.format("cm2", "*", 2)) ## Set cm2 to cm1 * 2 and send it to Python
28+
mad.send(cmatrix_str.format("cm3", "/", 3)) ## Set cm3 to cm1 / 3 and send it to Python
3729

3830
## Create a vector in MAD and send it to Python
3931
mad.send("""
@@ -72,41 +64,39 @@
7264
mad_list = mad.recv("list")
7365
for i, inner_list in enumerate(mad_list):
7466
for j, val in enumerate(inner_list):
75-
print(
76-
f"List value at [{i}][{j}]: {val} == {my_list[i][j]}", val == my_list[i][j]
77-
)
67+
print(f"List value at [{i}][{j}]: {val} == {my_list[i][j]}", val == my_list[i][j])
7868

7969
# Send an integer to MAD and receive a changed version back
80-
myInt = 4
70+
an_int = 4
8171
mad.send("""
82-
local myInt = py:recv()
83-
py:send(myInt+2)
72+
local an_int = py:recv()
73+
py:send(an_int+2)
8474
""")
85-
mad.send(myInt)
75+
mad.send(an_int)
8676
print("Integers", mad.recv() == 6)
8777

8878
# Send a float to MAD and receive a changed version back
89-
myFloat = 6.612
79+
a_float = 6.612
9080
mad.send("""
91-
local myFloat = py:recv()
92-
py:send(myFloat + 0.56)
81+
local a_float = py:recv()
82+
py:send(a_float + 0.56)
9383
""")
94-
mad.send(myFloat)
84+
mad.send(a_float)
9585
print("Floats", mad.recv() == 6.612 + 0.56)
9686

9787
# Send a complex number to MAD and receive a changed version back
98-
myCpx = 6.612 + 4j
88+
a_cpx = 6.612 + 4j
9989
mad.send("""
100-
local myCpx = py:recv()
101-
py:send(myCpx + 0.5i)
90+
local a_cpx = py:recv()
91+
py:send(a_cpx + 0.5i)
10292
""")
103-
mad.send(myCpx)
93+
mad.send(a_cpx)
10494
print("Complex", mad.recv() == 6.612 + 4.5j)
10595

10696
# Send None to MAD and it back
10797
mad.send("""
108-
local myNil = py:recv()
109-
py:send(myNil)
98+
local a_nil = py:recv()
99+
py:send(a_nil)
110100
""")
111101
mad.send(None)
112102
print("Nil/None", mad.recv() is None)

0 commit comments

Comments
 (0)